Skip to content

Instantly share code, notes, and snippets.

View samalba's full-sized avatar

Sam Alba samalba

View GitHub Profile
@samalba
samalba / main_test.go
Created July 23, 2013 02:50
How to assert values in golang unit tests
package main
import (
"fmt"
"testing"
)
func assertEqual(t *testing.T, a interface{}, b interface{}, message string) {
if a == b {
return
@samalba
samalba / gist:5971752
Created July 11, 2013 01:22
Quickly check the syntax of your Python code
# Add this to your ~/.bashrc (or ~/.zshrc)
pycheck () {
type flake8 > /dev/null || {
echo "pip install flake8"
return
}
find . -name '*.py' -type f -exec flake8 {} \;
}
echo workqueue:workqueue_queue_work > /sys/kernel/debug/tracing/set_event
cat /sys/kernel/debug/tracing/trace_pipe > out.txt
(Leave it running a couple of seconds, then Ctrl+C; this is just to flush the buffer)
cat /sys/kernel/debug/tracing/trace_pipe > out.txt
(Leave it running a couple of seconds, then Ctrl+C; this is to recover the data)
cut -d- -f2 out.txt | awk '{print $1}' | sort | uniq -c | sort -n
@samalba
samalba / build.sh
Last active December 14, 2015 14:29
Run gunicorn for a Python app on dotCloud using a custom service.
#!/bin/bash
cd $SERVICE_APPROOT
[ -d ~/env ] ||
virtualenv --python=python2.7 ~/env || exit 1
. ~/env/bin/activate
[ -f requirements.txt ] &&
pip install --download-cache=~/.pip-cache -r requirements.txt || exit 1
@samalba
samalba / gist:4941972
Created February 13, 2013 03:12
Generate SSH keys
import StringIO
from paramiko import DSSKey
def generate_ssh_key():
dss = DSSKey.generate()
out = StringIO.StringIO()
dss.write_private_key(out)
private_key = out.getvalue()
out.close()
public_key = 'ssh-dss {0}'.format(dss.get_base64())
@samalba
samalba / gist:2563872
Created May 1, 2012 00:11
javascript safe escape
var escapeInput = function (str) {
return str.replace(/['"<>]|^\s+|\s+$/g, '');
};