Skip to content

Instantly share code, notes, and snippets.

@jimjh
jimjh / luigi.py
Created September 5, 2018 05:32
example of shading
# luigi 1.x is renamed to luigi1
from luigi1 import Task as Task1
# luigi 2.x is imported as usual
from luigi import Task
@jimjh
jimjh / requirements.yaml
Created September 5, 2018 05:28
requirements.txt example for deps post
# compiled requirements.txt, or Pipfile.lock (aka "lock file")
certifi==2018.8.24 # via requests
chardet==3.0.4 # via requests
click==6.7 # via flask
flask==1.0.2
idna==2.7 # via requests
itsdangerous==0.24 # via flask
jinja2==2.10 # via flask
markupsafe==1.0 # via jinja2
requests==2.19.1
@jimjh
jimjh / bouncy.rs
Created June 19, 2017 18:08
Project Euler P112
pub fn search_bouncy() -> i32 {
//! procedural implementation
let mut n = 100;
let mut hit = 0.0;
let mut total = 100.0;
while hit / total < 0.99 {
n = n + 1;
if is_bouncy(n) {
hit = hit + 1.0;
}
@jimjh
jimjh / resize.sh
Created April 8, 2016 00:48
Resize docker terminals to a sensible width/height
#!/bin/bash
# Usage: ./resize.sh [container ID]+
set -o errexit
set -o nounset
set -o pipefail
sudo apt-get -qqy install jq socat
while [[ -n ${1:-''} ]]; do
@jimjh
jimjh / libgit2-fpm.sh
Last active December 29, 2015 19:41
libgit2-fpm.sh
#!/bin/bash
# cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr --build .
# make
# make install DESTDIR=~/tmpinstalldir
fpm -f \
-s dir \
-t deb \
-n libgit2 \
-v 0.23.4ppa1 \
-C ~/tmpinstalldir \
@jimjh
jimjh / child.sh
Created November 13, 2015 23:42
Using $@ vs $*
#!/bin/bash
# child.sh
# Prints all args.
while (( "$#" )); do
echo "arg: $1"
shift
done
@jimjh
jimjh / _vault
Last active November 2, 2015 21:58
zsh autocompletion for vault's subcommands
#compdef vault
# See https://vaultproject.io/
# Drop this file in ~/.oh-my-zsh/completions/_vault
subcommands=$(vault --help 2|& grep -E '^\s{4}' | awk '{printf $1; $1=""; print "\\:\x27"$0"\x27"}')
_arguments "1:subcommand:((${subcommands}))"
_message 'vault [-version] [-help] <command> [args]'
@jimjh
jimjh / pool.py
Created October 29, 2015 23:42
sharing state
def x():
# using a function as a convenient global object
print 'hello!'
x.favorite_band = 'Maroon 5'
def went_to_music_festival(s):
print 'favorite band was ' + x.favorite_band
@jimjh
jimjh / do-stuff.sh
Last active August 29, 2015 14:26
script template
#!/usr/bin/env bash
# Usage:
# Without trace, just run `./do-stuff.sh`
# With trace, use `BASH_XTRACEFD=3 ./do-stuff 3> trace.txt`
# Requires bash 4.+
set -o pipefail
set -o nounset
set -o errexit
if [[ ${BASH_XTRACEFD:+x} ]]; then
@jimjh
jimjh / basic_example.py
Created January 4, 2015 05:57
Basic Python Logging
import logging
def do_work():
logging.debug("x")
if __name__ == '__main__':
# Register STDOUT as a log handler.
# There are other ways to register handlers, but this is the simplest way.
# See https://docs.python.org/2/library/logging.html#logging.basicConfig