Arcane programming magics

From razwiki
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
  • set -x in bash and friends will log every command, including nested functions. This is extremely useful for debugging build environments where you are not presented with a repl and have to submit a job just to iterate
  • there are a ton of ways to look at local documentation: man, apropos, whatis, <command> --help, <command> <subcommand> --help, tldr
  • "the command line" is actually composed of 2 distinct programs: the terminal emulator (such as Terminal.app or the vim emulated terminal) and the shell (such as bash). Knowing which one is having an issue you're trying to figure out makes searching for help much easier

javascript

  • putting the word debugger in your code will pause at that point if you have devtools open
  • though frowned upon, tools like "alert()" and "confirm()" are very easy to implement and useful for debugging
  • html elements are executed in the order they are found, so a javascript tag before some html will not see the html when it loads. Putting javascript at the bottom of the page solves many newbie issues

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 be able 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
  • it's possible to run out of battery while a device is still plugged in. Sometimes this is due to using a suboptimal charger, other times even with a standard charger the cpu is just taking too much power

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
  • you can lower the brightness down to 0, at which point you can see the screen is still displaying if you look closely. Sometimes when it seems your computer is unresponsive the screen is just off

mediawiki

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