Skip to content

Instantly share code, notes, and snippets.

  • Unit

    • migrate listers rm_prefs into self.hm_prefs
      • Note this migration needs to take place before the User migration below (due to migration of rm_prefs and hm_prefs
  • User

    • rename rm_prefs -> hm_prefs (ie. copy values over)
      • delete rm_prefs on User if need be
    • copy all user.personal attributes onto user (top-level)
      • age = IntField()
  • gender = StringField(choices=['male', 'female', 'third'], default="female")

@ruiwen
ruiwen / .tmux-zoom
Last active December 23, 2015 03:19
Sample .tmux.conf and other scripts Add these to your $HOME in the appropriate places and shown in their filenames
#!/bin/bash -f
# Obtained from http://superuser.com/a/433702
currentwindow=`tmux list-window | tr '\t' ' ' | sed -n -e '/(active)/s/^[^:]*: *\([^ ]*\) .*/\1/gp'`;
currentpane=`tmux list-panes | sed -n -e '/(active)/s/^\([^:]*\):.*/\1/gp'`;
panecount=`tmux list-panes | wc | sed -e 's/^ *//g' -e 's/ .*$//g'`;
inzoom=`echo $currentwindow | sed -n -e '/^zoom/p'`;
if [ $panecount -ne 1 ]; then
inzoom="";
@ruiwen
ruiwen / gist:6510503
Created September 10, 2013 14:47
Move tracked files in git into a particular directory
$ mkdir rb
$ for i in `git ls-tree HEAD | cut -f2`; do git mv ${i} rb/; done
# Optional - undo the move for those that shouldn't have been moved
$ git reset HEAD {.gitignore,Procfile,requirements.txt,scripts,minions}
$ git checkout -- {.gitignore,Procfile,requirements.txt,scripts,minions}
function rainbow(numOfSteps, step) {
// based on http://stackoverflow.com/a/7419630
// This function generates vibrant, "evenly spaced" colours (i.e. no clustering). This is ideal for creating easily distiguishable vibrant markers in Google Maps and other apps.
// Adam Cole, 2011-Sept-14
// HSV to RBG adapted from: http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
var r, g, b;
var h = step / numOfSteps;
var i = ~~(h * 6);
var f = h * 6 - i;
var q = 1 - f;
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAccessToBucket",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::468336580105:user/BucketIAMUser"
},
"Action": [
import re
import PIL
from PIL import Image
def generate_thumbnails(fn):
match = re.match(r"^(?P<path>[^/]+)/receipt_(?P<dimensions>\d{4}x\d{4})_(?P<mp>.{3,5})\.jpg$", fn)
if not match:
return
print "Generating for " + fn
match = match.groupdict()
import boto
import os
import json
import base64
import hashlib
import requests
import datetime
import hmac
import pytz
@ruiwen
ruiwen / s3selfsignedPOST.py
Last active December 19, 2015 14:59
Self Signed S3 REST API Using POST
import boto
import os
import json
import base64
import hashlib
import requests
import datetime
import hmac
import pytz
@ruiwen
ruiwen / s3selfsigned.py
Last active December 19, 2015 14:59
Self Signed S3 REST API Request
import boto
import os
import base64
import hashlib
import requests
import datetime
import hmac
@ruiwen
ruiwen / gist:5908551
Created July 2, 2013 11:29
Unicode DictWriter
# Unicode DictWriter object
# http://stackoverflow.com/a/5838817
class DictUnicodeWriter(object):
def __init__(self, f, fieldnames, dialect=csv.excel, encoding="utf-8", **kwds):
# Redirect output to a queue
self.queue = cStringIO.StringIO()
self.writer = csv.DictWriter(self.queue, fieldnames, dialect=dialect, **kwds)
self.stream = f
self.encoder = codecs.getincrementalencoder(encoding)()