Knowlish

Little bits of tips ʼnʼ tricks I want to keep around.
You may find it useful too sometimes ^.^

By @MonoidMusician

Overflow

CLI

MacOS

Ubuntu (GNOME?)

  • MouseKeys fast: xkbset ma 60 10 10 5 2

Git

  • git clone --filter=blob:none <url> is a new better alternative to git clone --depth=1 <url> (with git clone --filter=tree:0 <url> skipping downloading trees but not recommended for dev work since it will redownload trees more often than necessary)

  • git push --set-upstream origin $(git branch --show-current)

  • View history of file (commits + patches): git log -p -- foo.sh

  • Local/private version of .gitignore: .git/info/exclude

  • Remove untracked and/or ignored files via git clean:

    • Untracked: git clean -f, dry-run: git clean -n
    • Ignored: git clean -fX, dry-run: git clean -nX
    • Both: git clean -fx, dry-run: git clean -nx
  • Current branch name: git branch --show-current

  • Upstream for current branch (pretty name): git rev-parse --abbrev-ref --symbolic-full-name @{upstream}

  • See what changes you are about to push: git diff @{u} HEAD

    Explanation

    First it finds the upstream @{u}/@{upstream} for the current branch.

    HEAD means to compare against the currently committed changes, not whatever files are in your working tree.

tmux

  • Detach: ctrl+b then d.
  • Reattach: tmux a.
  • Switch: ctrl+b then s.

Runtimes & Debugging

Browser JS

  • new URLSearchParams(window.location.search).{get,getAll,has,entries,...}(...)

    • .entries returns an iterator??
  • POST JSON to server:

    fetch('localhost', {
        method: 'POST', body: JSON.stringify(yourData),
        headers: { "Content-Type": "application/json" },
    }).then(r => r.json());

NodeJS

  • Full stack trace: NODE_OPTIONS='--stack-trace-limit=10000'
  • util.inspect.defaultOptions.depth = null; (no commandline option :sad:)

Erlang

  • io:format(user, <<"~p~n">>, [Object]) in tests and rp(Object). in the REPL
  • f(VarName) to unbind a variable in the REPL, f() to unbind them all.

Bash

Fish

  • cd (dirname (status -f)) (or status --current-filename)

    (do I need quotes? did we fix that in fish?)

  • Compare directory listings, excluding hidden files

    git diff --no-index (cd $ROOT1; find . -not -path '*/\.*' -type f | sort | psub) (cd $ROOT2; find . -not -path '*/\.*' -type f | sort | psub)

Nix

  • Nix test installation:

    nix-shell -p nix-info --run "nix-info -m"

GUI

VSCodium / VSCode

  • Language-specific settings: see https://code.visualstudio.com/docs/getstarted/settings.
    • Settings search: @lang:markdown. This will apply those settings to that language specifically!
      • You can discover this by clicking the filter icon at the far right of the search bar.
    • Json Settings: add a key with the language name in brackets, "[markdown]": { ... your settings ... }.
    • Can I just say how I miss Atomʼs settings menu? It was so clean, in comparison.
  • Extensions live in these places:
    • ~/.vscode-oss/extensions
    • ~/.vscode/extensions
    • /Applications/VSCodium.app/Contents/Resources/app/extensions
    • /Applications/VSCode.app/Contents/Resources/app/extensions
    • other OSes??
  • codium --list-extensions & codium --install-extension

Shortcuts

  • Keybinds for ctrl+(shift)+tab to just switch tabs, no “most recently used” switcher:

    Details

    From “Is there a quick change tabs function in Visual Studio Code?”:

    [
      {
          "key": "ctrl+tab",
          "command": "workbench.action.nextEditorInGroup"
      },
      {
          "key": "ctrl+shift+tab",
          "command": "workbench.action.previousEditorInGroup"
      },
    ]

    (or workbench.action.{next,previous}Editor to have it apply across windows instead of wrapping around)

    By default, Ctrl+Tab in Visual Studio Code cycles through tabs in order of most recently used. This is confusing because it depends on hidden state.

    Web browsers cycle through tabs in visible order. This is much more intuitive.

  • Right click to add file in same parent folder (extension)

  • Alt+up/down to reorder lines

  • Alt+click for multiselect

Highlighting

  • Weird bug where typing re in a markdown makes syntax highlighting wonky: it turns out to be caused by the extension file ocamllabs.ocaml-platform-1.*.*-universal/syntaxes/reason-markdown-codeblock.json, so you can just delete that whole file (you will have to do this at every update).

ffplay

  • p/Space to pause
  • s to step to next frame

Data Formats/Parsers

Scripts

  • Sum durations of A/V media (.mp3s in this case):

    for f in *.mp3; ffprobe -show_entries format=duration -v quiet -i $f | grep -oE '[[:digit:].]+'; end | awk '{s+=$1} END {print s}'

Misc

MacOS nonsense