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
| class String | |
| def self.levenshtein(a, b) | |
| case | |
| when a.empty?: b.length | |
| when b.empty?: a.length | |
| else [(a[0] == b[0] ? 0 : 1) + levenshtein(a[1..-1], b[1..-1]), | |
| 1 + levenshtein(a[1..-1], b), | |
| 1 + levenshtein(a, b[1..-1])].min | |
| 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
| int i=0; | |
| unsigned int mc = 0; | |
| Method* mlist = class_copyMethodList([MKMapView class], &mc); | |
| NSLog(@"%d methods", mc); | |
| for(i=0;i<mc;i++) | |
| NSLog(@"Method no #%d: %s", i, sel_getName(method_getName(mlist[i]))); |
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
| (defn fetch [address f] | |
| (with-open [rdr (BufferedInputStream. (.openStream (URL. address)))] | |
| (with-open [wtr (FileOutputStream. (file-str f))] | |
| (copy rdr wtr)))) |
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
| import org.apache.commons.lang.NotImplementedException; | |
| import org.apache.hadoop.conf.Configuration; | |
| import org.apache.hadoop.fs.*; | |
| import org.apache.hadoop.fs.permission.FsPermission; | |
| import org.apache.hadoop.util.Progressable; | |
| import java.io.BufferedInputStream; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.net.URI; | |
| import java.net.URL; |
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
| (defn- exponential-smooth-recur | |
| [current v factor] | |
| (if (empty? v) | |
| (rest current) | |
| (letfn [(smooth | |
| [y m] | |
| (+ (* (- 1 factor) m) (* factor y)))] | |
| (recur (conj current (smooth (first v) (last current))) (rest v) factor)))) | |
| (defn exponential-smooth |
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
| (defn exponential-smooth-recur | |
| [x f] | |
| (letfn [(smoothed-val [m n f] | |
| (+ | |
| (* m (- 1 f)) | |
| (* n f)))] | |
| (reverse (lazy-seq | |
| (loop [observed (rest x) smoothed (list (first x))] | |
| (if (empty? observed) | |
| smoothed |
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
| (use '(clojure.contrib sql)) | |
| (def db { | |
| :classname "org.apache.hadoop.hive.jdbc.HiveDriver" | |
| :subprotocol "hive" | |
| :subname "//hive-server:10000/default" | |
| :user "" | |
| :password ""}) | |
| (try |
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
| require "rubygems" | |
| require "mandy" | |
| Mandy.job "Word Count" do | |
| map_tasks 5 | |
| reduce_tasks 3 | |
| map do |line| | |
| line.split(' ').each do |word| | |
| word.downcase! |
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
| require "rubygems" | |
| require "mandy" | |
| Mandy.job "Word count" do | |
| map do |line| | |
| # code here | |
| 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
| describe "Word Count" do | |
| before(:all) do | |
| job_name = "Word Count" | |
| @runner = Mandy::TestRunner.new(job_name) | |
| end | |
| describe "mapper" do | |
| it "splits on spaces and emits words" do | |
| @runner.map("Fake carl") do |mapper| | |
| mapper.should_receive(:emit).with('fake', 1) |
OlderNewer