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
#name: ns | |
# -- | |
(in-ns '${1:name}) |
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
#!/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', '[email protected]')} | |
begin |
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
(defn dissipation | |
[decrements] | |
(let [size (count decrements)] | |
(loop [acc [] | |
sum size | |
acc-position 0 | |
decrements decrements] | |
(cond | |
(= size (count acc)) | |
acc |
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
(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)) |
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 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)))} |
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
(div :class "filters" | |
(loop-tpl :bindings [name ["bob" "joe"]] | |
(div | |
(h3 (text "~{name}")) | |
(ul | |
(loop-tpl :bindings [attr ["a" "b"]] | |
(li (text "~{attr}"))))))) |
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
(div :class "filters" | |
(loop-tpl :bindings [name ["bob" "joe"]] | |
(div | |
(h3 (text "~{name}")))) | |
(ul | |
(loop-tpl :bindings [attr ["a" "b"]] | |
(li (text "~{attr}"))))) |
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
(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>} |
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
(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) |