This file contains hidden or 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 matchparen(): | |
ct = 0 | |
msg = None | |
result = None | |
while (msg != True): | |
msg = (yield ct) | |
if msg == '(': | |
ct += 1 |
This file contains hidden or 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 cr(): | |
state = False | |
for i in range(100): | |
new_state = None | |
if state: | |
new_state = (yield i) | |
else: | |
new_state = (yield "Off") | |
if not (new_state is None): | |
state = new_state |
This file contains hidden or 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 inv_image(f, collection): | |
"""Returns the inverse image (in the mathematical sense) | |
of the function applied to the collection. | |
""" | |
result = {} | |
for x in collection: | |
img = f(x) | |
if result.has_key(img): | |
result[img].add(x) | |
else: |
This file contains hidden or 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
#Must be run with role foo, since foo has sudo access or other permissions | |
@hosts(*env.roledefs['foo']) | |
def do_foo_actions(): | |
sudo("mkdir /usr/local/program") | |
sudo("chown -R bar:bar /usr/local/program") | |
#Most of the work here is done in role bar. But the folder /usr/local/program must exist before we can deploy | |
@hosts(*env.roledefs['bar']) | |
def deploy_program(): | |
for h in env.roledefs['foo']: |
This file contains hidden or 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 | |
old=$1 | |
new=$2 | |
if [ $old ] && [ $new ] | |
then | |
echo "Cloning $old, saving result as $new" | |
else | |
echo "Usage: clone-ubuntu.sh oldname newname" |
This file contains hidden or 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
#!/usr/local/bin/python | |
from pylab import * | |
def bmr(height, weight, age): | |
"""Height in inches, weight in pounds, age in years. | |
Computes base metabolic rate for Harris Benedict Equation. | |
""" | |
return 66 + 6.23*weight + 12.7*height - 6.8 *age |
This file contains hidden or 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
#Created graph used here: http://crazybear.posterous.com/structural-shift-in-the-economy | |
import numpy.numarray as na | |
from pylab import * | |
labels = ["Financial Activites", | |
"Construction", | |
"Information Services", | |
"Retail", |
This file contains hidden or 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 org.apache.hadoop.io.*; | |
import java.util.*; | |
import java.io.*; | |
public class UUIDWritable implements WritableComparable<UUIDWritable> { | |
private UUID value; | |
public UUIDWritable(long mostSignificantBits, long leastSignificantBits) { | |
value = new UUID(mostSignificantBits, leastSignificantBits); |
This file contains hidden or 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
package stylewok.utils.writable; | |
import org.apache.hadoop.io.*; | |
import java.util.*; | |
import java.io.*; | |
public class UUIDToDoubleMapWritable extends HashMap<UUIDWritable,Double> implements Writable { | |
public UUIDToDoubleMapWritable() { } |
This file contains hidden or 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
from pylab import * | |
from numpy import * | |
import matplotlib.cbook as cbook | |
from datetime import datetime | |
from scipy.interpolate import interp1d | |
def read_file(filename): | |
dates = [] | |
values = [] | |
for l in open(filename).readlines(): |
OlderNewer