Skip to content

Instantly share code, notes, and snippets.

@ponkore
ponkore / factorial-run.clj
Created March 25, 2012 12:09
Calculate factorial
;; calculate elapsed time
(defmacro tm [form]
`(let [t# (System/currentTimeMillis)]
(do
(~@form)
(- (System/currentTimeMillis) t#))))
;; call 4 version of fact-* 10 times x 5 loop
(dotimes [i 5]
(println "fact-call: " (tm (dotimes [n 10] (fact-call 10000))))
@ponkore
ponkore / settings.xml
Created March 24, 2012 12:01
.m2/settings.xml
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.hoge.fuga.com</host>
<port>8080</port>
</proxy>
</proxies>
</settings>
@ponkore
ponkore / gist:2134255
Created March 20, 2012 11:24
tumblr css customize v1
.gist{
margin: 15px 0 !important;
}
.gist-file{
border: none !important;
}
.gist-meta{
border: 1px solid #d2d2d2 !important;
@ponkore
ponkore / project.clj
Created March 16, 2012 04:30
Hello, Compojure #2+ (swank-clojure)
;; v2: "from Emacs 'M-x clojure-jack-in'"
(defproject compojure-example "1.0.0-SNAPSHOT"
:description "Simple compojure example project"
:dependencies [[org.clojure/clojure "1.3.0"]
[compojure "1.0.1"]]
:dev-dependencies [[lein-ring "0.5.0"] ; 0.6.1 では NG だった
[swank-clojure "1.3.4"]]) ; added
@ponkore
ponkore / gist:2047862
Created March 16, 2012 00:27
reverse sample implementation (for study) => test result
bash$ rlwrap clj
Clojure 1.3.0
user=> (reverse nil)
()
user=> (reverse [])
()
user=> (reverse ())
()
user=> (reverse '(0 1 2))
(2 1 0)
@ponkore
ponkore / reverse-sample.clj
Created March 16, 2012 00:18
reverse sample implementation (for study)
;;; reverse (not elegant)
(defn reverse-sample [coll]
(if (empty? coll) ()
(reduce #(cons %2 (if (seq? %1) %1 (list %1))) (seq coll))))
@ponkore
ponkore / core.clj
Created March 15, 2012 11:47
Hello, Compojure #2
(ns compojure-example.core
(:use compojure.core
ring.adapter.jetty ; <- added
[hiccup.middleware :only (wrap-base-url)])
(:require [compojure.route :as route]
[compojure.handler :as handler]))
(defn index-page [] "<H1>Hello, world</H1>")
(defroutes main-routes
@ponkore
ponkore / project.clj
Created March 15, 2012 11:01
Hello, Compojure #1
;; v1: "lein ring server"
(defproject compojure-example "1.0.0-SNAPSHOT"
:description "Simple compojure example project"
:dependencies [[org.clojure/clojure "1.3.0"]
[compojure "1.0.1"]]
:dev-dependencies [[lein-ring "0.5.0"]] ; 0.6.1 では NG だった
:ring {:handler compojure-example.core/app})
@ponkore
ponkore / core.clj
Created March 15, 2012 11:00
Hello, Compojure #1
(ns compojure-example.core
(:use compojure.core
[hiccup.middleware :only (wrap-base-url)])
(:require [compojure.route :as route]
[compojure.handler :as handler]))
(defn index-page [] "<H1>Hello, world</H1>")
(defroutes main-routes
(GET "/" [] (index-page))
@ponkore
ponkore / gist:2040698
Created March 15, 2012 00:29
Lexical Scope _and_ Dynamic Scope (Clojure version)
user=> (def x 7)
#'user/x
user=> (defn g [] x)
#'user/g
user=> (defn f [] (let [x 9] (g)))
#'user/f
user=> (f)
7
user=>