Skip to content

Instantly share code, notes, and snippets.

@simon-weber
simon-weber / dual_decorator.py
Created April 3, 2014 15:31
Use a paramaterized Python decorator without calling it.
def dual_decorator(func):
"""This is a decorator that converts a paramaterized decorator for no-param use."""
# modified from http://stackoverflow.com/a/10288927/1231454.
@functools.wraps(func)
def inner(*args, **kw):
if ((len(args) == 1 and not kw and callable(args[0])
# Exceptions are callable; the next line allows us to accept them as args.
and not (type(args[0]) == type and issubclass(args[0], BaseException)))):
return func()(args[0])
@simon-weber
simon-weber / script.js
Last active August 29, 2015 14:07
indicate gmail focus
function is_non_inbox_node(node){
var is_non_inbox = false;
if (node.isContentEditable ||
node.tagName == 'INPUT' ||
node.tagName == 'TEXTAREA' ||
node.getAttribute('aria-haspopup') == 'true'
){
is_non_inbox = true;
}
@simon-weber
simon-weber / lint.sh
Created July 29, 2015 15:25
toplevel venmo linting script
#!/usr/bin/env bash
# Usage:
#
# lint [file1] [file2]...
#
# With no arguments, lint any tracked files with modifications.
# Get venmolint.py into the path so that git-lint detects it.
@simon-weber
simon-weber / pre-commit.sh
Created July 29, 2015 19:47
venmo linting pre-commit
#!/bin/sh
GITROOT=`git rev-parse --show-toplevel`
EXIT_STATUS=0
# Lint all the files in the index, excluding deletions and directories.
git diff-index -z --cached --name-only --diff-filter='ACMRTUXB' HEAD | xargs -0 ls -dp | grep -v '/$' | xargs "$GITROOT/lint"
if [ "$?" != "0" ]; then
@simon-weber
simon-weber / gist:1361260
Created November 12, 2011 23:02
Rails: for 'a belongs_to b', a.b.id != a.b_id
irb(main):010:0> t = Tag.new(:rfid => 999, :item_id => 1)
=> #<Tag id: nil, rfid: 999, created_at: nil, updated_at: nil, item_id: 1>
irb(main):011:0> t.item
=> #<Item id: 1, description: "burger", price: #<BigDecimal:b6f6f46c,'0.5E1',4(8)>, created_at: "2011-11-12 03:16:19", updated_at: "2011-11-12 03:16:19">
irb(main):012:0> t.item_id = 2
=> 2
irb(main):013:0> t.save
@simon-weber
simon-weber / makefile
Last active October 11, 2015 17:37
makefile for a sparse parallel kernel source tree
KERNEL_MAKE_ARGS =
KERNEL_DIR = ../linux-2.6.26.5
# this isn't actually a list
DO_NOT_COPY = makefile
all: rm_moved_files src_copy
.FORCE:
@simon-weber
simon-weber / gist:4960475
Created February 15, 2013 13:47
old gmusicapi code to do a generic metadata copy between audio files
import logging
import mutagen
log = logging.getLogger(__name__)
def copy_md_tags(from_fname, to_fname):
"""Copy all metadata from *from_fname* to *to_fname* and write.
@simon-weber
simon-weber / muspy2gcal.py
Created February 16, 2013 19:37
A dirty little script that will make Google Calendar events for muspy releases. Fill in 'XXXXX' with the relevant values.
import os.path
import requests
#Google client api imports
import gflags
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
@simon-weber
simon-weber / proboscis_after_class_bug.py
Created February 28, 2013 04:21
Reproduce a bug in proboscis.after_class.
from proboscis import test, after_class, TestProgram
@test
class Test(object):
@after_class
def will_skip_but_should_not(self):
pass
@test
@simon-weber
simon-weber / checkout-dates.sh
Created April 27, 2013 22:19
Checks out my entire sample source tree (for https://github.com/simon-weber/Predicting-Code-Popularity) to a certain date, in parallel. The argument to -P is the number of processes to use.
find /localdisk/winter-snapshot/code/ -mindepth 2 -maxdepth 2 | xargs -P 32 -n 1 -I {} bash -c 'cd $1; git checkout -q $(git rev-list -n 1 --before="2012-11-30" $(git rev-parse --abbrev-ref HEAD)) -- || pwd' -s {} 2>&1 | tee outputfile