Skip to content

Instantly share code, notes, and snippets.

View mpenet's full-sized avatar
🪲
breeding bugs

Max Penet mpenet

🪲
breeding bugs
View GitHub Profile
(defmacro let-pipeline [decls & body]
(let [pairs (partition 2 decls)
vars (map first pairs)
exprs (map second pairs)
predecessors (map #(take % vars) (range (count vars)))]
`(let [~@(mapcat
(fn [v preds expr]
`[~v
(run-pipeline (merge-results ~@preds)
(fn [[~@preds]] ~expr))])
@jlongster
jlongster / gist:1979842
Created March 5, 2012 17:50
Outlet meta-circular evaluator
;; Requires Outlet to run: https://github.com/jlongster/outlet
;;
;; Run with: `ol main.ol <input-file>`
;;
;; This is a meta-circular evaluator for a basic Lisp. It is
;; mostly taken from SICP 4.1*. I wanted to see if I could write a
;; debugger with it. Turns out if I want control over control flow I
;; need a register-based interpreter.
;;
;; * http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1
@erluko
erluko / ReturningException.java
Created November 19, 2011 23:09
Example of potential performance benefit of early exit in reduce
/* don't use this, it's just for a timing demonstration */
public class ReturningException extends RuntimeException {
transient public final Object data;
transient public final Object context;
public ReturningException(Object o){
this(null, o);
}
public ReturningException(Object c, Object o){
super("Not really an exception");
@simonmichael
simonmichael / gist:1185421
Created September 1, 2011 03:59
ghc-pkg-clean, ghc-pkg-reset
# unregister broken GHC packages. Run this a few times to resolve dependency rot in installed packages.
# ghc-pkg-clean -f cabal/dev/packages*.conf also works.
function ghc-pkg-clean() {
for p in `ghc-pkg check $* 2>&1 | grep problems | awk '{print $6}' | sed -e 's/:$//'`
do
echo unregistering $p; ghc-pkg $* unregister $p
done
}
# remove all installed GHC/cabal packages, leaving ~/.cabal binaries and docs in place.
curl -XPUT localhost:9200/test
curl -XPUT localhost:9200/test/tweet/_mapping -d '
{
"tweet" : {
"properties" : {
"name" : {
"type" : "string"
},
"comments" : {
"properties" : {
@weavejester
weavejester / gist:1001206
Created May 31, 2011 20:27
Clojure on Heroku
~/$ lein new ring-on-heroku
Created new project in: /home/jim/Development/ring-on-heroku
~/$ cd ring-on-heroku
~/ring-on-heroku$ echo 'web: lein run -m ring-on-heroku.core' > Procfile
~/ring-on-heroku$ cat > src/ring_on_heroku/core.clj
(ns ring-on-heroku.core
(:use ring.util.response
ring.adapter.jetty))
(defn app [req]
@jasonroelofs
jasonroelofs / setup-statsd.sh
Created April 27, 2011 18:25 — forked from collegeman/setup-statsd.sh
Turn an Ubuntu 10.10 EC2 into a StatsD/Graphite server
# install git
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
# install the Node package manager for later use
@pallix
pallix / ns
Created April 20, 2011 14:17
Emacs YASnippet snippet for Clojure ns declarations
(ns `(let* ((nsname '())
(dirs (split-string (buffer-file-name) "/"))
(aftersrc nil))
(dolist (dir dirs)
(if aftersrc
(progn
(setq nsname (cons dir nsname))
(setq nsname (cons "." nsname)))
(when (or (string= dir "src") (string= dir "test"))
(setq aftersrc t))))
jQuery.format = function(s, args) {
return s.replace(/\{([^}]+)\}/g, function(_, match){return args[match] || '';});
};
>> $.format('Hello {world}, {again}', {world: "universe", again: "testing"});
"Hello universe, testing"
>> $.format('Hello {0}, {1}', ["foo", "bar"]);
"Hello foo, bar"
(defmacro _->
([x] x)
([x form] (if (seq? form)
(if (seq-utils/includes? form '_)
(with-meta `(~@(replace {'_ x} form)) (meta form))
(with-meta `(~(first form) ~x ~@(next form)) (meta form)))
(list form x)))
([x form & more] `(_-> (_-> ~x ~form) ~@more)))
;-> and _-> are almost the same behavior until _ is specified.