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
# http://dibblego.wordpress.com/2008/09/05/haskell-scala-java-7-functional-java-java/
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
; http://www.lulu.com/items/volume_63/2167000/2167025/2/print/book.pdf
(defn f2-1
"Figure 2.1 max(x+x, x+3*y)"
[x y]
(max (+ x x)
(+ x
(* 3 y))))
View zshenv
#!/bin/zsh
# 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
do
if [[ -e $dircomponent ]]; then
path=($path $dircomponent)
fi
done
typeset -U path
View wide_finder_mod.clj
;; Discussed in detail at http://technomancy.us/130
(ns wide-finder
"A basic map/reduce approach to the wide finder using agents.
Optimized for being idiomatic and readable rather than speed."
(:use [clojure.contrib.duck-streams :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 "emailerd.py", line 399, in <module>
main(opts, args)
File "emailerd.py", line 369, in main
congen.next()
File "/home/chris/devel/envs/tg2env/lib/python2.6/site-packages/carrot-0.8.0-py2.6.egg/carrot/backends/pyamqplib.py", line 195, in consume
self.channel.wait()
File "build/bdist.linux-i686/egg/amqplib/client_0_8/abstract_channel.py", line 107, in wait
File "build/bdist.linux-i686/egg/amqplib/client_0_8/channel.py", 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 http://gist.github.com/186325
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
(custom-set-faces
'(default ((t (:height 115 :width normal :foundry "outline" :family "Lucida Console")))))
;; themes
(add-to-list 'load-path "color-theme.el")
(require 'color-theme)
'(progn
(color-theme-initialize)
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)
304)))
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) {