Alman Knowledge Base

website·Indexed 31 days ago

https://alman.netlify.app/

A collection of technical guides, code snippets, and tutorials covering multiple programming languages including Python, JavaScript, and Java. Content includes algorithm implementations like Heapsort and Quicksort, development environment setups for Vite, React, and Electron, Docker configurations for Node.js, and practical utility guides for tools like PDM, uv, NVM, and pdb.

Tokens
80.2K
Snippets
425
Records
442
Agent score
75%

What's inside Alman

  1. Extract comprehensive system and network information using JavaScript

    You can use the navigator and window objects to collect detailed information about a user's operating system, browser capabilities, screen resolution, and network status. This includes detecting the OS via navigator.platform, checking hardware concurrency for CPU cores, and verifying the availability of modern Web APIs (like WebAssembly or Service Workers).
    // Comprehensive system and network info object
    var extendedSystemInfo = {
      userAgent: navigator.userAgent,
      appName: navigator.appName,
      appVersion: navigator.appVersion,
      platform: navigator.platform,
      language: navigator.language,
      cookiesEnabled: navigator.cookieEnabled,
      javaEnabled: navigator.javaEnabled(),
      screen: {
        width: window.screen.width,
        height: window.screen.height,
        colorDepth: window.screen.colorDepth
      },
      online: navigator.onLine,
      os: detectOS(),
      connection: navigator.connection || navigator.mozConnection || navigator.webkitConnection || navigator.msConnection,
      cpu: navigator.hardwareConcurrency || 'Unknown',
      features: detectFeatures(),
      cookies: getCookies(),
      localStorage: getLocalStorage(),
      sessionStorage: getSessionStorage()
    };
    
    function detectOS() {
      var platform = navigator.platform.toLowerCase();
      if (platform.indexOf('win') !== -1) return 'Windows';
      if (platform.indexOf('mac') !== -1) return 'Mac OS';
      if (platform.indexOf('linux') !== -1) return 'Linux';
      if (/iphone|ipad|ipod|ios/.test(platform)) return 'iOS';
      if (/android/.test(platform)) return 'Android';
      return 'Unknown';
    }
    
    function detectFeatures() {
      return {
        localStorage: !!window.localStorage,
        sessionStorage: !!window.sessionStorage,
        indexedDB: !!window.indexedDB,
        webWorkers: !!window.Worker,
        serviceWorker: 'serviceWorker' in navigator,
        webAssembly: typeof WebAssembly === 'object' && typeof WebAssembly.compile === 'function',
        webGL: !!window.WebGLRenderingContext,
        cookiesEnabled: navigator.cookieEnabled,
        touchEvents: 'ontouchstart' in window || navigator.maxTouchPoints > 0,
        fetchAPI: 'fetch' in window,
        historyAPI: !!window.history && !!history.pushState,
        webRTC: !!navigator.mediaDevices && !!navigator.mediaDevices.getUserMedia,
        webSockets: 'WebSocket' in window || 'MozWebSocket' in window
      };
    }
    
    function getCookies() {
      return document.cookie;
    }
    
    function getLocalStorage() {
      var localStorageInfo = {};
      for (var key in localStorage) {
        if (localStorage.hasOwnProperty(key)) {
          localStorageInfo[key] = localStorage[key];
        }
      }
      return localStorageInfo;
    }
    
    function getSessionStorage() {
      var sessionStorageInfo = {};
      for (var key in sessionStorage) {
        if (sessionStorage.hasOwnProperty(key)) {
          sessionStorageInfo[key] = sessionStorage[key];
        }
      }
      return sessionStorageInfo;
    }
    
    console.log('Extended System Info:', extendedSystemInfo);
  2. View successful login history and current sessions in Ubuntu

    Use the following commands to track user logins and active sessions on an Ubuntu system:

    • last: Displays the most recent login records and user login history.
    • who: Shows information about users currently logged into the system.
    • w: Provides detailed information about currently logged-in users, including login time and running processes.
    • lastlog: Displays the last login time for all system users.
    • whoami: Prints the username of the current effective user.
    • id: Displays the real and effective user and group IDs (UID/GID).
  3. Orchestrate MongoDB and Python services with Docker Compose

    Deploy a multi-service architecture consisting of a MongoDB database and several Python services (control, script, websocket) using Poetry. This configuration uses network_mode: host for port access and includes socat services to provide SSL termination for specific ports.
    version: '3'
    services:
      mongodb:
        image: mongo
        volumes:
          - ./mongo/data:/data/db
        restart: always
        ports:
          - "127.0.0.1:27017:27017"
    
      web_control:
          build: .
          image: ubt_py37
          restart: always
          volumes:
            - .:/root/project
            - ./cache:/root/.cache/
          working_dir: /root/project
          command: poetry run python ctrl.py
          network_mode: host
          depends_on:
            - "mongodb"
    
      web_socat_1:
          build: .
          image: ubt_py37
          restart: always
          volumes:
            - .:/root/project
          working_dir: /root/project
          command: socat ssl-l:8443,reuseaddr,fork,cert=cert/a.crt,key=cert/b.key,verify=0 tcp:127.0.0.1:8080
          network_mode: host
          depends_on:
            - "web_websocket"
  4. Tmux basic concepts and startup

    Tmux is a terminal multiplexer that allows multiple terminals to be created, accessed, and controlled on a single screen. Sessions continue to run in the background even after disconnection.

    • Session: A collection of windows.
    • Window: Occupies the full screen and can be split into panes.
    • Pane: A divided area within a window, each acting as an independent pseudo-terminal.

    By default, all Tmux commands are preceded by the prefix key: Ctrl+b (referred to as <prefix> in shortcuts).

    # Start a new tmux session
    tmux
    
    # Attach to an existing session
    tmux attach
  5. Manage filesystem paths using pathlib.Path

    pathlib.Path is the recommended object-oriented way to handle file system paths in Python. It provides a consistent API across different operating systems for creating, manipulating, and querying paths.
    from pathlib import Path
    
    # Create a path object
    p = Path('/path/to/file.txt')
  6. Manage Windows Time Service using w32tm

    W32tm is a Windows command-line utility used to configure and manage the system time service. It allows administrators to query the current time status, force synchronization, and monitor time sources.
  7. Understand Git core concepts

    Git operates using several key areas and pointers to manage version control:

    • Workspace: The directory of files you are currently editing.
    • Index / Stage: A temporary storage area for changes prepared for commit.
    • Local Repository: The complete project history stored on your local machine.
    • Remote Repository: A project repository hosted on a network server for team collaboration.
    • HEAD: A pointer that typically indicates the latest commit of the current active branch.
  8. Enable BBR congestion control on Linux

    BBR (Bottleneck Bandwidth and Round-trip propagation time) is a Google-developed congestion control algorithm that improves connection performance, especially for servers in poor network conditions or overseas. To enable BBR, you must set the default queuing discipline (qdisc) to fq and the TCP congestion control to bbr in the system configuration.
    # Add BBR configuration to /etc/sysctl.conf
    sudo sh -c 'echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf'
    sudo sh -c 'echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf'
    
    # Apply the changes
    sudo sysctl -p
  9. Install Python packages from various sources

    pip supports installing packages from domestic mirrors, remote Git repositories, or local directories containing wheel (.whl) files.
    # Upgrade pip using a specific domestic mirror
    pip install --upgrade pip --index-url https://mirrors.sustech.edu.cn/pypi/simple
    
    # Install a package directly from a git repository
    pip install git+https://github.com/*.git
    
    # Install packages from a local directory (Windows batch example)
    # This installs wheels without searching the index or installing dependencies
    for %x in (dest\*.whl) do (python -m pip install --no-index --no-deps %x)
  10. Block WPS Office network access using Windows Firewall

    Prevent WPS Office from accessing the network by creating inbound and outbound block rules for its executables (e.g., ksolaunch.exe and wpscenter.exe) in the Windows Defender Firewall Advanced Security settings.
    @echo off
    rem Create inbound and outbound rules to block ksolaunch.exe
    netsh advfirewall firewall add rule name="Block WPS Inbound" dir=in program="C:\Program Files (x86)\Kingsoft\WPS Office\ksolaunch.exe" action=block
    netsh advfirewall firewall add rule name="Block WPS Outbound" dir=out program="C:\Program Files (x86)\Kingsoft\WPS Office\ksolaunch.exe" action=block
    
    rem Create inbound and outbound rules to block wpscenter.exe
    netsh advfirewall firewall add rule name="Block WPSCenter Inbound" dir=in program="C:\Program Files (x86)\Kingsoft\WPS Office\wpscenter.exe" action=block
    netsh advfirewall firewall add rule name="Block WPSCenter Outbound" dir=out program="C:\Program Files (x86)\Kingsoft\WPS Office\wpscenter.exe" action=block
    
    pause