Skip to content

Instantly share code, notes, and snippets.

@manutter51
manutter51 / MyList.ex
Created July 26, 2013 16:58
Decided to do one of the exercises from _Programming Elixir_, section 7.5. "Write max(list) that returns the element with the maximum value in the list (This is slightly trickier than it sounds.)" I've got both the max value and the (1-based) index of the max value. My First Elixir Code (aw)!
defmodule MyList do
def mymax([h | t]), do: mymax(h, t)
def mymax(v, []), do: v
def mymax(v, [h | t]) when h < v, do: mymax(v, t)
def mymax(_v, [h | t]), do: mymax(h, t)
@manutter51
manutter51 / snippets.sh
Created July 29, 2013 17:48
bash snippets
#!/bin/bash
alias reload="source ~/.bashrc"
# source the sublimerc file if it exists
if [ -f "${HOME}/.sublimerc" ] ; then
source "${HOME}/.sublimerc"
fi
src()
@manutter51
manutter51 / RsyncUpload
Last active August 29, 2015 13:56
Rsync upload with delete
rsync -azP --delete --exclude-from=.gitignore <src> <dest>
@manutter51
manutter51 / lazy-outer-inner-seq.clj
Last active October 25, 2018 13:45
Hand-rolled lazy seq for pairing inner values to outer keys in a map nested 1 layer deep with other maps.
(def mm {1 {101 :a 102 :b 103 :c} 2 {201 :aa 202 :bb}})
;; possible cases
;; fully populated {1 {11 :a, 12 :b}, 2 {21 :a, 22 :b}}
;; single inner value {1 {12 :b}, 2 {21 :a, 22 b}}
;; empty inner value, multi-entry outer {1 {}, 2 {21 :a, 22 :b}}
;; other degenerate cases that boil down to either "the first key-value pair has data to process" or "We're done."
(defn outer-inners