Dev Toolbox

website·Indexed 29 days ago

https://rashedmakkouk.github.io/dev-toolbox

A collection of development guides, DevOps templates, and best practices covering Git, GitLab, Kubernetes, Docker, Nginx, TypeScript, and OS-specific configurations for Windows, Linux, and WSL 2.

Tokens
12K
Snippets
105
Records
122
Agent score
74%

What's inside Dev Toolbox

  1. Inspect Git configuration and remote URLs

    Use these commands to view the current Git configuration list, detailed information about the remote named 'origin', or specifically retrieve the remote origin URL.
    git config --list
    git remote show origin
    git config --get remote.origin.url
  2. Identify running OS release and version

    Use these commands to determine the Linux distribution, version, and kernel architecture.
    cat /etc/*release
    lsb_release -a
    cat /etc/debian_version
    uname -mrs
    
    # Extracting specific ID and NAME from os-release
    source /etc/os-release
    echo $ID
    echo $NAME
  3. Structure git commit messages

    Follow these rules when writing commit messages to ensure consistency and clarity:

    1. Multi-line Tasks: Use two separate messages. The first should be a general overview of the commit, and the second should provide detailed information.
    2. Headers:
      • Use Summary: as the header for blocks listing specific commit changes.
      • Use Changelog: as the header for blocks listing changes that must be included in the CHANGELOG.md file.
    3. Formatting: Each commit change message must start with a capital letter immediately following its type prefix.
    4. Prefixes: Every commit change message must be prefixed with a specific change type.
  4. Merge an external Git repository into a monorepo while preserving history

    To move an external repository into a monorepo subdirectory while keeping its commit history, you must first rewrite the history of the external repo so that all files are located in the target directory before merging. This prevents files from being merged into the root of the monorepo.
    # 1. Clone the external repository to a local directory
    git clone <repo-url> <package>
    cd <package>
    
    # 2. Rewrite history to move all files into the target monorepo path
    export TARGET_DIR="packages/<package>"
    
    git filter-branch --prune-empty --tree-filter ' 
      mkdir -p "$TARGET_DIR"
      git ls-tree --name-only $GIT_COMMIT | xargs -I files mv files "$TARGET_DIR"
    '

    Note: The --prune-empty flag is used to remove commits that become empty as a result of the history rewrite.

  5. Organize Nginx configuration using Bases, Upstreams, and Sites

    To maintain a scalable Nginx setup, use the following directory structure within the conf/ folder:

    • conf/bases: Centralized, reusable common configurations and server block best practices.
    • conf/upstreams: Definitions of hosts used for proxying requests and load balancing. These are referenced in server blocks via the proxy_pass key within a location block.
    • conf/sites-available: Inactive server block templates (e.g., domain.com.conf for production, http-to-https.conf for SSL redirection, and non-to-www.conf for WWW redirection).
    • conf/sites-enabled: Active server blocks currently being loaded by the Nginx root config (e.g., domain.dev.conf for development).
  6. Mount a formatted disk to a directory

    To make a formatted disk accessible in the Linux filesystem, create a mount point directory in /mnt/ and mount the device using the appropriate filesystem type (e.g., ext2).
    # Create directory to map disk to
    mkdir /mnt/<dirname>
    
    # Mount disk to directory
    mount -t ext2 /dev/sdb /mnt/<dirname>
  7. Perform MySQL database operations in Docker

    Commands for managing MySQL instances running in Docker, including user creation, exporting dumps, and restoring dumps.
    -- Create new database user
    CREATE USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
    GRANT ALL ON *.* TO 'username'@'%';
    FLUSH PRIVILIGES;
    # Export database dump to host file
    docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
    
    # Restore database dump from host file
    docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE < backup.sql
  8. Bulk transfer GitHub issues to another repository using gh CLI

    To transfer multiple issues from a local repository to a target repository, use a combination of gh issue list to retrieve issue numbers and xargs to execute the gh issue transfer command for each issue.

    The command retrieves the issue numbers in JSON format, parses them using jq, and pipes them into the transfer command.

    gh issue list -s all -L 500 --json number --jq '.[].number' | \
    xargs -I % gh issue transfer % <target-repository>
  9. Implement Conventional Commits structure

    Follow the Conventional Commits specification for structured commit messages: <type>[optional scope]: <description>.

    Common types include:

    • feat: New feature
    • fix: Bug fix
    • docs: Documentation only
    • style: Formatting/white space
    • refactor: Code change that neither fixes bug nor adds feature
    • perf: Performance improvement
    • test: Adding/correcting tests
    • chore: Build process/auxiliary tools
    • ci: CI configuration
    • build: Build system/external dependencies

    Breaking changes are indicated by a ! suffix on the type or by using the BREAKING CHANGE: footer.

    # Example Breaking Change
    refactor!: Breaking change message
    
    # Example with footer
    fix!: New feature message
    
    BREAKING CHANGE: Breaking change message