Skip to content

Instantly share code, notes, and snippets.

@timvisher
timvisher / gist:842388
Created February 24, 2011 16:29
browse-url-ie
(defun browse-url-ie ()
"Browse url with ie"
(interactive)
(let ((browse-url-generic-program "iexplore"))
(call-interactively 'browse-url-generic)))
(dolist (variable '("PATH" "EMACSPATH"))
(setenv variable
(concat (getenv "HOME") "/bin:"
(getenv "HOME") "/.gem/ruby/1.8/bin:"
"/usr/local/bin:"
(getenv "PATH"))))
(defn do-copy-tree [from to include-globs]
(let [globs-pattern (globs->pattern include-globs)
src-paths (map fs/normpath (filter #(re-matches globs-pattern (.getName %)) (file-seq (io/as-file from))))
from (fs/normpath from)
to (fs/normpath to)
dest-paths (map #(.replaceFirst % from to) src-paths)]
(doall (map fs/copy+ src-paths dest-paths))))
@timvisher
timvisher / gist:860251
Created March 8, 2011 13:14
Problematic Square-Root Definition
user=> (defn good-guess? [guess number]
(< (Math/abs (- (* guess guess) number)) 0.0001))
#'user/good-guess?
user=> (defn improve-guess [guess number]
(average guess (/ number guess)))
#'user/improve-guess
user=> (improve-guess 4 9)
25/8
user=> (good-guess? 25/8 9)
java.lang.IllegalArgumentException: No matching method found: abs (NO_SOURCE_FILE:0)
@timvisher
timvisher / gist:860666
Created March 8, 2011 18:02
First Pass at a Template System in Clojure
(defn do-apply-snippets []
(let [snippet-paths (tree-paths "snippets")
snippet-keywords (map keyword (map #(.concat ":" %) (map #(.substring % 0 (.lastIndexOf % ".")) (map fs/basename snippet-paths))))
snippet-contents (map slurp (map clojure.java.io/as-file snippet-paths))
snippets (zipmap snippet-keywords snippet-contents)
html-files (map as-file (tree-paths target #{".html"}))
html-file-line-seqs (map #(with-open [rdr (clojure.java.io/reader %)] (doall (line-seq rdr))) html-files)
snippeted-html-file-line-seqs
(map
@timvisher
timvisher / gist:864408
Created March 10, 2011 16:30
Broken clj implementation
#!/bin/sh
# Runs clojure.
# With no arguments, runs Clojure's REPL.
# resolve links - $0 may be a softlink
CLOJURE=$CLASSPATH:$(brew --cellar)/clojure/1.2.0/clojure.jar:$(brew --cellar)/clojure-contrib/1.2.0/clojure-contrib.jar
java -cp $CLOJURE clojure.main "$@"
@timvisher
timvisher / gist:864818
Created March 10, 2011 20:08
Lazy, Infinite Square Root Function
;;Implement using infinite sequences
(require ['clojure.contrib.math :as 'math])
(defn average [x y] (/ (+ x y) 2))
(defn improve-guess [[guess number]]
[(average guess (/ number guess)) number])
(defn good-guess? [[guess number]]
(< (math/abs (- (* guess guess) number)) 0.0001))
@timvisher
timvisher / gist:897991
Created April 1, 2011 10:49
Set an asynchronous timed event in applescript
set backOnAt to (current date) + 60
set turnOn to "/Users/tim/Library/Scripts/timeMachineOn.scpt"
tell application "iCal"
tell calendar "Scheduled Scripts"
delete events
set turnBackOn to ¬
make new event with properties ¬
{start date:backOnAt}
tell turnBackOn
@timvisher
timvisher / gist:945068
Created April 27, 2011 20:08
Run commands that should need to be run from project root.
(defun cradle-run (args)
(interactive "MRun Cradle with args: ")
(let ((current-directory default-directory)
(cradle-home (locate-dominating-file default-directory "build.clj")))
(progn
(cd cradle-home)
(shell-command (concat "cradle " args))
(cd current-directory))))
(defun cradle-deploy ()