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 itertools | |
import sys | |
for k, s in itertools.groupby(sys.stdin.readlines(), lambda x: x.split(",")[0]): | |
sys.stdout.write(next(s)) |
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
exports.queries = []; | |
exports.holder = []; |
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
#lang racket | |
(define-syntax let1 | |
(syntax-rules () | |
((let1 ((var val) ...) expr) | |
((lambda (var ...) expr) val ...)))) | |
(define-syntax let1* | |
(syntax-rules () |
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
#lang r5rs | |
;Scheme doesn't come with a while loop so we create our own. | |
(define-syntax while | |
(syntax-rules (while-loop) | |
((while cond stmt1 stmt2 ...) | |
(letrec ((while-loop | |
(lambda () | |
(if cond | |
(begin stmt1 stmt2 ... (while-loop)) |
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
/** | |
* Takes a camel cased identifier name and returns an underscore separated | |
* name | |
* | |
* Example: | |
* camelToUnderscores("thisIsA1Test") == "this_is_a_1_test" | |
*/ | |
def camelToUnderscores(name: String) = "[A-Z\\d]".r.replaceAllIn(name, {m => | |
"_" + m.group(0).toLowerCase() | |
}) |
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 urllib | |
import json | |
def fetchProposals(): | |
proposals = urllib.urlopen("http://funnel.hasgeek.com/5el/json") | |
return [e for e in json.loads(proposals.read()).get('proposals') | |
if e['confirmed'] == True] |
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
#This is not a shell script even thought it looks like one | |
## Download the standard hasgeek libraries from git | |
git clone https://github.com/hasgeek/baseframe.git | |
cd baseframe/baseframe | |
make tinymce | |
cd .. | |
python setup.py develop | |
cd .. |
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
<?php | |
function caselessHasKey($arr, $str){ | |
foreach($arr as $k => $v){ | |
if(strcasecmp($str, $k) === 0) return TRUE; | |
} | |
return FALSE; | |
} | |
$a = Array("S" => 1, "I" => 2); | |
echo caselessHasKey($a, "s"); |
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
//https://www.ai-class.com/course/video/quizquestion/116 | |
//Calculate the average and the covariance matrix. | |
val ls = List(3 -> 8, 4 -> 7, 5 -> 5, 6 -> 3, 7 -> 2) | |
val l = ls.map{case (a, b) => (a.toDouble, b.toDouble)} | |
def square(n:Double) = n*n | |
def mu(l:List[Double]):Double = l.sum/l.length | |
def sigmaSq(l:List[Double], mu:Double):Double = l.map(x=>square(x-mu)).sum/l.length |
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 collection.generic.CanBuildFrom | |
object Unfoldable{ | |
implicit def anyToUnfoldable[T](t:T) = new Unfoldable(t) | |
} | |
class Unfoldable[T](x: T){ | |
def unfoldLeft[B, That](stop:T)(f:T=>(B, T)) | |
(implicit bf: CanBuildFrom[Nothing, B, That]): That = { | |
val b = bf() | |
def unfold(v:T){ |