Snippets

Snippets are super brief notes for my own use. I'd hoped that Twitter would be a convenient place to store tiny notes, but its not searchable enough. This page should allow quick browsing and searching for things I know I knew or saw in the past.

July

Checkout the branch where you want the file to by copied to, then:

git checkout <other-branch> <relative-file-path or directory>
  • Use a commit hash to pull files from any commit
  • Multiple files and directories can be specified
  • Overwrites the file

SO

14 July 2021
git

Zwischenzugs blog post arguing that to achieve a significant change in an organisation you need need to:

  1. Get funding.
  2. Persuade the finance department to give you money.
  3. Understand what they value.
  4. Understand their cash flows.
  5. Understand how and why customers or clients part with their money.
  6. Understand business constraints (legal, reg, operating).

The five whys approach to problem solving

Consider a deeper structural cause of cultural problems in change management: how money flows through the organisation.”

If you want to transform IT in an enterprise, start with finance. If you can crack that, you’ve a chance to succeed with sec and controls functions. If you don’t know why it’s important to start with finance, you’ll definitely fail “

14 July 2021
engineering
organisations
business
corporations

Hilarious article from UI Collecitve showing the results of a competition to design the worst possible volume control interface. 😂 😂 😂

14 July 2021
ui

Yesterday my daughter asked me to write a page in her Freundebuch.

12 July 2021
family

Of all tyrannies, a tyranny sincerely exercised for the good of its victims may be the most oppressive. It would be better to live under robber barons than under omnipotent moral busybodies.

The robber baron’s cruelty may sometimes sleep, his cupidity may at some point be satiated; but those who torment us for our own good will torment us without end for they do so with the approval of their own conscience. They may be more likely to go to Heaven yet at the same time likelier to make a Hell of earth.

This very kindness stings with intolerable insult. To be “cured” against one’s will and cured of states which we may not regard as disease is to be put on a level of those who have not yet reached the age of reason or those who never will; to be classed with infants, imbeciles, and domestic animals.

- C. S. Lewis

12 July 2021
oppression
consent

Blog post about how to make it easier to upgrade a cryptographic or hashing library.

Django encodes passwords for database storage like this:

<algorithm>$<iterations>$<salt>$<hash>

Interestingly, Giovanni Collazo emphasises that we should design systems for change, which initially seems pretty close to contradicting YAGNI, but the answer lies in the context.

10 July 2021
hashing
versioning

Lessons of a startup engineer is a great blog post from Todd Wolfson. So great that I might write notes on it like I would a book.

archive

10 July 2021
startup
engineering

A great article introducing and showing the relevance of Poisson’s Equation.

06 July 2021
math

His works in English and Latin.

06 July 2021
theology
history

June

30 June 2021
art
painting
photography

I have learnt that failure is my greatest teacher”

- Georges St-Pierre

29 June 2021
meta
advice

Contains too much conjecture at the start, but becomes more substantial.

At high levels of competition the difference between “good” and “great” is partly determined by how much pain you are willing to experience.

There are great benefits from training in a secondary discipline.

  • Anderson Silva is a ballet dancer.
  • Conor McGregor does “movement training”.
  • Israel Adesanya dances competitively.
  • Georges St-Pierre practices gymnastics.

archive

29 June 2021
sport
meta
training
23 June 2021
django
saas
startups
python

A series of scenes showing the character of Alfie Solomons from Peaky Blinders.

movie

22 June 2021
movie
youtube
peaky-blinders
humanity

Rabbits, fluid convection, the Mandelbrot set and lots of others things too. Also known as bifurcation theory.

The video shows how the Feigenbaum Constant is defined. It’s a fundamental constant I hadn’t come across before - 4.6692..

17 June 2021
math
chaos

article

An Apple onion router. The routing uses two hops; Apple provides the first, and independent third parties (not yet specified) provide the second.”

In one move, Apple has taken onion routing from a specialized tool for hackers to something that will be in daily use.”

16 June 2021
apple
onion
vpn
icloud

rich module python -m rich for a demo

Cool Python module to handle terminal output with debugging and logging features. It can even record stack trace errors to html.

16 June 2021
python
console
shell

An amateur practices until they can play it correctly, a professional practices until they can’t play it incorrectly.

16 June 2021
proverb
  • Invoked with s followed by 2 chars.
  • S goes backwards.
  • F, f, T, and t are enabled to work across lines.
  • Jump back with <C-O>
  • ; or , to go to next/previous highlighted text.
  • 5sxy searches for the next instance of xy within 5 lines.
  • 3dzqt delete up to the third instance of qt.

repo

15 June 2021
vim
plugin

A basic statement that is assumed to be true. E.g: “A straight line can be drawn between any two points”

12 June 2021
math

wikipedia

Hedgehogs know one big thing, Foxes know many things.

A classification system or mental model for writers and thinkers.

12 June 2021
meta
classification
thinking
12 June 2021
pair-programming
vim
tmux
ssh

A lobster diver was swallowed by a humpback whale. Then it spit him out. Humpback whales don’t have teeth, and have reduced forward vision when they open their mouths to feed.

article
archive

12 June 2021
whale

Key commands

  • git lfs install (also uninstall)
  • git lfs track "**/*.mp4"
  • git lfs ls-files
  • git lfs status

track just updates the .gitattributes file.

Commit the .gitattributes file with the tracking configuration before committing the large files.

status or ls-files should show the large files in question before you push the commit that starts tracking the large files.

11 June 2021
git
lfs
github-pages

Blog post demonstrating how to split a .bashrc file into “submodules” and keep it maintainable.

BASHRC_D=~/.config/bashrc.d
[[ -r ${BASHRC_D}/bootstrap ]] && . ${BASHRC_D}/bootstrap
for file in ${BASHRC_D}/*.sh; do
  [[ -r $file ]] && . $file
done
unset file
11 June 2021
bash
shell
zsh

The exhausted moments after running for almost 60 hours through impassable terrain:

movie

10 June 2021
movie
running
barkley
youtube

An essay called A project of ones own by Paul Graham.

  • being pushed into a task vs being pulled
  • skating vs walking
08 June 2021
paul-graham
meta
learning
school

May

Something should happen within 100ms of the users input in order to maintain a feeling of responsiveness.

If something happens within 50ms of the trigger event, it will feel almost instant.

Also, checkout hyperfine for performance benchmarking.

Lots of useful tips in the original blog post.

28 May 2021
shell
  • [s or ]s → go to next/previous bad word
  • z= → list of suggestions
  • zg → add word to good word list
  • zug → remove word from good word list
  • zw → add word to bad word list
  • zuw → remove word from bad word list
27 May 2021
vim
grep -inr --include package.json \
    'shortcut": {' . -A 3
  • It’s the --include flag that does the important part.
  • -i → case insensitive
  • -n → print line number
  • -r → recursive from starting page
  • . → start in current directory
  • -A 3 → print the 3 lines below the found line
18 May 2021
grep
linux

:map → show a list of the current keyboard mappings for normal, visual, select and operator pending modes.

:map! → show a list of the current keyboard mappings for insert and command-line mode

Top put all the mappings into a convenient text file:

:redir! > vim_maps.txt
:map
:map!
:redir END

source another source

18 May 2021
vim

This blog post arrives at the conclusion that the only way to take good paper notes is to organise them chronologically, and only summarise the content once the notebook is full.

Keep it simple, trust your intuitions.

simplerobustreliable

Also, it links to zettelkasten.de/the-archive

18 May 2021
zettelkasten
notes
knowledge-system

Without training, they lacked knowledge. Without knowledge, they lacked confidence. Without confidence, they lacked victory.”

- Julius Caesar

14 May 2021
quote
caesar
wisdom

I know about ImprovMX, which used to be great because you could do a lot for free, but now you only get 1 domain for free.

ForwardEmail are 3 times cheaper than ImprovMX, and I have 2 domains forwarding email. It’s not particularly private, but I can send and recieve from a domain, for free.

14 May 2021
email

A snippet detailing how to use nested auto commands to apply custom modifications when a colorscheme is loaded. Perhaps this will stop me :e-ing so frequently.

13 May 2021
vim

A useful collection of gists by Romain Lafourcade

A gist about netrw.

13 May 2021
vim
netrw

See where an option was set in vim using the following command:

:verbose set textwidth?

12 May 2021
vim
  • ???? → 4 chars
  • * → any number of chars
  • [:upper:][A-Z] same for [:lower:] and [:digit:]
  • [:alpha:][a-zA-Z]
  • [:alnum:][a-zA-Z0-9]

  • ls -l [a-d] → part of a range

  • ^ and $ works like in regex
  • la a*.{doc,docx}OR
  • ls a*.(doc|docx)OR
10 May 2021
linux

Create a custom command and function to create a new file in vim.

command! -nargs=1 Ms call s:NewFile(<q-args>)`

function! s:NewFile(fp)
  echom a:fp
  execute "e " . "~/foo/bar/" . a:fp . ".ext"
endfunction

Useful help:

  • :h %:h → filename modifiers
  • :h expand() → expand wildcards, including filename modifiers

question on SO

05 May 2021
vim
  • target function arguments
  • more types of object
  • consistent searching/jumping if you’re not inside the thing you’re targeting
  • jump forward or backward
  • look for the nth occurrence
  • select white space around/inside object

Github
Article about a plugin

05 May 2021
vim
  • <C-h> - same as backspace
  • <C-w> - delete previous word
  • <C-u> - delete everything before cursor (on same row)
  • <C-d> or <C-t> - (un)indent a row
  • <C-e> - delete next word (create a mapping in vimrc)
05 May 2021
vim

If you want to alias a bunch of arguments for a command, use global aliases:

alias -g foo="some complicated options"

grep some complicated options

becomes: grep foo

https://www.thorsten-hans.com/5-types-of-zsh-aliases/

05 May 2021
alias
linux

It’s annoying when you delete something and overwrite your yanked text.

Use numbered registers! "0 to "9

"0 contains the most recent yank. "1 contains the most recent deleted text

"0p - paste the most recent yank, even if you deleted something after yanking it

05 May 2021
vim
linux
text

Chezmoi is a great tool for managing dotfiles. This is a shortcut to update the source state based on local changes.

chezmoi status | cut -c 4- | xargs -I % -p sh -c 'chezmoi add ~/%'

Github

05 May 2021
dotfiles
alias

“It enhances your memory and makes you more creative. It makes you look more attractive. It keeps you slim and lowers food cravings. It protects you from cancer and dementia. It wards off colds and the flu. It lowers your risk of heart attacks and stroke, not to mention diabetes. You’ll even feel happier, less depressed, and less anxious.”

Why We Sleep by Dr. Matt Walker

04 May 2021
sleep
lifestyle

How to write robust bash scripts:

Bash Strict Mode

04 May 2021
bash
linux

An often recommended blog post by Kaleigh Moore about writing a good about page.

04 May 2021
writing

/etc (etsy) → “etcetera” or “editable text config” → a place to put config files.

Originally, the root directory had /boot for booting, /dev for devices… One dir for each type of thing. But this put config in many places. so etc/ became convention

02 May 2021
linux
filesystem

April

Blog post about browser/Web-app security, including:

  • CSRF
  • CORS
  • HTTP Security Headers
30 April 2021
xss
cors
http

From an Interview:

I don’t want to claim that programming is an art, because it really is mostly just about ‘good engineering’. I’m a big believer in Thomas Edison’s ‘one percent inspiration and ninety-nine percent perspiration’ mantra. It’s almost all about the little details and the everyday grunt-work.

But there is that occasional ‘inspiration’ part, that ‘good taste’ thing that is about more than just solving some problem - solving it cleanly and nicely and yes, even beautifully.

29 April 2021
linux
interview
linus

A RPC is when an executable causes a procedure (subroutine) to execute on another computer, It’s coded as if it were a normal (local) subroutine. You don’t explicitly code the details for the remote interaction. You write the same code whether the subroutine is local or remote.

29 April 2021
rpc
linux

Just found a really useful blog

Interesting discussion about the difference between builtins and executables,

Nice examples of using fzf to improve workflows.

29 April 2021
linux
shell
fzf
workflow
zsh
bash
builtin

lsblk is a command to get info about connected devices.

Used when attaching drives.

28 April 2021
unix
cli

A console based file manager with vi key bindings.

Install it with brew install ranger

Launch it with ranger

28 April 2021
ranger
unix
vim
tools

This is a great article about using regular expressions in Vim:

marcelfischer.eu/blog/2019/checkbox-regex/

28 April 2021
vim
regex

where <executable>

See a list of all builtin commands man where

25 April 2021
unix
macos
cli
bash

Make aliased files the real file

for f in $(find . -type l -maxdepth 1);
    do cp --remove-destination $(readlink $f) $f;
done;
20 April 2021
macos
linux
cli
bash

swap-window -s 3 -t 1

19 April 2021
tmux
macos
linux
cli

Save (write) a (read only) Vim file with sudo when you opened it without sudo-ing:

:w !sudo tee % > /dev/null

17 April 2021
vim
macos
linux

Broot is a tool that shows the contents of a directory on one screen, even its got lots of files or sub-directories.

13 April 2021
broot
macos
cli

I added keyboard navigation to my blog and it works really well. Now I find myself trying to use the same shortcuts on other sites.

12 April 2021
blog
jam
jquery

I should see if I can use GitHub actions to generate html from markdown and run some shell and python scripts.

10 April 2021
github
blog

Its more socially acceptable to make mistakes and errors of omission than commission.

10 April 2021
meta
thinking
advice

There is a similar tool, with a list of other similar tools here

07 April 2021
cli
unix
macos

An example of a safe, good, robust bash file skeleton.

06 April 2021
bash

I was running a binary in Debian that was complaining about an environment variable not existing. I moved the binary into a $PATH directory and logged in as a sudo user. Why did this solve the problem?

05 April 2021
debian
binary
path

As a hacker, or creator, or whatever the best label is, I always want to create something (usually code) and have it finished.

But a strange creativity and productivity boost comes from dabbling, dipping in and out.

I think that if the technical challenges aren’t too hard, then the main criteria for success is creativity.

Creativity needs time away from the project, and sleep, to bubble up and let ideas grow.

Ultimately, the most successful path is usually the most interesting, because success has more consequences than failure. “Interesting” requires elements of novelty and surprise, and without creativity these elements can’t flourish. 3/n

Dabbling results in more creativity than 6+ hours of strenuous work, and is more likely to give you satisfying results.

01 April 2021
meta
thinking
advice

bar << foo bar will stop reading input when it reached “foo”.

bar <<< "foo" foo is all the input. bar wont run interactively.

bar < <(foo:list) process subscription. Kind of like piping in the output of multiple commands.

Stack Overflow

01 April 2021
bash
syntax

March

console.info(`${JSON.stringify(foo, null, 2)}`);
31 March 2021
typescript
json
syntax

analystsnow.com looks like a really useful business.

30 March 2021
entrepreneur
saas

Frantic distraction via productive procrastination is exhausting, and useful.

30 March 2021
meta
thinking

<C-w>x - swap buffers, but keep arrangement the same

<C-w>H - make the current split cover the left of the screen.

J, K, L covers the bottom, top, right of the screen

29 March 2021
vim

A guide about writing plugins for Pelican.

Thanks @geographeur

29 March 2021
pelican
plugin
guide

I tried to read and write the same file in a pipeline, and got caught out by a race condition (why is the file empty?!). Do this instead:

some_script < file > smscrpt.$$ \
&& mv smscrpt.$$ file || rm smscrpt.$$

|| removes the temporary file if it errors.

$$ is the process ID and ensures that you always have a unique temporary file name.

24 March 2021
shell
pipe
syntax
bash

jj - A stream editor
jq - A json processor
python -m json.tool

I like jq for pretty printing JSON output, jj for making JSON pretty or condensed.

This was really useful when optimizing the search index for this blog.

24 March 2021
json
docker run -d ...
docker logs -f <ID>
docker run -it ...
docker run -itd
docker container attach <ID>
<C-p><C-q> -> detach from container interactively

stack overflow

17 March 2021
docker

Probably it’s one you just curl-ed

curl -sSfL https://example.com/install.sh | sh -s
11 March 2021
bash
syntax
shell

Split long strings (or command outputs) onto multiple lines Find and replace a particular char (maybe :) with a \n.

... | tr ':' '\n'

... | sed 's/:/\n/g'
10 March 2021
bash
linux
  1. Without noticing, create a .gitignore file with a single * in it.
  2. Spend a day trying to understand why ripgrep has stopped working for only 1 project.
  3. 😭😭😭
10 March 2021
ripgrep
fail

Teaching my kids about money and work is having an effect.

Yesterday, my daughter made a painting for me and asked my to buy it using pretend money.

05 March 2021
parenting
kids
money
teaching
sudo groupadd docker -> make the group 
sudo gpasswd -a $USER docker -> add $USER to the docker group
newgrp docker -> activate the changes
05 March 2021
sudo
docker
linux

If you’re cat-ing a file and the bash prompt doesn’t start on a new line (cos the file you displayed using cat doesn’t end with a new line char) the following will fix it:

cat <filename> ; echo

05 March 2021
cat
linux
bash
shell
adduser -m <username>
usermod -aG sudo <username>

CentOS:

adduser -m <username>
passwd <username>
usermod -aG wheel <username>

(wheel is a usergroup with sudo permissions)

04 March 2021
sudo
linux
user
admin

df -h

Show disk space

du -hs .

See how big the current dir is

03 March 2021
linux
du
df
shell
cli

Cloning large repos, or repos with large files in them, doesn’t work with git clone ... you need to use git lfs clone ...

So why is git lfs clone deprecated? What’s the replacement?

03 March 2021
git
git-lfs

Use nohup to keep a curl process running even when the terminal (tty?) session autocloses at 3am.

02 March 2021
linux
cli

You can group shells into groups:

  1. ksh - korn shell and zshell
  2. sh - bourne shell and bash (the bourne again shell)

Because

  • zsh isn’t a superset of bash.
  • bash is a superset of the bourne shell.
02 March 2021
zsh
bash
bsh
linux
cli

November

Two nights ago, I dreamt I was experimenting with Emacs..

27 November 2020
emacs
dream