Skip to content

Instantly share code, notes, and snippets.

@KWMalik
KWMalik / tree.md
Created October 12, 2012 21:57
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

Feature: search for movies by director
As a movie buff
So that I can find movies with my favorite director
I want to include and serach on director information in movies I enter
Background: movies in database
Given the following movies exist:
| title | rating | director | release_date |
@KWMalik
KWMalik / GameDef.scala
Created November 21, 2012 19:07 — forked from supki/GameDef.scala
Functional programming course at Coursera week 7.
package streams
import common._
trait GameDef {
case class Pos(x: Int, y: Int) {
def dx(d: Int) = copy(x = x + d, y)
def dy(d: Int) = copy(x, y = y + d)
@KWMalik
KWMalik / SHITLOAD
Created November 21, 2012 19:16 — forked from supki/SHITLOAD
How to create and use filters via libstackexchange
# First, try to get question body with default filter
μ> (fmap head . askSE $ questionsOnUsers [972985] <> site "stackoverflow" ) >>= (^! field "body") :: IO String
*** Exception: user error (key "body" not present)
# Okay, create appropriate filter for this task and get its name
μ> (askSE $ createFilter ["question.body"] [] "default") >>= (^! field "items" . fields "filter") :: IO [String]
["!9hnGssGO4"]
# See
μ> (fmap head . askSE $ questionsOnUsers [972985] <> site "stackoverflow" <> filter "!9hnGssGO4") >>= (^! field "body") :: IO String
@KWMalik
KWMalik / improved_tutorial.py
Created November 24, 2012 17:02 — forked from ipl31/improved_tutorial.py
Improved Tutorial 9 to be a little more pythonic and also track tickers with matched events
'''
(c) 2011, 2012 Georgia Tech Research Corporation
This source code is released under the New BSD license. Please see
http://wiki.quantsoftware.org/index.php?title=QSTK_License
for license details.
Created on March, 5, 2012
@author: Sourabh Bajaj
@contact: [email protected]