Skip to content

Instantly share code, notes, and snippets.

@flyingmachine
flyingmachine / hang.clj
Created Oct 14, 2014
http-kit client hanging
View hang.clj
(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>}
View works.clj
(div :class "filters"
(loop-tpl :bindings [name ["bob" "joe"]]
(div
(h3 (text "~{name}"))))
(ul
(loop-tpl :bindings [attr ["a" "b"]]
(li (text "~{attr}")))))
View ex.clj
(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 Dec 18, 2015
This macro lets you easily create functions with default positional arguments
View defnpd.clj
(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 Dec 18, 2015
Woohoo! Wrote my first emacs key binding!
View gist:5735498
(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 / android-setup.md
Last active Jan 10, 2020
How I set up my Android development environment
View android-setup.md
  1. Download the SDK from http://developer.android.com/sdk/index.html
  2. Unpack the ZIP file (named adt-bundle-<os_platform>.zip)
  3. Move the directory adt-bundle-<os_platform> to /Applications/Android: `mv adt-bundle-<os_platform> /Applications/Android
  4. Rename "eclipse" to "Android": mv /Applications/Android/eclipse/eclipse.app /Applications/Android/eclipse/Android.app
  5. Start the Android app
  6. Go to Window->Android SDK Manager
  7. Install packages:
    • Intel x86 Atom System Image
    • Google APIs
    • Intel x86 Emulator Accelerator (HAXM) # this is toward the bottom
@flyingmachine
flyingmachine / dissipation.clj
Created Feb 6, 2013
dissipation in two languages
View dissipation.clj
(defn dissipation
[decrements]
(let [size (count decrements)]
(loop [acc []
sum size
acc-position 0
decrements decrements]
(cond
(= size (count acc))
acc
View sql_pairs.rb
#!/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 Jan 21, 2013
A few YASnippet snippets for clojure's nrepl-mode
View ns
#name: ns
# --
(in-ns '${1:name})