Skip to content

Instantly share code, notes, and snippets.

@yuanmai
yuanmai / agent-examples.clj
Created March 5, 2012 01:15
Agent Examples
(def x (agent 0))
@x ; 0
(send x inc)
@x ; 1
(send x + 10)
@x ; 11
@yuanmai
yuanmai / refactoring.clj
Created March 5, 2012 16:03
Clojure refactoring powered by core.logic
(clojure.core.logic/unifier '[(+ ?x 1) (inc ?x)] '[(+ a 1) ?refactored])
;[(+ a 1) (inc a)]
@yuanmai
yuanmai / GIT Global Config
Created March 27, 2012 03:12 — forked from corbanb-snippets/GIT: Global Config
git globals and alias
# http://gitready.com/intermediate/2009/02/06/helpful-command-aliases.html
git config --global alias.rb rebase
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.co checkout
git config --global alias.df df
git config --global alias.lg log -p
public static float distFrom(float lat1, float lng1, float lat2, float lng2) {
double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
;; from http://www.learningclojure.com/2010/09/astonishing-macro-of-narayan-singhal.html
(defmacro def-let
"like let, but binds the expressions globally."
[bindings & more]
(let [let-expr (macroexpand `(let ~bindings))
names-values (partition 2 (second let-expr))
defs (map #(cons 'def %) names-values)]
(concat (list 'do) defs more)))
;; from http://blog.gaz-jones.com/2012/02/04/debug_let.html
(def long-list (into (repeat 10000 0) [9 9 9 9 9]))
(dotimes [_ 10]
(time
(dotimes [_ 1000]
(sort long-list)
)))
@yuanmai
yuanmai / gist:2613118
Created May 6, 2012 04:32
web site perf
ab -n 5000 -c 50 http://localhost:8080/
[MBProgressHUD showHUDAddedTo:[self.view.window.subviews objectAtIndex:0] animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
// Do something...
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:[self.view.window.subviews objectAtIndex:0] animated:YES];
});
});
[MBProgressHUD HUDForView: [UIApplication sharedApplication].keyWindow]
@yuanmai
yuanmai / simplifier.clj
Created May 9, 2012 14:00 — forked from ck/simplifier.clj
A Simplifier for all Expressions
;; A Simplifier for all Expressions
;; Example:
;; (simplify '(* 1 (+ x (- y y)))) ;=> x
;; (simplify '(and a (and (and) b))) ;=> (and a b)
;; See section 4.4, "Syntactic Abstraction" of Norvig and Pitman's
;; "Tutorial on Good Lisp Programming Style":
;; http://norvig.com/luv-slides.ps
@yuanmai
yuanmai / .Xmodmap
Created May 16, 2012 10:06
XQuartz settings
clear Mod1
clear Mod2
keycode 66 = Meta_L
keycode 69 = Meta_R
keycode 63 = Alt_L
keycode 71 = Alt_R
add Mod1 = Alt_L Alt_R
add Mod2 = Meta_L Meta_R