Skip to content

Instantly share code, notes, and snippets.

View zeeshanlakhani's full-sized avatar

Zeeshan Lakhani zeeshanlakhani

View GitHub Profile
@zeeshanlakhani
zeeshanlakhani / generator-ttd.scm
Created September 30, 2011 17:32 — forked from apg/generator-ttd.scm
generators (like python yield), in scheme, a language that doesn't normally have them.
;; Deriving something like generators, but I didn't really feel like
;; doing exactly that.
;; It doesn't, for instance, support sending back into the generator
;; This applys a function across a range from 0 to x.
(define (apply-to-range f i x)
(when (< i x)
(f i)
(apply-to-range f (+ 1 i) x)))
@zeeshanlakhani
zeeshanlakhani / monoid.py
Created October 13, 2011 15:49
Python Monoid
#Code from http://fmota.eu/, great!
class Monoid:
def __init__(self, null, lift, op):
self.null = null
self.lift = lift
self.op = op
def fold(self, xs):
if hasattr(xs, "__fold__"):
return xs.__fold__(self)
@zeeshanlakhani
zeeshanlakhani / disc.py
Created October 16, 2011 04:45 — forked from jaymzcd/disc.py
Codility tests
#!/usr/bin/env python2
from itertools import combinations
def number_of_disc_intersections(A):
boundries = list()
for x, r in enumerate(A):
boundries.append((x-r, x+r))
r = range(len(A))
@zeeshanlakhani
zeeshanlakhani / decorators.py
Created October 19, 2011 02:12
Make a Decorator Python
#simple decorators concept from...
#http://stackoverflow.com/questions/739654/understanding-python-decorators
def makebold(fn):
def wrapped():
return "<b>" + fn() + "</b>"
return wrapped
def makeitalic(fn):
def wrapped():
@zeeshanlakhani
zeeshanlakhani / grep.py
Created October 19, 2011 02:27
Coroutine Simple Example Python
# grep.py
#
# A very simple coroutine
def grep(pattern):
print "Looking for %s" % pattern
while True:
line = (yield)
if pattern in line:
print line,
@zeeshanlakhani
zeeshanlakhani / make_turk_job.py
Created October 28, 2011 21:47 — forked from aparrish/make_turk_job.py
make a mechanical turk job with boto
import boto.mturk
import boto.mturk.connection
import boto.mturk.price
from boto.mturk.question import *
import sys
question = QuestionForm([
Question(
identifier=1,
content=QuestionContent([
@zeeshanlakhani
zeeshanlakhani / jquery.ba-tinypubsub.js
Created November 2, 2011 21:45 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@zeeshanlakhani
zeeshanlakhani / TestSing.java
Created November 14, 2011 17:32
Simple Singleton Example in Java
import java.io.*;
import java.util.*;
class Singleton {
private static Singleton _Instance;
private Singleton()
{
}
@zeeshanlakhani
zeeshanlakhani / function_lengths.py
Created January 8, 2012 22:42 — forked from wesm/function_lengths.py
Count all function lengths under a directory
from pandas import DataFrame
from pandas.util.testing import set_trace
import os
import numpy as np
import matplotlib.pyplot as plt
dirs = []
names = []
lengths = []
@zeeshanlakhani
zeeshanlakhani / sinatra_metal.rb
Created January 9, 2012 16:39 — forked from raggi/sinatra_metal.rb
sinatra as rails metal example - mostly unnecessary
require 'sinatra/metal'
class SinatraMetal < Sinatra::Base
include Sinatra::Metal
get '/sinatra' do
'hello sinatra!'
end
end