Skip to content

Instantly share code, notes, and snippets.

View justinmklam's full-sized avatar

Justin Lam justinmklam

View GitHub Profile
@justinmklam
justinmklam / issue-template.md
Last active July 14, 2021 20:43
A collection of github repo templates (readme, pull requests, issues, etc.)

Expected Behavior

Please describe the behavior you are expecting

Current Behavior

What is the current behavior?

Failure Information (for bugs)

@justinmklam
justinmklam / makefile-cheatsheet.md
Last active July 9, 2021 21:24
Cheat sheet for makefile

Assign output of command to a variable, then use the variable. Needs $<); \ to pipe the output and concatenate the subsequent line, since each line is executed in a separate shell.

# Usage: make db-upgrade-gcp environment=dev
db-upgrade-gcp:
	TOKEN=$$(gcloud auth print-identity-token $<); \
	python bin/db_upgrade_gcp.py $(environment) --gcp_token $$TOKEN
@justinmklam
justinmklam / pytest-skip-by-default.md
Last active July 6, 2021 00:23
Skip tests by default in pytest
@justinmklam
justinmklam / python-system-commands.md
Last active June 16, 2021 21:09
Ways to execute shell commands from python using subprocess

Basic example:

import os

os.system("python --version")

Better, since stdout and return codes aren't easily processed when using os.system:

@justinmklam
justinmklam / postgresql.md
Last active September 29, 2022 18:27
Postgresql cheat sheet

Installation

brew install postgres

# Start the service and register to autostart on boot
brew services start postgresql

# Create user
createdb $(whoami)
@justinmklam
justinmklam / progressbar.py
Last active June 4, 2021 15:17
Simple progress bar without external dependencies. Adapted from https://stackoverflow.com/a/34482761
import os
import sys
def progressbar(it, prefix="", file=sys.stdout):
count = len(it)
num_bar_chars = 5
width = os.get_terminal_size().columns - (
len(prefix) + len(str(count)) * 2 + num_bar_chars
)
@justinmklam
justinmklam / mac-os-apps.md
Last active July 8, 2022 21:32
Mac utility apps that make everyday computing easier.

Brew

Install the following with:

# Add --cask if required
brew install $(cat brew-packages.txt)

In brew-packages.txt:

@justinmklam
justinmklam / configs-for-karabiner-layers.md
Last active December 7, 2025 17:00
Karabiner configs for macOS

Instructions:

  1. In GUI, add rule under complex modifications
  2. Change to_if_alone_timeout_milliseconds from 1000 to 500 ms

See blog post or KeymapDB for more details.

@justinmklam
justinmklam / docker-cheet-sheet.md
Last active July 12, 2022 19:28
Docker cheat sheet

Building

# Specify tag 
docker build -t mycontainer .

# Specify dockerfile
docker build -f Dockerfile .
# Outside top right
l1 = plt.legend(bbox_to_anchor=(1.04,1), borderaxespad=0)
# Outside bottom right
l2 = plt.legend(bbox_to_anchor=(1.04,0), loc="lower left", borderaxespad=0)
# Outside center right
l3 = plt.legend(bbox_to_anchor=(1.04,0.5), loc="center left", borderaxespad=0)
# Outside top single row
l4 = plt.legend(bbox_to_anchor=(0,1.02,1,0.2), loc="lower left",
mode="expand", borderaxespad=0, ncol=3)
# Outside bottom right