Skip to content

Instantly share code, notes, and snippets.

@jimjh
jimjh / luigi.py
Created Sep 5, 2018
example of shading
View luigi.py
# 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 Sep 5, 2018
requirements.txt example for deps post
View requirements.yaml
# 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 Jun 19, 2017
Project Euler P112
View bouncy.rs
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 Apr 8, 2016
Resize docker terminals to a sensible width/height
View resize.sh
#!/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 Dec 29, 2015
libgit2-fpm.sh
View 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 Nov 13, 2015
Using $@ vs $*
View child.sh
#!/bin/bash
# child.sh
# Prints all args.
while (( "$#" )); do
echo "arg: $1"
shift
done
@jimjh
jimjh / _vault
Last active Nov 2, 2015
zsh autocompletion for vault's subcommands
View _vault
#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 Oct 29, 2015
sharing state
View pool.py
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 Aug 29, 2015
script template
View do-stuff.sh
#!/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 Jan 4, 2015
Basic Python Logging
View basic_example.py
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