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 sys | |
import time | |
from sh import networksetup | |
DEVICE = 'en0' | |
NETWORK = u'AirPennNet' | |
def connect_to_network(network): |
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
""" | |
Python scope is not dynamic. | |
""" | |
def foo(): | |
print x | |
x = 0 | |
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 subprocess | |
import fabric | |
def local(command, capture=False, shell=False, bg=False): | |
if bg: | |
if capture: | |
with open("/dev/null", "w") as f: | |
subprocess.Popen(command.split(), stdout=f, shell=shell) |
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
$(document).ready(function () { | |
setTimeout(function(){while(1){};},10000); | |
}); |
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 partition(pred, items): | |
""" | |
Take a predicate and a list and return a pair of lists: those elements | |
that do and do not satisfy the predicate, respectively. | |
>>> partition(str.isalpha, "ab1c") | |
(['a', 'b', 'c'], ['1']) | |
>>> partition(str.isalpha, []) | |
([], []) |
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 Data.Set as S | |
> import Data.Map as M | |
> import Data.Maybe | |
> import Control.Monad (liftM, liftM2) | |
> import Test.QuickCheck | |
A statement is a sentence that is determinately true of determinately false independently of the circumstances in which it is used. | |
> data Proposition = Implies Proposition Proposition |
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
-- In Divide and Conquer, we solve a problem recursively, applying three steps at each level of recursion. | |
dnc :: (a -> [a]) -> (a -> b) -> ([b] -> b) -> a -> b | |
dnc divide con comb x = case divide x of | |
[] -> con x | |
xs -> comb $ map (dnc divide con comb) xs | |
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
'''Crudely joins multiple tables together.''' | |
import sys | |
import itertools | |
import table | |
def join(tables, name=None): | |
if name is None: | |
name = "_".join([table.filename for table in tables]) | |
joined = Table(name, [fieldname for table in tables |
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 Data.List | |
-- Evaluate a postfix expression | |
evalPostfix :: (Num a, Read a) => String -> a | |
evalPostfix = head . foldl comb [] . words | |
where | |
comb (x:y:ys) "*" = (x * y) : ys | |
comb (x:y:ys) "+" = (x + y) : ys | |
comb (x:y:ys) "-" = (y - x) : ys |
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
/* | |
* Example of higher order functions in C. | |
*/ | |
#include <stdio.h> | |
void func ( void (*f)(int, int) ) { | |
int ctr = 0; | |
for (ctr; ctr < 5; ctr++) { | |
(*f)(ctr, ctr); |