Skip to content

Instantly share code, notes, and snippets.

View thmsmlr's full-sized avatar

Thomas Millar thmsmlr

View GitHub Profile
@thmsmlr
thmsmlr / cached_property.py
Created June 18, 2015 16:56
Cached Property
def cached_property(func):
property_name = '_' + func.__name__
@functools.wraps(func)
def wrapped(self, *args, **kwargs):
private_property = getattr(self, property_name, None)
if kwargs.get('force', False) or private_property == None:
val = func(self, *args, **kwargs)
setattr(self, property_name, val)
return val
else:
@thmsmlr
thmsmlr / deploy.sh
Created August 17, 2016 17:17
GitHub Pages deploy script
#!/bin/sh
set -e
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "jekyll" ]; then
echo "ERROR! You can only deploy from jekyll branch"
exit 1
fi
CLEAN_REPO=$(git status --porcelain)
@thmsmlr
thmsmlr / bash-compose-up
Created July 1, 2020 05:59
A simple way to spin up many blocking bash commands at once, killing all on SIGINT
#!/usr/bin/env bash
#
# This is a basic script to launch multiple programs and kill them
# all at the same time. It does this by launching the first n-1 jobs as
# background jobs, then running the nth job as a foreground job.
#
# It traps the exist signal produced by doing `CTRL-C` on the CLI and
# iterates through the PIDs of the background jobs and runs kill -9 on them.
#
@thmsmlr
thmsmlr / killport
Created February 1, 2022 19:01
killport
#!/bin/sh
usage() {
cat >&2 << EOF
killport: kill -9 any process that is bound to a local port
Usage:
killport <port>
EOF
}
@thmsmlr
thmsmlr / google-vim-hotkeys.js
Last active April 20, 2022 18:25
[Tampermonkey] Google VIM Hotkeys
// ==UserScript==
// @name Google VIM Hotkeys
// @namespace https://gist.github.com/ccjmne
// @version 0.0.1
// @description Navigate results from Google using j/k vim bindings
// @author Thomas Millar <[email protected]> (https://github.com/thmsmlr)
// @match *://www.google.com/*
// @grant none
// ==/UserScript==
@thmsmlr
thmsmlr / kino_daemon.exs
Created January 14, 2024 21:59
Kino Background Daemon
child_spec = Task.child_spec(fn ->
IO.puts("""
I am doing daemon things for my Livebook.
If I re-evaluate the cell, this task will be terminated and restart with the new version of the code.
If the task ever terminates, the Supervisor will automatically restart it.
Useful for running things in the background that don't need to directly interact with your notebook.
""")
@thmsmlr
thmsmlr / app.js
Created February 14, 2024 16:54
Code Splitting for Phoenix LiveView Hooks
// assets/js/app.js
window._lazy_hooks = window._lazy_hooks || {};
let lazyHook = function(hook) {
return {
mounted() { window._lazy_hooks[hook].mounted(...arguments) },
beforeUpdate() { window._lazy_hooks[hook].beforeUpdate(...arguments) },
updated() { window._lazy_hooks[hook].updated(...arguments) },
destroyed() { window._lazy_hooks[hook].destroyed(...arguments) },
disconnected() { window._lazy_hooks[hook].disconnected(...arguments) },