Skip to content

Instantly share code, notes, and snippets.

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()
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAccessToBucket",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::468336580105:user/BucketIAMUser"
},
"Action": [
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;
@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}
@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="";
  • 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")

package com.thoughtmonkeys.pitstop;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
package com.thoughtmonkeys.pitstop;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
@ruiwen
ruiwen / enum.js
Last active October 5, 2015 07:04
Enums
function Enum() {
var self = this;
var vals = {};
for(var i=0; i < arguments.length; ++i) {
vals[arguments[i]] = i == 0? 0 : Math.pow(2, i-1)
vals[i] = i == 0? 0 : Math.pow(2, i-1)
Object.defineProperty(self, arguments[i], {
'value': vals[arguments[i]],
})
}
function keypress(n) {
var keyboardEvent = new KeyboardEvent('keydown', {bubbles:true});
Object.defineProperty(keyboardEvent, 'charCode', {get:function(){return this.charCodeVal;}});
Object.defineProperty(keyboardEvent, 'keyCode', {get: function(){return this.charCodeVal;}});
keyboardEvent.charCodeVal = n;
document.body.dispatchEvent(keyboardEvent);
}