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
#!/usr/bin/env io | |
File standardInput contents split(" ") map(fromBase(16) asCharacter) prepend("" asMutable) reduce(appendSeq) println |
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
#!/usr/bin/env io | |
Matrix := Object clone do( | |
with := method(row, column, | |
self clone do( | |
row ::= 0 | |
column ::= 0 | |
) setRow(row) setColumn(column) do( | |
data := list() preallocateToSize(size) | |
size repeat(data push(nil)) |
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
#!/bin/sh | |
# download Postgres app at http://postgresapp.com/ and put it in /Applications folder and rename it to Postgres.app | |
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config |
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
#!/usr/bin/env io | |
// finding minimum of a loop ascending sequence | |
findmin := method(seq, | |
left := 0 | |
right := seq size -1 | |
loop( | |
leftValue := seq at(left) |
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
#!/usr/bin/env ruby | |
require 'JSON' | |
class Point | |
attr_reader :x,:y | |
def initialize(x,y) | |
@x = x | |
@y = y | |
end |
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
#!/usr/bin/env io | |
Number isNarcissistic := method(base, | |
base ifNil(base = 10) | |
digits := self toBase(base) asList map(fromBase(base)) | |
self == digits map(** digits size) sum | |
) | |
# print the narcissistic number in range [0, 1000] (decimal) | |
Range 0 to(1000) asList select(isNarcissistic) println |
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
#!/usr/bin/env io | |
kNN := method(inX, dataSet, k, | |
dataSet map(x, list(x first, x second distanceTo(inX))) \ | |
sortBy(block(a, b, a second < b second)) setSize(k) map(first) \ | |
uniqueCount sortBy(block(a, b, a second > b second)) first first | |
) | |
dataSet := list( | |
list("A", vector(1, 1.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
#!/usr/bin/env io | |
# calculate the information gain(entropy) by Claude Shannon | |
# input like list("a", "b", "a", "c", ...) | |
List shannonEntroy := method( | |
self uniqueCount map(last / self size) map(p, p * (- p log2)) sum | |
) | |
# => 0.97.... |
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
#!/usr/bin/env io | |
# naive bayes classification | |
# 性别 身高(英尺) 体重(磅) 脚掌(英寸) | |
## M 6 180 12 | |
## M 5.92 190 11 | |
## M 5.58 170 12 | |
## M 5.92 165 10 | |
## F 5 100 6 |
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
#!/usr/bin/env ruby | |
require 'nokogiri' | |
require 'open-uri' | |
require 'json' | |
def get_doc(url, localfile) | |
filename = File.exists?(localfile) ? localfile : url | |
Nokogiri::HTML(open(filename)) | |
end |
OlderNewer