Skip to content

Instantly share code, notes, and snippets.

View gist:138490
import functional
def MultiCompose(*funcs):
"""Return a function composed of many functions
MultiCompose(f, g, h) == f(g(h))
return functional.partial(reduce, functional.compose)(funcs)
View gist:139774
def balanced(s, parens="()[]", swap={')':'(', ']':'['}):
if list(reversed(s[:len(s)//2])) == [swap.get(c) for c in list(s)[len(s)//2:]]:
return all(True for i in s if i not in parens)
return False
def balanced(s, parens="()[]", swap={')':'(', ']':'['}):
return all(True for i in s if i not in parens) if list(reversed(s[:len(s)//2]))\
== [swap.get(c) for c in list(s)[len(s)//2:]] else False
View genetic.clj
; A Field Guide to
; Genetic Programming
(defn f2-1
"Figure 2.1 max(x+x, x+3*y)"
[x y]
(max (+ x x)
(+ x
(* 3 y))))
View zshenv
# Dynamically build the $PATH variable
for dircomponent in $path /sw/bin /sw/sbin /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin /compat/linux/bin /compat/linux/sbin /compat/linux/usr/bin /compat/linux/usr/sbin /usr/games /usr/X11R6/bin /usr/X11R6/sbin ~/bin ~/crossover/bin
if [[ -e $dircomponent ]]; then
path=($path $dircomponent)
typeset -U path
View wide_finder_mod.clj
;; Discussed in detail at
(ns wide-finder
"A basic map/reduce approach to the wide finder using agents.
Optimized for being idiomatic and readable rather than speed."
(:use [ :only [reader]]))
(def re #"GET /(\d+)")
(defn inc-or-init [i]
(if i (inc i) 1))
View ConsumerSet separate callback ack error
Traceback (most recent call last):
File "", line 399, in <module>
main(opts, args)
File "", line 369, in main
File "/home/chris/devel/envs/tg2env/lib/python2.6/site-packages/carrot-0.8.0-py2.6.egg/carrot/backends/", line 195, in consume
File "build/bdist.linux-i686/egg/amqplib/client_0_8/", line 107, in wait
File "build/bdist.linux-i686/egg/amqplib/client_0_8/", line 1973, in _basic_deliver
File "/home/chris/devel/envs/tg2env/lib/p
View layout.harmony.js
IMPORTANT: Requires this version of jquery
until 1.3.3 comes out
ALSO: This is very dirty still and has not been
abstracted for use. It is just solving our immediate problems.
Use cases that must pass (and should be tested someday):
* Clicking on links updates layout
* Click around a bit and then use back/forward buttons
View chris.el
;; windows emacs customisations after using emacs starter kit.
;; font
'(default ((t (:height 115 :width normal :foundry "outline" :family "Lucida Console")))))
;; themes
(add-to-list 'load-path "color-theme.el")
(require 'color-theme)
View main.clj
(GET "/queue/:id" [{:headers {"Content-Type" "application/json"}}]
(let [res (poll-queue-for-messages (params :id))]
(if (pos? (count res))
(json-str res)
View viewer.js
success: function (data) {
//called when successful
if (data.length) {
// $.each(data, function (i, msg) {
// msg = $('<p/>').haml(message(msg)).html()
// $(msg).insertAfter('.queue_title')
// .animate({height: "toggle"}, 0).animate({height: "toggle"}, {queue: true});
// });
function make_caller_with_tail(msgs) {