Skip to content

Instantly share code, notes, and snippets.

@jgdavey
jgdavey / scratch.clj
Created September 30, 2016 20:31
Datomic Database Functions
;; Install boot.
;; In the same folder as this file, run:
;; boot -d com.datomic/datomic-free:0.9.5404 -r $PWD repl
(ns scratch
(:require [datomic.api :as d]))
(d/create-database "datomic:mem://scratch")
(def conn (d/connect "datomic:mem://scratch"))
(def schema
@jgdavey
jgdavey / keybase.md
Created February 7, 2016 15:55
keybase.md

Keybase proof

I hereby claim:

  • I am jgdavey on github.
  • I am joshuadavey (https://keybase.io/joshuadavey) on keybase.
  • I have a public key ASC8tdiHKKv4NE6qgIYzZDyVegyL9IrqEoKXxomWczwAuwo

To claim this, I am signing this object:

@jgdavey
jgdavey / expiry_chan.clj
Last active February 12, 2016 02:13
Channel that excludes "old" items (defined by max-age-millis)
(ns expiry-chan
(:require [clojure.core.async :as async :refer [go >! <! chan]]))
(defn expiry-chan [in max-age-millis]
(let [middler (chan 1024 (map #(vector (System/currentTimeMillis) %)))
out (chan)]
(async/pipe in middler)
(go (loop []
(if-let [[ts value] (<! middler)]
(do
@jgdavey
jgdavey / .vimrc
Created February 23, 2015 01:58
browser repl vimrc workaround
function! s:brepl(remove) abort
if a:remove
call fireplace#platform().piggieback("", 1)
echo "Piggieback connection removed"
else
let form = '(do ' .
\ '(require ''adzerk.boot-cljs-repl)' .
\ '(let [env (adzerk.boot-cljs-repl/repl-env)]' .
\ ' (Thread/sleep 100)' .
\ ' env))'
@jgdavey
jgdavey / vim-clojure-basics.md
Created June 13, 2014 14:12
Clojure + vim: Basic Evaluation and Documentation

Vim is a powerful text editor. Clojure is a powerful programming language. While its been possible to edit Clojure code in vim for years, the toolchain has improved greatly over the past year. Today we're going to see how we can integrate vim with our Clojure REPL environment.

Life without integration

In a shell session, let's fire up a Clojure REPL. I'm going to use lein repl to do this. In another shell session, let's start vim and edit a clojure file.

@jgdavey
jgdavey / projections.json
Created April 24, 2014 18:40
Clojure .projections.json
{
"*" : {
"start" : "lein repl",
},
"src/*.clj": {
"command": "namespace",
"alternate": "test/{}_test.clj",
"template": "(ns {dot|hyphenate})\n\n"
},
"test/*_test.clj": {
@jgdavey
jgdavey / trace_paths.clj
Created March 4, 2014 02:26
How to get paths for map of sets?
(use 'clojure.test)
(deftest tracing-paths
(testing "trace-paths"
(is (= (trace-paths {:a nil} :a)
[[:a]]))
(is (= (trace-paths {:a #{:b}
:b nil} :a)
@jgdavey
jgdavey / atomically
Created December 20, 2012 17:08
Verify a series of commits are atomic
#!/usr/bin/env bash
if [ -n "$(git status --porcelain)" ]; then
echo "ERROR: You have a dirty working copy. This command would remove any files not already checked in"
exit 1
fi
log() {
if [ -z "$quiet" ]; then
echo
@jgdavey
jgdavey / hinder.sh
Created May 14, 2012 21:03
Simulate network latency and packet loss on Mac OS X (requires sudo)
#!/bin/bash
set -e
USAGE="Usage: $0 [ip_address | reset]"
if [ "$#" == "0" ]; then
echo "$USAGE"
exit 1
fi
@jgdavey
jgdavey / .gitconfig
Created March 30, 2012 22:16
Git alias to add untracked files
[alias]
add-untracked = !"git status --porcelain | awk '/\\?\\?/{ print $2 }' | xargs git add"