Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / .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"
@jgdavey
jgdavey / gist:1685824
Created January 26, 2012 23:28
Harvest your git messages
#!/usr/bin/env ruby
# Adapted from https://gist.github.com/946311
#
# To use, put something like the following in your .bashrc.local:
#
# alias harvest='rvm use 1.9.2@harvester;harvester;cd ..;cd -'
author = `git config --global user.name`.chomp
@jgdavey
jgdavey / _hitch.sh
Created October 2, 2011 17:51
Hitch author completion
#compdef hitch
__hitch_authors() {
local expl
local -a _authors
if [ -f $HOME/.hitch_pairs ]; then
_authors=(${${(f)"$(cat $HOME/.hitch_pairs | awk '/:/ { print }')"}/:[ $'\t']##/:})
fi
_describe -t hitch-authors 'hitch authors' _authors "$@"
}
function! s:ToggleDoEndOrBrackets()
let char = getline('.')[col('.')-1]
if char =~ '[{}]'
if char=='}'
norm %
endif
norm h
" Bracket touching previous word
if getline('.')[col('.')-1] =~ '[^ ;]'
exe "norm! a "