Skip to content

Instantly share code, notes, and snippets.

View msgodf's full-sized avatar

Mark Godfrey msgodf

View GitHub Profile
@msgodf
msgodf / async-merge.clj
Last active August 29, 2015 13:57
Just a quick demo of how the Clojure core.async merge function works. I wanted to check that the values from the input channels appear in the merged channel straight away.
(clojure.core.async/go
(let [sleepy-val (fn [v t] (clojure.core.async/go
(clojure.core.async/<! (clojure.core.async/timeout t))
v))
chans (clojure.core.async/merge (map #(sleepy-val % (rand-int 3000))
(range 10)))]
(while (when-let [v (clojure.core.async/<! chans)]
(prn v)
v))))
@msgodf
msgodf / gist:4f6ca8a1df5c65bb9483
Created July 17, 2014 10:46
Encode a bunch of FLAC files in the current directory to MP3
ls -1|sed -e "s/'/\\\'/g" -e "s/.flac//g"|xargs -I{} avconv -i {}.flac -c:a libmp3lame -b:a 256k {}.mp3
@msgodf
msgodf / .bashrc
Created July 17, 2014 11:01
My .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
@msgodf
msgodf / .Xdefaults
Created July 21, 2014 10:35
My X configuration
! xscreensaver ---------------------------------------------------------------
!font settings
xscreensaver.Dialog.headingFont: -*-dina-bold-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.bodyFont: -*-dina-medium-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.labelFont: -*-dina-medium-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.unameFont: -*-dina-medium-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.buttonFont: -*-dina-bold-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.Dialog.dateFont: -*-dina-medium-r-*-*-10-*-*-*-*-*-*-*
xscreensaver.passwd.passwdFont: -*-dina-bold-r-*-*-10-*-*-*-*-*-*-*
@msgodf
msgodf / .vimrc
Created August 9, 2014 07:31
My .vimrc
set nocompatible
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
@msgodf
msgodf / update_at.clj
Created November 5, 2014 14:13
A function to update multiple parts of a structure.given a function that gives the locations of those parts.
(defn update-at
"Takes a structure, a function that returns a list of paths (lists of keys) and a
function to apply at those paths within the structure.
For any paths that don't already exist in m, then f will be called with nil
and that path in the structure will be created with the result."
[m path-generation-fn f]
(reduce (fn [s v] (update-in s v f))
m
(path-generation-fn m)))
@msgodf
msgodf / euroclojure-2015-talks
Last active August 29, 2015 14:20
EuroClojure 2015 talks
https://twitter.com/pyr "talking about #mesos and mesomatic: the cluster is a library"
https://twitter.com/AdamTornhill "Beyond Code: Repository Mining with #Clojure"
https://twitter.com/kachayev "Reinventing Haxl: Efficient, Concurrent and Concise Data Access"
https://twitter.com/ifesdjeen "Clojure is a sweet spot for Analytics"
https://twitter.com/mtrimpe "building Elephant 2000, McCarthy’s programming language for 2015, using Clojure"
@msgodf
msgodf / gist:888d90bb90b94d87d5bf
Created June 2, 2015 07:24
Git config aliases
[alias]
st = status
lg = log
ci = commit -v
co = checkout
br = branch
# View stash diffs - use n to go to the next stash and N to go to the previous stash
stp = "!IFS=$'\n';for stash in $(git stash list);do echo $stash;echo;git --no-pager diff --color=always $(echo $stash|cut -f1 -d:);done|less -pstash"
@msgodf
msgodf / gethostnames.sh
Created June 21, 2015 19:46
Get host names of any machines connected to my local network
#!/bin/bash
for i in $(seq 255);
do
nslookup 192.168.1.$(echo $i) 192.168.1.1 >/dev/null;
if [ $? -ne 1 ];
then
echo -n 192.168.1.$i;
nslookup 192.168.1.$(echo $i) 192.168.1.1|grep name|cut -d= -f2;
fi;
done
@msgodf
msgodf / gist:b108c0c79f5245fa3f30
Created July 8, 2015 09:27
Understanding how lists get destructured as maps in Clojure
;; @andrew_jones mentioned this from Miller and Vandgrift's Applied Clojure book
;; unusual how the varargs were being destructured as if they were a map
((fn [& opts] (let [{:keys [a b c]} opts] (str a b c))) :a 1 :b 2 :c 3);;=>"123"
;; opts is a list, not a vector
(let [{:keys [a b c]} '(:a 1 :b 2 :c 3)] (str a b c));;=>"123"
(let [{:keys [a b c]} [:a 1 :b 2 :c 3]] (str a b c));;""
(let [{:keys [a b c]} [[:a 1] [:b 2] [:c 3]]] (str a b c));""