Skip to content

Instantly share code, notes, and snippets.

@fordhurley
fordhurley / slicetricks.md
Created April 2, 2019 00:48
Golang SliceTricks, documented

Golang SliceTricks, documented

This is a fork of the SliceTricks page of the golang wiki, but with documentation for each of the "tricks." I believe that documentation has been omitted because the names refer to the old container/vector, but that package no longer exists in the standard library, so you can't find it on godoc. I created this by referring to this archive.org cache, (TODO: find git commit).

@fordhurley
fordhurley / subl.bash
Created September 2, 2015 13:37
Easily open the current directory in sublime. Place in your aliases file or .bashrc.
# Sublime Text launcher, which does special stuff if you pass no arguments. If a
# ".sublime-project" file is found in the current dir, it opens that. Otherwise,
# it opens ".".
function subl() {
local args=$@
if [[ $# -lt 1 ]]; then
args="$(find . -maxdepth 1 -name '*.sublime-project' -print -quit)"
fi
if [[ -z "$args" ]]; then
args="."
@fordhurley
fordhurley / lorem.bash
Created September 2, 2015 13:36
Place this in your aliases file (or .bashrc) to have lorem ipsum text available at your fingertips.
# Lorem ipsum text. Optional argument is the number of sentences to
# produce. Each sentence will be separated by an empty line.
# Requires `pip install fake-factory`.
function lorem() {
local repeat=$1
if [[ -n $repeat ]]; then
repeat="-r $repeat"
fi
PYTHONIOENCODING=UTF-8 python -m faker text $repeat
}
@fordhurley
fordhurley / base32
Created May 1, 2015 14:18
base32 encoder/decoder
#!/usr/bin/env python
"""base32 encoding based on http://www.crockford.com/wrmg/base32.html
Encodes the positive integer on stdin. This tool is designed to parallel
base64(1).
Usage: base32 [-h | -D]
-h print this help
-D decode input instead
"""
@fordhurley
fordhurley / docker-clean
Last active August 29, 2015 14:19
Clean up your boot2docker VM
#!/bin/bash
remove_exited_containers() {
docker ps -a -q | xargs -n 1 -I {} docker rm {}
}
remove_untagged_images() {
docker rmi $(docker images --filter dangling=true -q)
}
@fordhurley
fordhurley / timed_run.py
Created January 22, 2015 13:56
Implementing a timeout in python with multiprocessing
import time
import multiprocessing as mp
from Queue import Empty
def timed_run(func, args=(), kwargs={}, timeout=10, default=None):
def run_func(q):
result = func(*args, **kwargs)
q.put(result)
@fordhurley
fordhurley / boilerplate.sh
Created October 24, 2014 11:48
bash script boilerplate
#!/usr/bin/env bash
set -o xtrace # Expand and echo commands
set -o nounset # Error if attempt to use undefined variable
set -o errexit # Abort script at first error
@fordhurley
fordhurley / hipchat.py
Last active April 6, 2024 14:40 — forked from wsorenson/hipchat.py
Updated script to log in with email and password and minor updates to the scraper
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
import re
import getpass
import requests

Backing up a GPG private key to a QR code

Use at your own risk! As with any backup method, test out your backup by restoring from it before you trust it.

  1. Install qrcode to generate the QR code:

     pip install qrcode
    
  2. Export the key, piping the output to qr, and save this to a png file: