Skip to content

Instantly share code, notes, and snippets.

View samalba's full-sized avatar

Sam Alba samalba

View GitHub Profile
@samalba
samalba / gist:2563872
Created May 1, 2012 00:11
javascript safe escape
var escapeInput = function (str) {
return str.replace(/['"<>]|^\s+|\s+$/g, '');
};
@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 / 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
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 / 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 {} \;
}
@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 / tohex.py
Last active December 20, 2015 03:29
Convert a binary file into an array of bytes which can be inserted in a code
#!/usr/bin/env python
import sys
if __name__ == '__main__':
fname = sys.argv[1]
with open(fname) as f:
print '['
while True:
b = f.read(14)
@samalba
samalba / gist:6465780
Last active December 22, 2015 11:29
Run docker-registry tests in docker-ci
#!/bin/sh
# NOTE: Run from the docker-registry root directory
# Setup the environment
export SETTINGS_FLAVOR=test
export DOCKER_REGISTRY_CONFIG=config_test.yml
export DOCKER_CREDS=REPLACE:ME
export S3_ACCESS_KEY=REPLACEME
export S3_SECRET_KEY=REPLACEME
@samalba
samalba / config.yml
Created November 18, 2013 22:55
Enabling LRU cache on docker-registry
dev:
# This assumes the Redis info are in environment variables
cache:
host: _env:REDIS_HOST
port: _env:REDIS_PORT
password: _env:REDIS_PASSWORD

Keybase proof

I hereby claim:

  • I am samalba on github.
  • I am samalba (https://keybase.io/samalba) on keybase.
  • I have a public key whose fingerprint is B411 50C3 439F 0404 0B18 7512 C92D F665 EE29 B29B

To claim this, I am signing this object: