Skip to content

Instantly share code, notes, and snippets.

@mdemare
mdemare / SSH Tips
Created February 24, 2011 12:13
Good SSH tips
1) COPY SSH KEYS TO USER@HOST TO ENABLE PASSWORD-LESS SSH LOGINS. (NOT ON MAC)
ssh-copy-id user@host
To generate the keys use the command ssh-keygen
2) START A TUNNEL FROM SOME MACHINE’S PORT 80 TO YOUR LOCAL POST 2001
ssh -N -L2001:localhost:80 somemachine
;;; Number of arguments expected: 2 + 4, 3 + 8, 4 + 16
(defmacro multibool [& args]
(let [offset ({6 2, 11 3, 20 4} (count args))]
(assert offset)
`(condp = (+ ~@(map (fn [i] `(if ~(nth args i)
~(bit-shift-left 1 (- (dec offset) i))
0))
(range 0 offset)))
~@(reduce (fn [memo i] (into memo (list (nth args (+ 2 i)) i)))
'()
;variants of the code from point #2 of:
; http://www.tbray.org/ongoing/When/200x/2009/12/01/Clojure-Theses
;original
(apply merge-with +
(pmap count-lines
(partition-all *batch-size*
(line-seq (reader filename)))))
(multibool masculine plural "la" "le" "il" "la")
(defn multibool [& args]
(let [offset ({6 2, 11 3, 20 4} (count args))]
(if-not offset
(throw
(IllegalArgumentException.
"Illegal number of arguments (expected: 2 + 4, 3 + 8, 4 + 16)")))
(nth args
(+ offset
(reduce (fn [sum i] (+ sum (if (nth args i)
(bit-shift-left 1 (- (dec offset) i))
(({true {true "i" false "il"}
false {true "le" false "la"}}
masculine) plural)
(if (and masculine plural)
"i"
(if plural
"le"
(if masculine
"il"
"la")))
((comp
(partial reduce (fn [sum i] (+ sum i)) 0)
(partial filter #(= 1 (mod % 2)))
(partial map #(count (.split % " ")))
(partial remove #(re-find #"^#" %))
#(.split % "\n"))
text)
((comp
#(reduce (fn [sum i] (+ sum i)) 0 %)
(fn [s] (filter #(= 1 (mod % 2)) s))
(fn [s] (map #(count (.split % " ")) s))
(fn [s] (remove #(re-find #"^#" %) s))
#(.split % "\n"))
text)
(->> (.split text "\n")
(remove #(re-find #"^#" %))
(map #(count (.split % " ")))
(filter #(= 1 (mod % 2)))
(reduce (fn [sum i] (+ sum i)) 0))