Skip to content

Instantly share code, notes, and snippets.

Nebuta nebuta

  • Japan
Block or report user

Report or block nebuta

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nebuta
nebuta / webget.rb
Created Nov 8, 2011
Get google search result
View webget.rb
require 'net/http'
require 'cgi'
require 'rubygems'
require 'hpricot'
require 'open-uri'
require "resolv-replace"
require 'timeout'
BASE_URL = "http://www.google.com/search?"
LANG = "ja"
@nebuta
nebuta / webget.rb
Created Nov 8, 2011
Get google search result
View webget.rb
require 'net/http'
require 'cgi'
require 'rubygems'
require 'hpricot'
require 'open-uri'
require "resolv-replace"
require 'timeout'
BASE_URL = "http://www.google.com/search?"
LANG = "ja"
@nebuta
nebuta / aozoraget.rb
Created Nov 8, 2011
Get aozora bunko
View aozoraget.rb
#aozoraget.rb
require 'rubygems'
require 'hpricot'
require 'open-uri'
for i in 1..13
toc = "http://www.aozora.gr.jp/index_pages/sakuhin_a#{i}.html"
puts "Opening: " + toc
html = IO.read(toc)
@nebuta
nebuta / aozora.rb
Created Nov 8, 2011
Make a dictionary for ja encodings
View aozora.rb
require 'rubygems'
require 'hpricot'
require 'iconv'
$vector = Hash.new
$vector[:utf8] = Array.new(65536).fill(0)
$vector[:shiftjis] = Array.new(65536).fill(0)
$vector[:iso] = Array.new(65536).fill(0)
$vector[:eucjp] = Array.new(65536).fill(0)
@nebuta
nebuta / rfcascii.rb
Created Nov 8, 2011
Make a dictionary for ASCII
View rfcascii.rb
require 'rubygems'
require 'hpricot'
require 'iconv'
$vectorascii = Array.new(65536).fill(0)
$pwd = ""
def normalize
norm = 65536
@nebuta
nebuta / subtract.rb
Created Nov 8, 2011
Make dictionary data after subtraction of ASCII
View subtract.rb
#subtract.rb
def normalize
norm = 65536
$vector.each_key{|key|
sqsum = $vector[key].inject(0){|sum,e| sum += e*e}
p sqsum
factor = Math.sqrt(sqsum)
$vector[key].map!{|e| e.to_f * norm / factor}
}
@nebuta
nebuta / makecoursevectors.rb
Created Nov 8, 2011
Make dictionary data with lower resolution (=smaller size)
View makecoursevectors.rb
def normalize(v, norm)
ret = Hash.new
v.each_key{|key|
sqsum = v[key].inject(0){|sum,e| sum += e*e}
factor = Math.sqrt(sqsum)
ret[key] = v[key].map{|e| e.to_f * norm / factor}
}
ret
end
View encode_test.rb
require 'rubygems'
require 'hpricot'
$asciilist = (0x20..0x7e).to_a | [0x09,0x0a,0x0c,0x0d]
def parse(lines)
arr = Array.new(65536)
start = 0
lines.each{|line|
arr[start,256]=line.chomp.split("\t").map{|e| e.to_f}
@nebuta
nebuta / encode_test_1d.rb
Created Nov 8, 2011
Test algorithm with 1d dictionary
View encode_test_1d.rb
require 'rubygems'
require 'hpricot'
$asciilist = (0x20..0x7e).to_a | [0x09,0x0a,0x0c,0x0d]
def isAscii?(b)
$asciilist.include? b
end
def parse1d(lines)
@nebuta
nebuta / 2dto1d.rb
Created Nov 8, 2011
Make 1D dictionary
View 2dto1d.rb
#2dto1d.rb
def normalize(norm)
$vector.each_key{|key|
sqsum = $vector[key].inject(0){|sum,e| sum += e*e}
p sqsum
factor = Math.sqrt(sqsum)
$vector[key].map!{|e| e.to_f * norm / factor}
}
end
You can’t perform that action at this time.