hystking / Yuhei Nakayama / gon

@hystking

Commit activity

34 commits in the last 30 days

longest streak 23 dayscurrent 23

1,077 / 2,500 XP1,423 XP to root

Today

Lost commits after a bad git reset --hard? They're probably still there.
git reflog
git branch rescue <sha>
git reflog records everywhere HEAD has been. Find the SHA, park it on a branch, and you're back.

Yesterday

Need to find the commit that added or removed a string? Skip the log scroll:
git log -S "retryCount" --oneline
-S (the "pickaxe") lists commits where the number of occurrences of that string changed. Add -p to see the actual diff.

Tue, Nov 10

Check a URL's status code without downloading the body:
curl -s -o /dev/null -w "%{http_code}\n" https://example.com
-o /dev/null throws away the response, and -w prints only the format you ask for. It's handy for health checks in a loop.

Mon, Nov 9

Sun, Nov 8

Bash scripts fail quietly by default. Add this line near the top:
set -euo pipefail
-e exits on the first error, -u catches typos in variable names, and pipefail makes a pipeline fail if any stage fails, not just the last one.

Sat, Nov 7

Switched branches and want to jump back?
git switch -
Like cd -, it returns to the branch you checked out last. Run it again to toggle between the two.
Wait until you pair that with git merge - or git rebase -. The shorthand @{-1} works across almost every git command that takes a branch ref.

Fri, Nov 6

Filenames with spaces breaking your xargs pipeline?
find . -name "*.txt" -print0 | xargs -0 wc -l
-print0 ends each path with a null byte instead of a newline, and xargs -0 splits on that. Spaces and tabs in names are now harmless.
Pairing -print0 with xargs -0 or using find with -exec ... + is the only way to survive user-uploaded filenames that have spaces and quotes in them.

Thu, Nov 5

Which commit broke the tests? Let git find it:
git bisect start HEAD v1.4.0
git bisect run npm test
Git binary-searches the history and stops at the culprit. Exit code 0 is good, anything else is bad. Done? git bisect reset.

Wed, Nov 4

Port already in use? Find what's holding it and stop it:
lsof -ti :3000 | xargs kill
-t prints only the PIDs, so kill gets exactly what it needs. Swap in your port number. Handy for the "address already in use" moment.

Tue, Nov 3

Copy a file's contents to your clipboard on macOS, no selecting required:
pbcopy < notes.txt
Then Cmd+V anywhere. pbpaste goes the other way, dumping the clipboard to stdout. Pipe it into jq or grep and you're done.

Mon, Nov 2

Sun, Nov 1

Sat, Oct 31

Fri, Oct 30

Thu, Oct 29

Wed, Oct 28

Tue, Oct 27

Compare two commands' output without temp files:
diff <(sort old.txt) <(sort new.txt)
<(...) is process substitution. The shell gives diff a fake file that holds each command's output. Works in bash and zsh.

Mon, Oct 26

Sun, Oct 25

Need to check a URL's status code or headers without downloading the page?
curl -I https://example.com
-I sends a HEAD request and prints only the headers. Good for spotting redirects, caching rules, and content types.

Sat, Oct 24