Skip to content

Instantly share code, notes, and snippets.

(defn lowercase-keys
[m]
(into {} (for [[k v] m]
[(.toLowerCase k) v])))
(defn remove-hop-by-hop-headers
"Removes hop-by-hop headers from a ring request/response map.
Assumes header keys are lowercase strings.
See:
@lynaghk
lynaghk / grr.clj
Created August 17, 2013 17:31
Channel composition; it's fine, but I'm already missing function composition
(defn map-into
"Forwards `(f (<! recv))` to `send`; returns `send` for convenience."
[send f recv]
(go (loop []
(let [val (<! recv)]
(when-not (nil? val)
(>! send (f val))
(recur)))))
send)
@lynaghk
lynaghk / run.rb
Last active December 31, 2015 05:09
#this works
docker run -i -privileged -v /examples:/examples my-box ruby /examples/run.rb
#this doesn't
(cd /examples && tar -cf - .) | docker run -i -privileged my-box bash -c "mkdir foo && cd foo && tar -mxf - && ruby run.rb"
;;with adv. optimizations on my macbook air
(ns foo
(:require [datascript :as d]))
(d/q '[:find (sum ?x)
:with ?idx
:in [[?idx ?x]]]
(map-indexed vector (range 10000)))
module Saucelabs
SAUCE_USERNAME = ''
SAUCE_TOKEN = ''
def self.setup_saucelabs_connection!(driver=nil)
WebMock.allow_net_connect!
driver ||= {
capability: :chrome,
platform: 'Windows 8',
version: '',
@lynaghk
lynaghk / deploy.sh
Created May 23, 2015 06:56
Sketch of setting up a server for Clojure apps
#!/bin/bash
set -e
lein uberjar
rsync target/weathertron.jar weathertron@weathertron:.
ssh root@weathertron svc -t /etc/service/weathertron
@lynaghk
lynaghk / gist:0b401411dd55d7af20d2
Created June 3, 2015 03:58
copy and eval form in cider buffer.
(defun cider-send-dwim (arg)
"Send the appropriate forms to the REPL to be evaluated."
(interactive "P")
(let ((expr (cider-last-sexp)))
(set-buffer (cider-current-repl-buffer))
(unless (eq (current-buffer) (window-buffer))
(pop-to-buffer (current-buffer) t))
(goto-char (point-max))
(insert expr)
(cider-repl-return)
@lynaghk
lynaghk / gist:52ec255ea22ba9f1efef
Created June 16, 2015 19:15
datascript entity export
;;Export datoms, replacing eids w/ tempids so that the datoms can be imported into a second datascript/datomic db.
(let [db (d/db conn)
eids (->> (d/q '{:find [?eid]
:in [$ %]
:where [(exportable ?eid)]}
db export-rules)
(map first)
set)
@lynaghk
lynaghk / gist:0608a43f173558b6fcf30c3be53d77dd
Last active November 13, 2017 10:43
cljs production mode

I'm modeling a state machine in ClojureScript and am using clojure.spec to check invariants in each state.

However, I'd like to remove this checking in the production build, since it adds ~ 200kB minified code size and 100ms startup time.

I haven't been able to find a tidy way to do this --- this writeup explains the approaches I've considered and their tradeoffs.

Here's the current setup:

(ns app.state-machines.foo
@lynaghk
lynaghk / foo.ebnf
Last active December 7, 2017 07:44
2017 advent of code day 7, interactive repl session
<deps> = node (<'->'> names)?
node = name weight
names = name (<','> name)*
weight = <'('> #"[0-9]+" <')'>
name = #"[A-z]+"