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
# アルゴリズム辞典 | |
# 島内剛一 野下浩平 伏見正則 有沢誠 浜田穂積 | |
# | |
# ディジタル探索 pp. 522-523 | |
require 'pp' | |
class Node | |
attr_accessor :key, :left, :right | |
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/ruby | |
# -*- encoding: utf-8 -*- | |
# | |
# アルゴリズム辞典 | |
# 島内剛一 野下浩平 伏見正則 有沢誠 浜田穂積 | |
# | |
# パトリシア pp. 624-625 |
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
#: coding: utf-8 | |
class Command | |
def initialize() | |
@command ||= {} | |
end | |
def register(name, cmd) | |
@command[name] = cmd | |
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
# -*- coding: utf-8 -*- | |
# cjheath/geoip https://github.com/cjheath/geoip | |
require 'geoip' | |
def build_hosts(hosts_file) | |
hosts ||= [] | |
lines = File.open(hosts_file).readlines() | |
lines.each{|line| |
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/ruby | |
# -*- encoding: utf-8 -*- | |
require 'uri' | |
require 'pp' | |
=begin | |
FreeStyleWiki 入門2 - A Guide to FreeStyle Wiki powered by FSWiki.com http://koitaro.fswiki.com/wiki/FreeStyleWiki+%C6%FE%CC%E72 |
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/ruby -Ku | |
require 'pp' | |
def ngram(gram = 2, text) | |
len = text.length - 1 | |
0.upto(len) {|i| | |
if i + gram > text.length | |
return | |
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/ruby -Ku | |
# ref. Ruby1.9でUTF-8の漢字だけ正規表現でヒットさせる - 屑プログラマの憂鬱 | |
# http://d.hatena.ne.jp/Artisan/20120826/1345990754]] | |
def ngram(gram = 2, text) | |
ngrams ||= [] | |
len = text.length - 1 | |
0.upto(len) {|i| | |
if i + gram > text.length |
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
#: coding: utf-8 | |
class Queue | |
def initialize(size) | |
@queue = Array.new(size) | |
@head = 0 | |
@tail = 0 | |
end | |
def get() |
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
#: coding: utf-8 | |
class Queue | |
def initialize() | |
@queue ||= [] | |
end | |
def get() | |
return nil if @queue.empty? | |
return @queue.shift() |
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
# coding: utf-8 | |
# hatenablog をスクレイピング | |
# | |
# 使い方: | |
# hatenablog.rb <hatenablog URI> [カテゴリ] | |
# | |
# 例: | |
# ruby hatenablog.rb http://jkondo.hatenablog.com/ > jkondo.txt | |
# |
OlderNewer