Skip to content

Instantly share code, notes, and snippets.

Terminal Tips & Tricks

  • Pretty prompt
    # Start colored text with:
    #   %F{red}
    # End colored text with:
    #   %F{red}
    # %n    : user name
    # %m    : computer name
    # %/    : current dir
#!/bin/sh
# We don't need extra husky dependency for a simple task
COMMIT_LINT_HOOK_PATH="$PWD/.custom_git_hooks"
COMMIT_LINT_CMT_MSG_HOOK_PATH="$COMMIT_LINT_HOOK_PATH/commit-msg"
ensure_hook_dir() {
if [ ! -d "$COMMIT_LINT_HOOK_PATH" ]; then
mkdir "$COMMIT_LINT_HOOK_PATH"
#!/bin/zsh
line_lengths=($(git log --pretty=format:%s | awk '{ print length($0) - 9 }'))
sum=0
line_count=${#line_lengths}
for line_length in ${line_lengths[@]}; do
sum=$((sum + line_length))
done
const fs = require('fs');
const path = require('path');
const target_dir = process.argv[2];
fs.readdir(target_dir, function(err, items) {
for(var i = 0; i < items.length; i++) {
nfd_name = items[i];
nfc_name = items[i].normalize('NFC');
console.log(`nfd_name: ${nfd_name}\nnfc_name: ${nfc_name}`);

Build

user@host $ mkdir node-arch && cd node-arch
user@host $ vim Dockerfile

Dockerfile

FROM ubuntu:20.04

RUN apt update &amp;&amp; apt install -y vim git libaio1 curl build-essential gettext-base
extension Data {
var hexDescription: String {
return reduce("") {$0 + String(format: "%02x", $1)}
}
}

Install Lima

username@mac:workdir $ brew install lima

Prepare Docker-CLI & Docker Compose

Using Homebrew

username@mac:workdir $ brew install docker docker-compose
username@lima-docker:/Users/username$ echo '{ "insecure-registries": ["REGISTRY_HOST:REGISTRY_PORT"] }' > $HOME/.config/docker/daemon.json
username@lima-docker:/Users/username$ systemctl --user daemon-reload
username@lima-docker:/Users/username$ systemctl --user stop docker
username@lima-docker:/Users/username$ systemctl --user start docker
#!/bin/bash
# IMPORTANT: Don't forget to logout from your Apple ID in the settings before running it!
# IMPORTANT: You will need to run this script from Recovery. In fact, macOS Catalina brings read-only filesystem which prevent this script from working from the main OS.
# This script needs to be run from the volume you wish to use.
# E.g. run it like this: cd /Volumes/Macintosh\ HD && sh /Volumes/Macintosh\ HD/Users/sabri/Desktop/disable.sh
# WARNING: It might disable things that you may not like. Please double check the services in the TODISABLE vars.
# Get active services: launchctl list | grep -v "\-\t0"
# Find a service: grep -lR [service] /System/Library/Launch* /Library/Launch* ~/Library/LaunchAgents
@crowjdh
crowjdh / export keychain.scpt
Created March 11, 2022 15:32
Open Keychain/Sublime Text(or any editor), select first item, run the script
openKeychain()
-- Count how many entries you have, or just pick one.
-- Having excessive number won't hurt.
repeat 300 times
tell application "System Events" to keystroke return
copyPastePlainTexts()
copyPastePassword()
openKeychain()