Skip to content

Instantly share code, notes, and snippets.

@umstek
Last active January 16, 2024 13:07
Show Gist options
  • Save umstek/156df8cc990f2f495c7ff0a4ea8a67eb to your computer and use it in GitHub Desktop.
Save umstek/156df8cc990f2f495c7ff0a4ea8a67eb to your computer and use it in GitHub Desktop.
Useful commands

Delete all node_modules folders

find . -name "node_modules" -prune -exec rm -rf '{}' +

Flatten directory structure

find /dir1 -mindepth 2 -type f -exec mv -t /dir1 -i '{}' +

Set user name and email for Git

git config --global user.name "Your Name"
git config --global user.email you@email.provider

--global sets this for the whole user.

Set vscode as Git editor (for commit message etc.)

git config --global core.editor "code --wait"

Do not convert line endings in Git

git config --global core.autocrlf false

Make git push without setting upstream manually

git config --global push.autoSetupRemote true

Find the branch you were working on by providing a change committed to that branch

git log --oneline -S "whatever you want to search" --source --all

Create a keypair

Private key

openssl genpkey -algorithm ed25519 -out private.pem

Public key

openssl pkey -in private.pem -pubout -out public.pem

Connecting to OpenVPN3 VPN

Import

openvpn3 config-import --config config.ovpn

Connect

openvpn3 session-start --config config.ovpn

Disconnect

openvpn3 session-manage --disconnect --config config.ovpn

Rename local git master branch to main after having renamed it in the remote

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

Create tar.gz archive from folder

Use sudo to avoid any permission errors.
You may want to v flag out if you can't determine the cause in case of an error.

tar -czvf whatever.tar.gz folder

Allow application to bind to privileged port without sudo

Note: It's better to run your program on a non-privileged port and use a webserver like nginx if that's applicable.

setcap 'cap_net_bind_service=+ep' /path/to/program

Show all merge commits since the last tag

git log $(git describe --tags --abbrev=0)..HEAD --oneline --merges --first-parent

Delete files when it says argument list is too long

find . -type f -name "*.log" -print0 | xargs -0 rm

Run process in background even after you quit SSH session

nohup ts-node scripts/script.ts &> script.log &

Possible fix to the error FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

export NODE_OPTIONS="--max-old-space-size=8192"
# then run the script

Script to find all folders in ~/src those are not pushed, not committed, or are not git repositories (ChatGPT) for backing up

#!/bin/bash

src_dir=~/src

# Define color codes
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m' # No color

for dir in "$src_dir"/*/; do
    repo_dir="$dir"
    
    if [ -d "$repo_dir/.git" ]; then
        cd "$repo_dir"
        
        if [ -z "$(git status --porcelain)" ]; then
            echo -e "${GREEN}Repository at $repo_dir is clean.${NC}"
        else
            if [ -n "$(git ls-files --exclude-standard --others)" ]; then
                echo -e "${RED}Repository at $repo_dir has untracked files.${NC}"
            fi
            
            if [ -n "$(git diff --stat)" ]; then
                echo -e "${RED}Repository at $repo_dir has uncommitted changes.${NC}"
            fi
            
            if [ -n "$(git log --branches --not --remotes)" ]; then
                echo -e "${RED}Repository at $repo_dir has unpushed commits.${NC}"
            fi
        fi
    else
        echo -e "${YELLOW}$repo_dir is a project directory without a Git repository.${NC}"
    fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment