Skip to content

Instantly share code, notes, and snippets.

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@logosity
logosity / wait-any.clj
Created August 9, 2013 20:09
Block a caller on any number of long-running/non-terminating functions continuing when any one of them returns (the others will run to completion, or presumably get cleaned up by the calling context):
;;; block caller until any one of the passed functions complets and return its result
(defn wait-any [& fns]
(let [p (promise)]
(doseq [f fns] (future (deliver p (f))))
(deref p)))
;;; (wait-any #(do (Thread/sleep 4000) 1) #(do (Thread/sleep 2000) 2) #(do (Thread/sleep 3000) 3))
;;; output: 2
//"safe" version:
function listFruits(fs) {
var fruits = [].concat(fs);
fruits.sort();
for(var i in fruits) {
console.log(fruits[i]);
}
}
(defn listFruits [fruits]
(doall (map println (sort fruits))))
(def fruits ["Banana", "Orange", "Apple", "Mango"])
(listFruits fruits) ;prints Apple Banana Mango Orange each on their own line
(println fruits) ;["Banana" "Orange" "Apple" "Mango"] yay!!
function listFruits(fs) {
fs.sort();
for(var i in fs) {
console.log(fs[i]);
}
}
var fruits = ["Banana", "Orange", "Apple", "Mango"];
listFruits(fruits); //prints Apple Banana Mango Orange each on their own line
console.log(fruits); //["Apple", "Banana", "Mango", "Orange"] ouch!!
@logosity
logosity / monitors.sh
Created January 15, 2013 20:43
toggle screen saver on and off on an xwindows-using linux machine (tested only on Ubuntu)
#!/bin/bash
case "$1" in
on)
/usr/bin/xset -display :0.0 dpms force on
/usr/bin/xset -display :0.0 -dpms
/usr/bin/xset -display :0.0 s off
/usr/bin/xset -display :0.0 s reset
;;
off)
@logosity
logosity / gita.sh
Created January 15, 2013 20:38
Run git commands in all sub directories of current directory.
#!/bin/bash
find_command="find . -mindepth 0 -maxdepth 1 -type d -print"
git_command="git $*"
for i in $($find_command | sort)
do
[ -d $i/.git ] && echo ${i:2}: $(cd $i; $git_command 2> /dev/null)
done
@logosity
logosity / tail.sh
Created May 9, 2012 20:33
Tail Recursion in bash
#!/bin/bash
# warning you need to build in something to stop the loop
# in practice, I used a kill file check before invoking the script again
echo 'tail recursive bash ftw'
sleep 10
$0 &
# if you didn't listen and ran this as-is, try:
# killall tail.sh
@logosity
logosity / learn_clojure.clj
Created April 27, 2012 20:56
Get this code running and you'll have everything you need...
(use '[clojure.string :only (join)])
(use '[clojure.data.json :only (read-json)])
(defmacro google [& terms]
`(map :url
(get-in (read-json (slurp (str "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="
~(join \+ (map str terms))))) [:responseData :results])))
(google learning clojure)
(google learning clojure eclipse)
@logosity
logosity / print-stack.clj
Created March 22, 2012 15:26
print out current stack in clojure
;;; print out the stack at the point of invocation of the macro (and continue execution)
;;;
(defmacro print-stack []
`(doseq [s# (.getStackTrace (Thread/currentThread))]
(println s#)))