Skip to content

Instantly share code, notes, and snippets.

View sidharthkuruvila's full-sized avatar

Sidharth Kuruvila sidharthkuruvila

View GitHub Profile
@sidharthkuruvila
sidharthkuruvila / dedup.py
Created March 3, 2017 17:17
cat test.csv | sort | python dedup.py
import itertools
import sys
for k, s in itertools.groupby(sys.stdin.readlines(), lambda x: x.split(",")[0]):
sys.stdout.write(next(s))
@sidharthkuruvila
sidharthkuruvila / data_holder.js
Created December 15, 2016 12:38
Migrate knex migrations to liquibase
exports.queries = [];
exports.holder = [];
@sidharthkuruvila
sidharthkuruvila / lets.scm
Created September 2, 2012 21:58
let, let* and named let in scheme.
#lang racket
(define-syntax let1
(syntax-rules ()
((let1 ((var val) ...) expr)
((lambda (var ...) expr) val ...))))
(define-syntax let1*
(syntax-rules ()
@sidharthkuruvila
sidharthkuruvila / map.scm
Created September 2, 2012 02:37
An imperative implementation of map in scheme
#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))
@sidharthkuruvila
sidharthkuruvila / gist:3154845
Created July 21, 2012 06:30
Utility to functions to convert between camel case and underscore separated names
/**
* 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()
})
@sidharthkuruvila
sidharthkuruvila / gist:3141271
Created July 19, 2012 07:12
Fetch Proposals
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]
@sidharthkuruvila
sidharthkuruvila / gist:2916970
Created June 12, 2012 11:20
Hack night setup notes
#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 ..
<?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");
//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
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){