Skip to content

Instantly share code, notes, and snippets.

@flyingmachine
flyingmachine / enqueue-expansion.clj
Created February 15, 2015 15:05
enqueue expansion
(let [saying (promise)]
(future (deliver saying (do (wait 100 "Cheerio!"))))
@(let [saying (promise)]
(future (deliver saying (do (wait 400 "Pip pip!"))))
@(let [saying (promise)]
(future (deliver saying (do (wait 200 (println "'Ello, gov'na!")))))
(println @saying)
saying)
(println @saying)
saying)
@flyingmachine
flyingmachine / hang.clj
Created October 14, 2014 14:26
http-kit client hanging
(defn app [req]
{:status 200
:headers {"Last-Modified" "Wed, 28 May 2014 19:41:37 GMT", "Content-Length" "2"}
:body "ok"})
(org.httpkit.server/run-server app {:port 7071})
@(org.httpkit.client/get "http://localhost:7071" {:timeout 500})
; => {:opts {:url "http://localhost:7071", :method :get, :timeout 500}, :error #<TimeoutException org.httpkit.client.TimeoutException: read timeout: 500ms>}
(div :class "filters"
(loop-tpl :bindings [name ["bob" "joe"]]
(div
(h3 (text "~{name}"))))
(ul
(loop-tpl :bindings [attr ["a" "b"]]
(li (text "~{attr}")))))
(div :class "filters"
(loop-tpl :bindings [name ["bob" "joe"]]
(div
(h3 (text "~{name}"))
(ul
(loop-tpl :bindings [attr ["a" "b"]]
(li (text "~{attr}")))))))
@flyingmachine
flyingmachine / defnpd.clj
Last active December 18, 2015 18:49
This macro lets you easily create functions with default positional arguments
(defmacro defnpd
;; defn with default positional arguments
[name args & body]
(let [unpack-defaults
(fn [args]
(let [[undefaulted defaulted] (split-with (comp not vector?) args)
argcount (count args)]
(loop [defaulted defaulted
argset {:argnames (into [] undefaulted)
:application (into [] (concat undefaulted (map second defaulted)))}
@flyingmachine
flyingmachine / gist:5735498
Last active December 18, 2015 05:49
Woohoo! Wrote my first emacs key binding!
(defun nrepl-start-http-server ()
(interactive)
(nrepl-load-current-buffer)
(nrepl-set-ns (nrepl-current-ns))
(nrepl-interactive-eval "(def server (-main)) (println server)"))
(eval-after-load 'nrepl
'(define-key clojure-mode-map (kbd "C-c C-v") 'nrepl-server))
@flyingmachine
flyingmachine / dissipation.clj
Created February 6, 2013 15:42
dissipation in two languages
(defn dissipation
[decrements]
(let [size (count decrements)]
(loop [acc []
sum size
acc-position 0
decrements decrements]
(cond
(= size (count acc))
acc
#!/usr/bin/env ruby
# Simple, not robust script for pairing sql fields to values
# example usage: pbpaste | ./sql_pairs.rb
sql = STDIN.read
# sql = %{INSERT INTO "users" ("username", "email") VALUES ('joe schmoe', 'joe@schmoe.com')}
begin
@flyingmachine
flyingmachine / ns
Created January 21, 2013 00:36
A few YASnippet snippets for clojure's nrepl-mode
#name: ns
# --
(in-ns '${1:name})