Skip to content

Instantly share code, notes, and snippets.

pesterhazy / git-ag
Created Mar 1, 2014
Search your git repository using ag (the silver searcher)
View git-ag
# Put additional ignore patterns (one by line) in .grepignore
git-ag () {
if [[ "$1" = "-a" ]]
View grep-with-exclusions
#!/usr/bin/env zsh
# Grep in the files of the current git repository *with a list of exclusions*, using `git grep` or `ag`.
# Exclusions are defined in .grepignore. Each line is a regex suitable for grep(2); if the filename
# matches any of the regexes, it is excluded from the search.
# Works with zsh (bash not tested).
# Versions for `git grep` and `ag` are provided.
pesterhazy / .zshrc
Created Oct 5, 2014
symlink dotfiles in your dropbox folder to your $HOME
View .zshrc
dropbox-update-dotfiles () {
if [[ ! -d "$src" ]]; then
print Using $HOME/dotfiles.
if [[ ! -d "$src" ]]; then
print "Directory $src not found."
pesterhazy / in_vagrant
Created Dec 22, 2014
in_vagrant: transparently execute command inside vagrant
View in_vagrant
# Syntax:
# ./in_vagrant [command] [args]
# Example usage:
# Set up a Vagrantfile with a config called "foo"
pesterhazy / equalsstar.clj
Created Feb 13, 2015
Debugging aid: show differences between two data structures
View equalsstar.clj
(defn =* [a b]
(if (= a b)
(println "No match:" a b)
(println "Dfference:" )
(clojure.pprint/pprint ( a b))
pesterhazy / constrain.clj
Last active Aug 29, 2015
Constrain a sequence in clojure
View constrain.clj
(defn constrain
"Truncate a sequence
Returns a two-element vector to signal whether of not the seq has
been truncated"
[max coll]
(let [[head tail] (split-at max coll)]
(if (seq tail)
[nil (take max coll)]
pesterhazy / nixos-14.12-vagrant
Last active Aug 29, 2015
Trying out nixos 14.12 in vagrant
View nixos-14.12-vagrant
# The vagrant box provided by @zimbatm is still on 14.02. Follow
# this recipe to update the machine to 14.12
# Make sure you have a recent version of `vagrant` (
# and virtualbox.
mkdir nixos-test
cd nixos-test
vagrant init zimbatm/nixbox64 # creates Vagrantfile
vagrant up # brings up the box
pesterhazy / when-seq.clj
Created May 11, 2015
when-seq: conditionally apply operation on sequence in threading macro
View when-seq.clj
(defn when-seq
"If condition is true, perform seq operation f on xs with args; otherwise return f.
Intended for use in the thread first macro. For example:
(-> []
(when-seq x conj x))
will be [:foo] if x is :foo, [] if x is nil"
[xs condition f & args]
pesterhazy / guard-nil.clj
Last active Aug 29, 2015
guard-nil: ensure non-nil argument, raise descriptive exception otherwise
View guard-nil.clj
(defmacro guard-nil
"Returns `x` unless it is nil, in which case a descriptive exception is raised"
`(if-some [v# ~x]
(throw (AssertionError. (str "Form should not be nil: " (pr-str '~x))))))
pesterhazy / profiles.clj
Last active Aug 29, 2015
profiles.clj for leiningen: vinyasa.pull pulls lein dependencies into a running repl
View profiles.clj
;; An example of `profiles.clj'. You can install it by placing it in the
;; ~/.lein/profiles.clj folder
;; Based on the example given in:
{:user {:dependencies [[org.clojure/tools.namespace "0.2.4"]
[leiningen #=(leiningen.core.main/leiningen-version)]
[im.chit/vinyasa "0.3.4"]]
[(require '[vinyasa.inject :as inject])