Arcane programming magics

From razwiki
Revision as of 04:36, 8 January 2022 by Razzi (talk | contribs) (→‎shells)
Jump to navigation Jump to search

Software development has a high learning curve, in part due to the lack of discoverability of useful features.

Here are some useful things that I either learned by accident or by somebody else passing on their arcane wisdom to me.

git

  • .git/config is the text file that all the git configuration commands edit, and you can edit by hand.
  • git reflog shows you all git references ever visited; very useful for restoring work thought to be lost.
  • set environment variable GIT_TRACE to see what git is doing when it doesn't do what you'd expect

ssh

  • you can close an unresponsive ssh session with ~.
  • ssh is really hard to get working as intended; add verbosity with ssh -vv <domain> to potentially get an idea of what the program is doing and what you can do

shells

  • exit status 0 is success, so conditionals like if <some command that succeeds> use inverted logic from the usual "if true"
  • you can see the exit status with echo $? in bash / zsh or echo $status in fish
  • hit control-t to transpose characters around the cursor in shell (and most macos text inputs). Very handy to correct typos
  • colored text (and a lot of shell features) are based on "printing" escape sequences; for example echo -e '\e[0;33mhi\e[0;37mthere'
  • in addition to control-c "interrupt" to exit a process, you can control-\ "whack" a process to force kill it
  • aliases in bash and abbrs in fish will save you a lot of typing

javascript

  • putting the word debugger in your code will pause at that point if you have devtools open

python

  • in ipython, type a question mark after an object to see some info about it, and 2 question marks to see its source code. Also works in jupyter
  • the current directory cannot be imported from by default. EXPORT PYTHONPATH=. to import from the current directory

routers

  • you can access your router settings at 192.168.0.1 or sometimes 192.168.1.1. If that doesn't work some routers have magic log-in pages that the routers intercept, like router.asus.com

computer hardware

  • there's this battery on your motherboard that keeps the circuit "on" so that low-level settings can be persisted. If you pop it out and put it back in, it will reset your basic computer settings
  • if a laptop won't turn on at all, try disconnecting the battery and connecting it to power. This kept my 2014 macbook air working for years

macos

  • command-shift-4 takes a screenshot; from the reticule interface you can drag for a rectangle or hit space to capture a window.
  • command-control-shift-4 takes a screenshot and copies it to your clipboard
  • command-down opens a file from the file browser. I wish return did this but that renames it.
  • command-up goes up the file hierarchy.
  • You can change volume by sub-rectangle increments: hold option+shift and hit the brightness keys

mediawiki

  • adding a space to the start of a line in source editing mode will make it monospaced like a <pre>