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 -*- | |
require 'rinda/tuplespace' | |
require 'drb/drb' | |
require 'webrick' | |
require 'webrick/cgi' | |
class RichRinda < WEBrick::CGI | |
def initialize(ts, *args) | |
super(*args) | |
@ts = ts |
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
class Merge | |
def initialize(*fnames) | |
@file = fnames.collect {|fn| MergeFile.new(fn)} | |
delete_empty | |
end | |
def delete_empty | |
@file.delete_if {|f| f.empty?} | |
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
module Enumerable | |
def merge(*other) | |
return to_enum(__method__, *other) unless block_given? | |
inputs = [self, *other] | |
while ! inputs.keep_if {|it| it.peek rescue nil}.empty? | |
yield(inputs.min_by {|it| it.peek}.next) | |
end | |
end | |
def split_for_shuffle(n = 1000000) |
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
drb.rb | |
#!/usr/local/bin/ruby | |
=begin | |
Tiny distributed Ruby --- dRuby | |
DRb --- dRuby module. | |
DRbProtocol --- Mixin class. | |
DRbObject --- dRuby remote object. | |
DRbConn --- | |
DRbServer --- dRuby message handler. | |
=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
module ERBWithHash | |
class HashAsBinding < BasicObject | |
def initialize(hash) | |
@_env = hash | |
end | |
def method_missing(msg, *args, &block) | |
super if block | |
super unless args.empty? | |
@_env.fetch(msg) { @_env.fetch(msg.to_s) { super }} |
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 -*- | |
require 'test/unit' | |
class TriApp | |
def on_OK(t1, t2, t3) | |
n1 = positive_integer(t1) | |
n2 = positive_integer(t2) | |
n3 = positive_integer(t3) | |
return "三角形ではありません" unless triangle?(n1, n2, n3) | |
case [n1, n2, n3].uniq.size |
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
require 'av_capture' | |
require 'drb' | |
class PhotoServer | |
attr_reader :worker | |
def initialize | |
@worker = Queue.new | |
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
class ChannelSpace | |
class ChannelHandle | |
def initialize(ts, size) | |
@ts = ts | |
@size = size | |
@name = Object.new | |
@ts.write([@name, 0, []]) | |
end | |
def write(value) |
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 -*- | |
require 'rinda/tuplespace' | |
module Channel | |
class ChannelSpace | |
class Any | |
def initialize(ary) | |
@ary = ary | |
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
require 'rinda/tuplespace' | |
class ChannelSpace | |
include DRbUndumped | |
class ChannelError < RuntimeError | |
def initialize(str, handle) | |
@channel = handle | |
super(str) | |
end |