Skip to content

Instantly share code, notes, and snippets.

/**
* Basically like doWithM, just that your callback need not call done() at the
* end.
*
* ex.
* var linkFuture = doWith(element("a.myLink").attr("href"), function(href) {
* console.log("got link", href);
* });
*/
angular.scenario.dsl('doWith', function() {
@rctay
rctay / ng.scenario.Describe.beforeAll.js
Last active December 19, 2015 01:08
angular.scenario: add beforeAll
/**
* Defines a block to execute before each it or nested describe.
*
* beforeAll()s will be called before beforeEach()s.
*
* Note: unlike beforeEach(), this needs to be called on "this", ie.
*
* this.beforeAll(...)
*
* This can be fixed but would require too much hacking.
@rctay
rctay / binding-ns.clj
Last active December 15, 2015 00:59
binding based on Vars in a namespace
(defmacro binding-ns
"Like binding, but bindings are based on all publics in ns."
[from-ns & body]
(let [ns-vars (fn [-ns]
; fnext to get var from ns-publics name-var pairs
(filter #(:dynamic (meta (fnext %)))
(ns-publics -ns)))
var-ize (fn [from-name-vars]
(loop [ret {} from-name-vars (seq from-name-vars)]
(if-let [[name from-var] (first from-name-vars)]
@rctay
rctay / make_quad.m
Created December 16, 2012 21:59
check quadratic formulation in symmetric Q
function [y,x] = make_quad(Q)
n=size(Q,1);
x=sym('x', [n 1]);
assume(x,'real');
y=simplify(1/2 * x' * Q * x);
end
@rctay
rctay / pyrefactors.py
Created November 14, 2012 03:08 — forked from geeknam/pyrefactors.py
Python refactors
"""
Use setattr
"""
# Normal
item.price = self.request['price']
item.quantity = self.request['quantity']
item.shipping = self.request['shipping']
item.save()
@rctay
rctay / fn.py
Created August 7, 2012 17:01
[python] (fork) object proxying
## Based on http://code.activestate.com/recipes/519639/ (r1)
## and http://code.activestate.com/recipes/496741-object-proxying/ (r1)
import copy
def proxy(cls, target):
"""
A, the class of the object to be proxied, intentionally takes an argument.
This foils any proxy techniques that instantiate the class of the proxee.
@rctay
rctay / sitecustomize.py
Created July 24, 2012 09:38
[python] start debugger on exception
#
# original: http://code.activestate.com/recipes/65287/
#
# place in lib/python2.x/sitecustomize.py
import bdb
import sys
def info(type, value, tb):
if hasattr(sys, 'ps1') \
@rctay
rctay / do_rsync.sh
Created July 13, 2012 14:59
[sh] rsync runner (just a fancy macro really)
#!/bin/sh
# Usage: name host ['common opts'] ['1st run opts'] ['2nd run opts'] ...
if test "$#" -lt 2; then
echo "too little arguments!"
exit 1
fi
RSYNC=rsync
@rctay
rctay / mysql_backports.py
Created July 4, 2012 08:09
[django] backport savepoints for MySQL
from django.db.backends import BaseDatabaseFeatures
from django.db.backends.mysql.base import (
DatabaseFeatures as MySQLDatabaseFeatures,
DatabaseOperations as MySQLDatabaseOperations,
)
try:
from django.util.functional import cached_property
except ImportError:
# Backport from django 1.4
@rctay
rctay / post-commit
Created June 22, 2012 16:05
[git,django,south] hook to warn about migrations from merges
#!/bin/sh
# was it a merge?
if test `git rev-list --parents -n 1 HEAD | wc -w` -lt 3; then
exit 0;
fi
if test `git rev-list ^HEAD^1 HEAD^@ -- sq/migrations | wc -l` -gt 0; then
echo '#'
echo '# WARNING: Migrations detected in merge; you may want to apply them.'