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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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="." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import sys | |
import os | |
import re | |
import getpass | |
import requests |