Instantly share code, notes, and snippets.

# Vincent Foleygnuvince

• Sort options
Created Jul 14, 2014
View gist:dc45daf97d3de3eef227
 def g(x): return x*x def f(x): global f if x == 5: f = g return x print [f(x) for x in xrange(10)]
Created Nov 26, 2014
 (* Lexer *) { open Parser } let alpha = ['a'-'z' 'A'-'Z' '_'] let digit = ['0'-'9'] let alnum = (alpha | digit) let intlit = digit+ let ident = alpha alnum*
Created Feb 5, 2009
View gist:58942
 (def brackets (zipmap "([{<" ")]}>")) (def opening-brackets (set (keys brackets))) (def closing-brackets (set (vals brackets))) (defn- check-aux [[x & xs] stack] (if x (cond (opening-brackets x) (recur xs (conj stack (brackets x))) (closing-brackets x) (if (= x (peek stack)) (recur xs (pop stack)) false)
Created Feb 5, 2009
View gist:58924
 (def opening-brackets "({[<") (def closing-brackets ")}]>") (def brackets (reduce #(apply assoc %1 %2) {} (map vector opening-brackets closing-brackets))) (defn- check-aux [[x & xs] stack] (if x (cond (some #{x} opening-brackets) (recur xs (conj stack (brackets x))) (some #{x} closing-brackets) (if (= x (peek stack)) (recur xs (pop stack))
Created Feb 6, 2009
View gist:59176
 >>> s1 = set(["a", "b", "c"]) >>> s2 = set(["a"]) >>> s1 - s2 set(['c', 'b'])
Created Feb 13, 2009
View gist:63007
 {21:33}[vince@vincent: prog/clojure]% clj slowdemo.clj get-byte "Elapsed time: 202.54176 msecs" get-short "Elapsed time: 110.68448 msecs" {21:33}[vince@vincent: prog/clojure]% clj slowdemo.clj Reflection warning, line: 9 - call to and can't be resolved. Reflection warning, line: 14 - call to and can't be resolved. get-byte
Created Feb 14, 2009
View gist:64518
 user> (def rep (unpack (File. "/home/vince/prog/python/pyreplib/misc/sea_savior.rep"))) #'user/rep user> (unit-distribution (get-in rep [:players 0 :actions])) {"Firebat" 34, "Dropship" 3, "Science Vessel" 43, "Medic" 48, "Marine" 599, "SCV" 82} user> (unit-distribution (get-in rep [:players 1 :actions])) {"Ultralisk" 95, "Defiler" 32, "Scourge" 25, "Mutalisk" 8, "Zergling" 179, "Overlord" 35, "Drone" 158} user> (action-distribution (get-in rep [:players 1 :actions]))
Created Aug 3, 2010
View gist:505810
 /* * Compare two cards and return: * < 0 if a is smaller than b * 0 if a is equal to b * > 0 if a is greater than b */ int CardCompare(const Card* a, const Card* b) { if (a == NULL) return 1; if (b == NULL)
Created Dec 18, 2011
View tree.ml
 type 'a tree = | Empty | Node of ('a * 'a tree * 'a tree) let rec walk_tree f tree = match tree with | Empty -> () | Node (x, left, right) -> f x; walk_tree f left;
Created Dec 18, 2011
View tree.ml
 type 'a tree = | Empty | Node of ('a * 'a tree * 'a tree) let rec walk_tree f tree = match tree with | Empty -> () | Node (x, left, right) -> f x; walk_tree f left;
You can’t perform that action at this time.