This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; here's how to reload a single namespace: | |
; (use 'some-namespace-name :reload) | |
; here's a function that will reload all that match "ns-part": | |
(defn reload-all [ns-part] | |
(map #(use % :reload) (filter #(re-find (re-pattern ns-part) (str%)) (loaded-libs)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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#))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//"safe" version: | |
function listFruits(fs) { | |
var fruits = [].concat(fs); | |
fruits.sort(); | |
for(var i in fruits) { | |
console.log(fruits[i]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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 |
OlderNewer