Small Programming Tricks
Day to day, I think a surprising amount of engineering productivity comes from small nuggets of knowledge: being aware that a language feature exists; knowing that an unexplained tcp delay is probably related to the TCP_NO_DELAY setting and Nagle’s algorithm; knowing the right git incantation to get out of a pickle; or knowing a trick with sed to rewrite a file.
In one sense, this is self-evident: anything you know is going to be made up of smaller pieces of knowledge. Of course those smaller pieces of knowledge matter.
But I think there are some nuggets of knowledge that are particularly valuable and don’t require a lot of supporting mental infrastructure. You don’t need to know any python to use python3 -m http.server to start a simple server in a directory, but it might still make your work marginally easier. Let me share a few examples:
You probably know that ctrl + r allows searching your terminal’s command history, but if you install fzf, you can set it up so that ctrl + r does a fuzzy search. If you want even more power, atuin replaces your shell history with a searchable SQLite database. per-directory-history lets you switch back and forth between searching for commands that have been run in a specific directory or searching all previous commands. Finally, you can configure how much history to store: stackoverflow question.
allows searching your terminal’s command history, but if you install fzf, you can set it up so that does a fuzzy search. If you want even more power, atuin replaces your shell history with a searchable SQLite database. per-directory-history lets you switch back and forth between searching for commands that have been run in a specific directory or searching all previous commands. Finally, you can configure how much history to store: stackoverflow question. You can SELECT without a FROM . This can be useful for testing out how a function in your database actually works or reminding yourself how SELECT TRUE <> NULL works.
without a . This can be useful for testing out how a function in your database actually works or reminding yourself how works. PostgresSQL and MySQL both support explain analyze which will actually run the query you’re trying to optimize and give you a ton more information about its performance.
which will actually run the query you’re trying to optimize and give you a ton more information about its performance. In regular expressions, \b , the word boundary assertion, makes it easy to look for the beginnings or ends of words.
, the word boundary assertion, makes it easy to look for the beginnings or ends of words. You can use logarithms with metrics to get a sense of the distribution of values for a field you’re interested in: const bucket = Math. floor (Math. log10 ( userInGroupCount )) metrics . increment ( "my_metric" , { bucket });
Modern JS now supports Array.flatMap, Object.entries, and Promise.withResolvers.
... continue reading