This file contains 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
#!/usr/bin/env ruby | |
def pop; $stack.pop || raise(StackUnderflow); end | |
def push(expression); $stack << expression; end | |
def unary; -> { push(yield pop) }; end | |
def binary; -> { push(yield pop, pop) }; end | |
def unary_boolean; -> { push(if yield pop then 1 else 0 end) }; end | |
def binary_boolean; -> { push(if yield pop, pop then 1 else 0 end) }; end | |
def swap; $stack[-2,2] = $stack[-2,2].reverse; end | |
$stack = [] |
This file contains 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 foo.core | |
(:refer-clojure :exclude [slurp])) | |
(defmacro slurp [file] | |
(clojure.core/slurp file)) | |
;; In CLJS | |
(ns bar.core | |
(:require [foo.core :include-macros true :refer [slurp]])) |
This file contains 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
/* | |
Watch out, os.IsExist(err) != !os.IsNotExist(err) | |
They are error checkers, so use them only when err != nil, and you want to handle | |
specific errors in a different way! | |
Their main purpose is to wrap around OS error messages for you, so you don't have to test | |
for Windows/Unix/Mobile/other OS error messages for "file exists/directory exists" and | |
"file does not exist/directory does not exist" |
This file contains 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
#!/usr/bin/env boot | |
;; | |
;; Threads & concurrency without hardware threads or continuations | |
;; | |
;; Most of this is from the paper "Trampolined Style" by Ganz, Friendman, and Wand | |
;; | |
(defrecord Done [value]) | |
(defrecord Doing [thunk]) |
This file contains 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 fjorm.http | |
(:require | |
[cheshire.core :as json])) | |
(defmacro with-open-> [stream & body] | |
`(with-open [stream# ~stream] | |
(-> stream# ~@(map #(if (seq? %) % (list %)) body)))) | |
(defn post-json [url json] | |
(let [bytes (.getBytes (json/generate-string json))] |