Skip to content

Instantly share code, notes, and snippets.

Bill Caputo logosity

Block or report user

Report or block logosity

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@logosity
logosity / wait-any.clj
Created Aug 9, 2013
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):
View wait-any.clj
;;; 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
View immutability_and_safety_2.js
//"safe" version:
function listFruits(fs) {
var fruits = [].concat(fs);
fruits.sort();
for(var i in fruits) {
console.log(fruits[i]);
}
}
View immutability_and_safety.clj
(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!!
View immutability_and_safety.js
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 Jan 15, 2013
toggle screen saver on and off on an xwindows-using linux machine (tested only on Ubuntu)
View monitors.sh
#!/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 Jan 15, 2013
Run git commands in all sub directories of current directory.
View gita.sh
#!/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
Tail Recursion in bash
View tail.sh
#!/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 Apr 27, 2012
Get this code running and you'll have everything you need...
View learn_clojure.clj
(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 Mar 22, 2012
print out current stack in clojure
View print-stack.clj
;;; 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#)))
You can’t perform that action at this time.