Skip to content

Instantly share code, notes, and snippets.

View ecounysis's full-sized avatar

Eric Christensen ecounysis

View GitHub Profile
@ecounysis
ecounysis / gist:2721646
Created May 17, 2012 21:21
Bash Colors
color_start='\e['
color_end='\e[m'
Black='0;30m'
Blue='0;34m'
Green='0;32m'
Cyan='0;36m'
Red='0;31m'
Purple='0;35m'
Brown='0;33m'
@ecounysis
ecounysis / final_four.py
Created March 17, 2012 06:05
Final Four Pick Strategy
#seeds making it to final four in past ten years
seeds=[3,4,8,11,1,2,5,5,1,1,2,3,1,1,1,1,1,1,2,2,2,3,4,11,1,1,4,5,1,2,2,3,1,2,3,3,1,1,2,5]
# track how many times each seed has made it to final four
data=[]
for i in range(16):
s=i+1
data.append([s,len(filter(lambda x:x==s,seeds))])
# compute likelihoods
@ecounysis
ecounysis / map_reduce.py
Created February 29, 2012 18:34
MapReduce Python Class
# I don't know whether this is valuable or meaningful, but it seems interesting.
class MR:
def process(self,the_list,the_map_function,the_reduce_function,the_initial_value):
return reduce(the_reduce_function, map(the_map_function, the_list), the_initial_value)
def sum1(x):
return MR().process(x, (lambda x: x), (lambda x,y: x+y), 0)
def len1(x):
@ecounysis
ecounysis / FunctionPiper.py
Created February 29, 2012 01:36
Function Piping in Python
# I don't know 100% what this is, but it seems interesting, so I am recording it.
class FunctionPiper:
def applyAll(self, data):
if len(self.functionList) > 0:
for func in self.functionList:
data = func(data)
return data
j=FunctionPiper()
@ecounysis
ecounysis / numbers.clj
Created February 25, 2012 05:23
Numbers from "The Little Schemer" in Clojure
(defn add1 [x] (+ x 1))
(defn sub1 [x] (- x 1))
(defn o+ [x y]
(cond (= y 0) x
:else (o+ (add1 x) (sub1 y))))
(defn o- [x y]
(cond (= y 0) x
@ecounysis
ecounysis / numbers.scm
Created February 25, 2012 05:10
Numbers from "The Little Schemer"
(define (add1 x) (+ x 1))
(define (sub1 x) (- x 1))
(define (o+ x y)
(cond ((= y 0) x)
(else (o+ (add1 x) (sub1 y)))))
(define (o- x y)
(cond ((= y 0) x)
@ecounysis
ecounysis / dice.clj
Created February 25, 2012 00:38
Clojure Dice
(defn make-die [sides]
(fn [] (+ 1 (rand-int sides))))
(def d20 (make-die 20))
(def d6 (make-die 6))
(def d4 (make-die 4))
(def d10 (make-die 10))
(def d12 (make-die 12))
(def d100 (make-die 100))
(def d1000 (make-die 1000))
@ecounysis
ecounysis / mymail.awk
Created February 7, 2012 00:05
command line send mail
BEGIN {
body=0;
}
body==1 {a=a$0"\n";};
/^Body:/ {body=1;a=a" --body=\"";}
/^To:/ {a=a" -t"$2;}
/^From:/ {a=a" -f"$2;}
/^Subject:/ {a=a" -u\""$2"\"";}
/^Attachments:/ {
@ecounysis
ecounysis / mymailer.py
Created February 4, 2012 01:03
command line send mail
#!/usr/bin/python
from mailer import Mailer, Message
from optparse import OptionParser
def isnull(opt, default):
if (opt == "" or opt is None):
return default
else:
return opt
@ecounysis
ecounysis / caeser.hs
Created February 2, 2012 00:46
Caesar Cypher in Haskell
import Char
cCipher s = encode 3 s
cDecipher s = decode 3 s
encode sh s = map (encodeChar sh) s
decode sh s = encode (-sh) s
encodeChar sh c
| isChar c = shift sh c
| otherwise = c