Skip to content

Instantly share code, notes, and snippets.

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
@mdemare
mdemare / index.txt
Created December 12, 2008 06:09 — forked from mmcgrana/index.txt
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:
(: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)
)
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
(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)))))))
;; 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))
clj MyApp.clj | grep assert | sort | uniq > MyAppTest.clj
text.split("\n").
reject {|l| l =~ /^#/}.
map {|l| l.split.size }.
select {|l| l.odd? }.
inject(0) {|sum,i| sum+i }
(reduce
(fn [sum i] (+ sum i))
0
(filter #(= 1 (mod % 2))
(map
#(count (.split % " "))
(remove
#(re-find #"^#" %)
(.split text "\n")))))
(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)