This file contains hidden or 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
.gist{ | |
margin: 15px 0 !important; | |
} | |
.gist-file{ | |
border: none !important; | |
} | |
.gist-meta{ | |
border: 1px solid #d2d2d2 !important; |
This file contains hidden or 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
<settings> | |
<proxies> | |
<proxy> | |
<active>true</active> | |
<protocol>http</protocol> | |
<host>proxy.hoge.fuga.com</host> | |
<port>8080</port> | |
</proxy> | |
</proxies> | |
</settings> |
This file contains hidden or 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
;; 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)))) |
This file contains hidden or 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
;; FizzBuzz in Clojure | |
(defn fizzbuzz [max] | |
(map (fn [n] | |
(cond | |
(= (mod n 15) 0) "FizzBuzz" | |
(= (mod n 3) 0) "Fizz" | |
(= (mod n 5) 0) "Buzz" | |
:else n)) | |
(take max (iterate inc 1)))) |
This file contains hidden or 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
;; 何のひねりもない fibo | |
(defn fibo [x] | |
(if (or (= 0 x) (= 1 x)) | |
1 | |
(+ (fibo (- x 1)) (fibo (- x 2))))) | |
;; | |
(map #(fibo %) (take 10 (iterate inc 1))) | |
;; => (1 2 3 5 8 13 21 34 55 89) |
This file contains hidden or 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
# groovy client with no arguments (startup server) | |
bash$ groovyclient | |
Invoking server: 'groovyserver' -p 1961 | |
Groovy home directory: (none) | |
Groovy command path: /opt/local/bin/groovy (found at PATH) | |
GroovyServ home directory: /opt/local/share/devel/groovyserv | |
GroovyServ work directory: /Users/masao/.groovy/groovyserv | |
Original classpath: (none) | |
GroovyServ default classpath: /opt/local/share/devel/groovyserv/lib/* | |
Starting..... |
This file contains hidden or 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
;; mod を普通に使う | |
(defn gcd [m n] | |
(if (zero? n) m | |
(gcd n (mod m n)))) | |
(gcd 1763 1927) | |
; => 41 |
This file contains hidden or 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
irb(main):008:0> (1..10).each { |i| puts "This is sentence number #{i}" } | |
This is sentence number 1 | |
This is sentence number 2 | |
This is sentence number 3 | |
This is sentence number 4 | |
This is sentence number 5 | |
This is sentence number 6 | |
This is sentence number 7 | |
This is sentence number 8 | |
This is sentence number 9 |
This file contains hidden or 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
#!/usr/bin/env ruby | |
arr = (1..16).to_a | |
tmp = [] | |
arr.each do |val| | |
tmp.push(val) | |
if tmp.length == 4 | |
puts tmp.join(",") | |
tmp = [] | |
end | |
end |
This file contains hidden or 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
;;; | |
;;; 簡単 grep。のつもりが、あんまりかっこ良くないorz | |
;;; | |
(use '[clojure.java.io :as io]) | |
(defn indexed [coll] | |
(map vector (iterate inc 1) coll)) | |
(defn grep [re file] | |
(with-open [rdr (io/reader file)] |