Skip to content

Instantly share code, notes, and snippets.

@naiquevin
naiquevin / elections2014.py
Created May 16, 2014 12:49
elections2014
import os
import json
import requests
from lxml import html
def num_to_state(n):
assert n <= 35
if n < 10:
@naiquevin
naiquevin / concurrently.py
Last active August 29, 2015 14:01
Concurrently run list of functions and get results as a list
from operator import itemgetter
from threading import Thread
try:
from Queue import Queue
except ImportError:
from queue import Queue
def concurrently(fns):
@naiquevin
naiquevin / message_ring.erl
Created May 29, 2014 16:49
message_ring.erl
-module(message_ring).
-compile(export_all).
-export([]).
%% Problem Statement: Write a ring benchmark. Create N processes in a
%% ring. Send a message round the ring M times so that a total of N *
%% M messages get sent. Time how long this takes for different values
%% of N and M.
@naiquevin
naiquevin / fifthel-mcl-r-session.txt
Last active August 29, 2015 14:02
Hands on R session from Machine learning workshop
### Hands on R session by Harshad Saykhedkar from today's Machine
### learning workshop (Fifth elephant Mumbai run-up event)
---
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: i686-pc-linux-gnu (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
@naiquevin
naiquevin / a.py
Last active August 29, 2015 14:09
Python scoping
import d
x = 10
def f(n):
return x + n
print 'f(2) called directly in module a [a.x = 10]'
print f(2)
@naiquevin
naiquevin / async.clj
Created January 8, 2015 18:10
clojure core.async - consume until some timeout
(defn consume-until-timeout
[ms ch f init & args]
(let [tmt (timeout ms)]
(go (loop [ret init]
(if-let [v (first (alts! [ch tmt]))]
(recur (apply f ret [v]))
ret)))))
(comment
@naiquevin
naiquevin / throttle_greedy.py
Created June 30, 2015 18:54
Greedy throttling for function calls
import time
from functools import wraps
def throttle_greedy(wait):
def decorator(fn):
state = {'last_call_at': None}
@wraps(fn)
def wrapper(*args, **kwargs):
@naiquevin
naiquevin / acl_ex1.php
Created November 14, 2011 11:39
Code Examples for Acl in Kodelearn http://github.com/kodeplay/kodelearn
<?php
// defining resource-levels as arrays
return array(
'exam' => array(
'levels' => array(
'view',
'create',
'edit',
'delete'
@naiquevin
naiquevin / dummy.php
Created June 18, 2012 06:49
Kodemall Cache examples
<?php
class DummyCacheBackend implements CacheBackend {
public function get($key) {
return array();
}
public function set($key, $value) {
return;
@naiquevin
naiquevin / notes.txt
Created August 15, 2012 15:27
Tuple based tree implementation in Erlang (from LYSE) and Python
The no. of lines in erlang implementation is half that in python!
Observe how pattern matching alone gets rid of the selector functions