Skip to content

Instantly share code, notes, and snippets.

Small things I have picked up over the years that help me write better code

This is a living document that I add to when I discover something that helps me produce more quality code per unit of time.

Code is read and run much more than it is written - if you write it well, you save yourself much headache down the road.

  • Use git commit --verbose when committing. This allows you to easily check your work and catch if there's any unintended changes, and keep the diff as clean as possible.
  • When writing a ticket, add more context than you think is needed. Overexplain yourself. It's easy to think it's obvious in the moment, when you have all the context loaded in your brain - but future self and others will have a much easier time understanding.

Be Boring

@thedch
thedch / setup.md
Last active May 2, 2025 20:34
Setting up a new laptop

It is the convention of modern editors to remember which of your open files you have viewed last, and cycle through them in that order when you press Ctrl+Tab or Ctrl+Shift+Tab for reverse.

This frustrates me, I prefer the explicit "next and previous" tab, based on the order of the tabs themselves in the UI, same as any modern web browser. So, here is how to change that (recorded for convenience next time I need to set up a computer from scratch).

VS Code

Open the keyboard shortcuts UI, and click the weird button on the top right to open the raw JSON. Add:

<script type="text/babel">
const manuallyMakeElement = (props) => {
return React.createElement('div', {className: 'container'}, props.children)
}
const message = (props) => {
return props.children + ' ' + props.other_thing
}
const passFunctionIntoElement = React.createElement(message, {children: 'Pass function', other_thing: 'into'})
@thedch
thedch / deadcode.sh
Created January 25, 2020 19:04
A bunch of greps strung together to find unused classes in Python. May have bugs.
#!/bin/bash
# there's probably (definitely?) a better way to do this, but it seems to work.
classes=$(grep -oEh "^class \w+[\(:]" * | cut -c 7- | sed 's/.\{1\}$//')
for c in $classes ; do
grep $c * | grep -vq "class" || echo $c
done
def examine(x):
iam = str(type(x))
try: return iam + ' ' + examine(x[0])
except: return iam
def main():
print(examine([[[[1,2,3,]]]]))
@thedch
thedch / same-line-print.py
Created July 30, 2018 22:06
Easy progress bar style print on the same line
from time import sleep
def main():
for i in range(10):
print('Counter:', i, end='\r')
sleep(.1)
if __name__ == '__main__':
[
{ "keys": ["super+\\"], "command": "toggle_side_bar" },
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },
{ "keys": ["super+shift+f"], "command": "show_panel", "args": {"panel": "replace", "reverse": false} },
]
{
"auto_find_in_selection": true,
"close_windows_when_empty": true,
"ensure_newline_at_eof_on_save": true,
"find_selected_text": true,
"font_size": 13,
"hot_exit": false,
"ignored_packages":
[
"Vintage"
fig,axes=plt.subplots(3, 4, figsize=(10,5))
for i, ax in enumerate(axes.flat):
ax.imshow(img)
plt.tight_layout()
@thedch
thedch / asana.py
Last active December 21, 2021 02:44
Helper functions to create a task in a specific section in Asana
# The current Asana Python client does not seem to support task creation in a given section.
# The API documentation is also somewhat lacking, and there's some conflicting instructions on various forums.
# After a bit of searching + trial and error, I figured out how to do it using the requests library.
# I'm posting these helper functions here for anyone who may need them in the future.
import requests
import json
headers = {
'Content-Type': 'application/json',