This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT localhost:9200/test | |
curl -XPUT localhost:9200/test/tweet/_mapping -d ' | |
{ | |
"tweet" : { | |
"properties" : { | |
"name" : { | |
"type" : "string" | |
}, | |
"comments" : { | |
"properties" : { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/$ 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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. |