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
rails professional_urls | |
cd professional_urls | |
for x in asp php exe jsp cgi; do script/generate controller $x index default home show edit; done | |
echo 'ActionController::Routing::Routes.draw { |map| map.connect ":action.:controller" }' > config/routes.rb | |
echo '<pre><%= h params.to_yaml %></pre>' > app/views/asp/default.html.erb | |
script/server & | |
open http://localhost:3000/default.asp?pgx=LF&ixFilter=1 | |
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
For each Ruby module/class, we have Ruby methods on the left and the equivalent | |
Clojure functions and/or relevant notes are on the right. | |
For clojure functions, symbols indicate existing method definitions, in the | |
clojure namespace if none is explicitly given. clojure.contrib.*/* functions can | |
be obtained from http://github.com/kevinoneill/clojure-contrib/tree/master, | |
ruby-to-clojure.*/* functions can be obtained from the source files in this | |
gist. | |
If no method symbol is given, we use the following notation: |
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
(:verb0 :arrive | |
(subject_tags :animal :persona :human :organization) | |
(en "arrive") | |
(es "llegar" "¿Cómo va a llegar el niño hasta aquí?") | |
(nl "aan-komen" :zijn true) | |
(de "an-kommen" :sein true) | |
(fr "arriver" "Ils furent *arrivés* dans le hall d'entrée." :etre true) | |
(it "arrivare" :essere true) | |
) |
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
def dameraulevenshtein(seq1, seq2) | |
oneago = nil | |
thisrow = (1..seq2.size).to_a + [0] | |
seq1.size.times do |x| | |
twoago, oneago, thisrow = oneago, thisrow, [0] * seq2.size + [x + 1] | |
seq2.size.times do |y| | |
delcost = oneago[y] + 1 | |
addcost = thisrow[y - 1] + 1 | |
subcost = oneago[y - 1] + ((seq1[x] != seq2[y]) ? 1 : 0) | |
thisrow[y] = [delcost, addcost, subcost].min |
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.contrib.pprint) | |
(defn assert-equal [expected actual] | |
(if (not= expected actual) | |
(throw | |
(AssertionError. | |
(str "\nExpected\n" | |
(with-out-str (pprint expected)) | |
"\ngot\n" | |
(with-out-str (pprint actual))))))) |
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
;; original | |
(defn left-s [s length] | |
(subs s 0 (if (< length 0) (+ length (count s)) length))) | |
;; generates assert-equal everytime it's called | |
(defn left-s [s length] | |
(let [rvalue | |
(subs s 0 (if (< length 0) (+ length (count s)) length))] | |
(println "\n(assert-equal" (pr-str rvalue) "(left-s" (pr-str s) length "))") | |
rvalue)) |
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
clj MyApp.clj | grep assert | sort | uniq > MyAppTest.clj |
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
text.split("\n"). | |
reject {|l| l =~ /^#/}. | |
map {|l| l.split.size }. | |
select {|l| l.odd? }. | |
inject(0) {|sum,i| sum+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
(reduce | |
(fn [sum i] (+ sum i)) | |
0 | |
(filter #(= 1 (mod % 2)) | |
(map | |
#(count (.split % " ")) | |
(remove | |
#(re-find #"^#" %) | |
(.split text "\n"))))) |
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
(let [x (.split text "\n") | |
x (remove #(re-find #"^#" %) x) | |
x (map #(count (.split % " ")) x) | |
x (filter #(= 1 (mod % 2)) x) | |
x (reduce (fn [sum i] (+ sum i)) 0 x)] | |
x) |
OlderNewer