Skip to content

Instantly share code, notes, and snippets.

View daveyarwood's full-sized avatar

Dave Yarwood daveyarwood

View GitHub Profile
(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))]
@jgrimes
jgrimes / trampoline.clj
Created October 6, 2016 20:30
Trampolined Style in Clojure
#!/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])
@mastef
mastef / isexist_vs_isnotexist.go
Created February 4, 2016 08:30
os.IsExist(err) vs os.IsNotExist(err)
/*
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"
@noprompt
noprompt / slurp.clj
Created February 19, 2014 04:52
How to use slurp from ClojureScript
(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]]))
@fogus
fogus / forth.rb
Created January 26, 2012 03:32 — forked from deadprogram/forth.rb
Forth interpreter in 64 lines of Ruby
#!/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 = []