This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Combines 2 vectors into a single vector of size av, | |
# by applying a binary operation (defined in block) | |
# on each element. | |
# | |
# Examples: | |
# map2([1,2,3], [4,5,6]) { |a,b| a*b } == [4,10,18] | |
# map2([1,2,3], [4,5] ) { |a,b| a+b } == [5,7,nil] | |
# map2([1,2], [4,5,6]) { |a,b| a+b } == [5,7] | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Backbone.js 0.9.2 | |
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc. | |
// Backbone may be freely distributed under the MIT license. | |
// For all details and documentation: | |
// http://backbonejs.org | |
// Use a factory function to attach Backbone properties to an exports value. | |
// Code at the end of this file creates the right define, require and exports | |
// values to allow Backbone to run in a CommonJS or AMD container or in the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fact2 [n] | |
(if (= n 1) | |
1 | |
(* n (fact2 (- n 1))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rgb2hex = lambda r,g,b: '#'+''.join([ hex(x)[2:].zfill(2) for x in (r,g,b) ]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
sed -i.bak "s@^\(CREATE DATABASE\)@#\1@g" $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: init_venv deps freeze clean_venv | |
all: init_venv deps | |
PYTHONPATH=venv ; . venv/bin/activate | |
init_venv: | |
if [ ! -e "venv/bin/activate_this.py" ] ; then PYTHONPATH=venv ; virtualenv --clear venv ; fi | |
deps: | |
PYTHONPATH=venv ; . venv/bin/activate && venv/bin/pip install -U -r requirements.txt && if [ "$(ls requirements)" ] ; then venv/bin/pip install -U -r requirements/* ; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def subdict(d, include_keys=[]): | |
""" | |
Subsets a :dict: by keys specified in :include_keys: | |
>>> subdict({ 'a': 1, 'b': 2, 'c': 3 }, ['a', 'c']) | |
{ 'a': 1', 'c': 3 } | |
>>> subdict({ 'a': 1, 'b': 2, 'c': 3 }, ['x', 'y']) | |
{} | |
>>> subdict({}, []) | |
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import datetime | |
from dateutil import tz | |
from naive_aware import isAware, makeAware, makeNaive | |
def jdumps(obj): | |
return json.dumps(obj, | |
default=lambda o: (makeAware(o) if isinstance(o, datetime.datetime) else o).isoformat() \ | |
if (isinstance(o, datetime.datetime) or isinstance(o, datetime.date)) else None, | |
sort_keys=True, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
openssl genrsa -out private.key 4096 | |
openssl rsa -in private.key -pubout > public.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
IFACE=en0 | |
macaddr=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'` | |
sudo airport -z | |
osascript -e 'tell application "System Preferences" to quit' | |
sudo scselect -n | |
sudo ifconfig $IFACE lladdr $macaddr | |
# These should match | |
echo $macaddr |
OlderNewer