Skip to content

Instantly share code, notes, and snippets.

View djui's full-sized avatar

Uwe Dauernheim djui

View GitHub Profile
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;
(ns io.djui.misc)
;; Use case example for tree-seq
(defn- map-traverse
"Traverse a map with vectors in values as branches and return a list of key
x's values. Example:
{:a nil :x {:foo 1} :b [{:c nil :x 42} \"test\"]} => [{:foo 1} 42]"
[map-tree x]
(let [map-vals #(when (map? %) (vals %))
branch? (comp (partial some sequential?) map-vals)
@djui
djui / redcarpet_without_pygments.rb
Last active December 17, 2015 01:38
Jekyll plugin to allow prism.js for markdown code blocks. Markdown parsing is done using redcarpet.
module Jekyll
class RedcarpetWithoutPygmentsParser < Converter
safe true
priority :high
def initialize(config)
require 'redcarpet'
@config = config
@redcarpet_extensions = {}
@djui
djui / gapmap.clj
Last active December 15, 2015 14:49
gapmap function for Clojure
(defn gapmap
"Returns a lazy sequence consisting of the result of applying f to all
adjacent values of coll. f should be a function of 2 arguments. If coll
contains less than 2 items, it is returned and f is not called."
{:added "1.6"}
([f coll]
(if-let [r (next coll)] ; at least two items?
(lazy-seq (gapmap-internal f (first coll) r))
coll)))
@djui
djui / 4clojure - 53
Last active December 15, 2015 04:50
#(second (reduce (fn [[t r] x]
(if (= (last t) (dec x))
[(conj t x) r]
(if (> (count t) (max 1 (count r)))
[[x] t]
[[x] r])))
[[] []] (conj % -1)))
@djui
djui / malcolm.zsh
Created November 3, 2012 20:32
malcolm - most amazing list comprehender of log messages
#!/bin/zsh
PRODUCT="malcolm"
PRODUCT_LONG="most amazing list comprehender of log messages"
VERSION=1.0.0
PORT=8080
VERBOSE=false
_usage() {
echo "Usage: $(basename $0) [-V|--version] [-v|--verbose] <command> [<args>]"
@djui
djui / ast.erl
Created October 1, 2012 20:58
create Erlang Modules
-define(A(A), erl_syntax:atom(A)).
-define(I(I), erl_syntax:integer(I)).
-define(S(S), erl_syntax:string(S)).
-define(V(V), erl_syntax:variable(V)).
s_f(N, P, B) -> erl_syntax:function(N, erl_syntax:clause(P, [], B)).
s_c(M, F, A) -> [erl_syntax:application(?A(M), ?A(F), [A])].
s_m(M) -> s_d(module, [?A(M)]).
@djui
djui / tmux-p0wn.sh
Created October 1, 2012 18:22
p0wn your tmux session
alias tmux-p0wn='tmux list-clients | sed "s|^\(/dev/ttys[0-9]\+\).*\[\([0-9]\+x[0-9]\+\).*$|\2 \1|" | sort -r -n | tail -n +2 | cut -d " " -f 2 | xargs -n 1 tmux detach-client -t'
@djui
djui / jira2branch.sh
Created August 29, 2012 20:52 — forked from andreineculau/jira2branch.sh
JIRA ticket to branch name
#!/bin/sh
case $(uname) in
"Linux") S=$(xclip -o);;
"Darwin") S=$(pbpaste -prefer txt);;
esac
python -c "
import sys,re;
F = sys.argv[2].split('\n');
@djui
djui / jira2branch.sh
Created August 29, 2012 20:52 — forked from andreineculau/jira2branch.sh
JIRA ticket to branch name
#!/bin/bash -e
# Usage # copy from browser "JIRA-205\nTicket title"
# $ jira2branch # echoes jira-205-ticket-title
# $ jira2branch team # echoes jira-205-team-ticket-title
OS=`uname`
function paste() {
if [ $OS == "Darwin" ]; then