Skip to content

Instantly share code, notes, and snippets.

View superbobry's full-sized avatar

Sergei Lebedev superbobry

View GitHub Profile
@superbobry
superbobry / gist:802449
Created January 30, 2011 02:27
a sketch of HTTP Digest Mixin for Tornado
# -*- coding: utf-8 -*-
"""
Incomplete RFC 2617 implementation for Tornado web server [1], originally
implemeted as `curtain` by Brian K. Jones [2].
[1] http://tornadoweb.org
[2] http://github.com/bkjones/curtain
"""
@superbobry
superbobry / gist:1104021
Created July 25, 2011 12:28
CoffeeScript awesomeness!
coffee> f = ([x, y]) -> x + y
[Function]
coffee> f([1, 2])
3
coffee> f = ({x, y}) -> x + y
[Function]
coffee> f({x: 1, y: 2})
3
>>> map(lambda (x, y): x + y, ([1, 2], [3, 4]))
[3, 7]
>>> map(lambda (x, y): x + y, [xrange(2)])
[1]
>>> def g():
... yield 1
... yield 2
...
>>> map(lambda (x, y): x + y, [g()])
[3]
@superbobry
superbobry / gist:1316541
Created October 26, 2011 14:39
fetch a list of depends from _oasis file
#use "topfind"
#require "oasis.base"
open OASISTypes
open OASISVersion
let (|>) x f = f x
let find_all_depends =
let rec inner acc = function
@superbobry
superbobry / gist:1362119
Created November 13, 2011 13:37
Small ints in PyPy and CPython
# PyPy
>>>> 0 is 0
True
>>>> x = 0
>>>> x is 0
False
# CPython
>>> 0 is 0
True
@superbobry
superbobry / okasaki.ml
Created December 9, 2011 19:52
okasaki exercises
(* Chapter 2: BST *)
type 'a tree = Empty | Node of 'a tree * 'a * 'a tree
module Set : sig
val empty : 'a tree
val member : 'a tree -> 'a -> bool
val insert : 'a tree -> 'a -> 'a tree
end = struct
@superbobry
superbobry / treap.ml
Created December 14, 2011 23:17
basic treap implementation
(** Task X: Treap. *)
module Treap = struct
type ('a, 'b) t =
| Empty
| Node of ('a, 'b) t * 'a * 'b * ('a, 'b) t
let empty = Empty
let rec merge l r = match (l, r) with
@superbobry
superbobry / gist:1617642
Created January 15, 2012 22:03
First class modules and functors
# module M = Map.Make((val (module String : Map.OrderedType) : Map.OrderedType));;
module M :
sig
type key
type +'a t
end
# module M = Map.Make(String);;
module M :
sig
type key = String.t
@superbobry
superbobry / rose.ml
Created February 15, 2012 20:08
Basic Rose Trees in OCaml
open StdLabels
type 'a tree = Node of ('a * 'a tree list)
let rec make ~f init =
let (label, forest) = f init in
Node (label, (List.map ~f:(make ~f) forest))
and draw ~f (Node (label, forest)) =
let rec inner = function
@superbobry
superbobry / gist:1917188
Created February 26, 2012 15:00
Iterable unpacking in Python
>>> def f((x, y)): return x + y
...
>>> def gen():
... yield 1
... yield 2
...
>>>
>>> f(gen())
3