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
def Maybe(obj) | |
Maybe.new(obj) | |
end | |
class Nothing | |
include Singleton | |
end | |
class Maybe | |
attr_reader :value |
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
>> sudo dpkg -i libmagic1_5.11-1_amd64.deb libmagic-dev_5.11-1_amd64.deb file_5.11-1_amd64.deb | |
[sudo] password for rupert: | |
(Odczytywanie bazy danych ... 291117 files and directories currently installed.) | |
Przygotowanie do zastąpienia libmagic1 5.04-5ubuntu2 (wykorzystując libmagic1_5.11-1_amd64.deb) ... | |
Rozpakowanie pakietu zastępującego libmagic1 ... | |
Przygotowanie do zastąpienia libmagic-dev 5.04-5ubuntu2 (wykorzystując libmagic-dev_5.11-1_amd64.deb) ... | |
Rozpakowanie pakietu zastępującego libmagic-dev ... | |
Przygotowanie do zastąpienia file 5.04-5ubuntu2 (wykorzystując file_5.11-1_amd64.deb) ... | |
Rozpakowanie pakietu zastępującego file ... | |
Konfigurowanie libmagic1 (5.11-1) ... |
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
module EventMachine | |
TestTimeoutExceededError = Class.new(RuntimeError) | |
module TestHelper | |
def self.included(cls) | |
cls.class_eval(<<-HERE_DOC, __FILE__, __LINE__) | |
DefaultTimeout = nil unless const_defined?(:DefaultTimeout) | |
def self.default_timeout(timeout) |
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
>> ncat 127.0.0.1 3456 | |
auth | |
a3863a5aa8afe5eaf1ccfa6738172305 | |
message from a3863a5aa8afe5eaf1ccfa6738172305 |
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 TestUser | |
def is_ok? | |
true | |
end | |
def receive_message | |
yield("message", self) | |
end | |
def &(other) |
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
jobs = [] | |
jobs << Fiber.new{ 2.times{|i| puts "working on part #{i}"; Fiber.yield(i) }; :finished } | |
jobs << Fiber.new{ 4.times{|i| puts "doing part #{i}"; Fiber.yield(i) }; :finished } | |
jobs << Fiber.new{ 3.times{|i| puts "making part #{i}"; Fiber.yield(i) }; :finished } | |
until jobs.empty? | |
job = jobs.shift | |
result = job.resume | |
jobs << job if result != :finished | |
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
results = [] | |
f1 = Fiber.new do | |
i = 1 | |
loop do | |
i+= 1 | |
if Prime.prime?(i) | |
results << i | |
Fiber.yield(i) | |
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
> require 'prime' | |
> f1 = Fiber.new{ i = 1; loop{ i+= 1; Fiber.yield(i) if Prime.prime?(i) } } | |
> f2 = Fiber.new{ i = 1; loop{ i+= 1; Fiber.yield(i**2) } } | |
> 4.times do | |
> puts f1.resume + f2.resume | |
> end | |
6 | |
12 | |
21 | |
32 |
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
ruby-1.9.2-p180-fastrequire :057 > f1 = Fiber.new{ i = 1; loop{ i+= 1; Fiber.yield(i) if Prime.prime?(i) } } | |
=> #<Fiber:0x0000000234a150> | |
ruby-1.9.2-p180-fastrequire :058 > f2 = Fiber.new{ i = 1; loop{ i+= 1; Fiber.yield(i**2) } } | |
=> #<Fiber:0x00000002329c48> | |
ruby-1.9.2-p180-fastrequire :060 > 4.times do | |
ruby-1.9.2-p180-fastrequire :061 > puts f1.resume + f2.resume | |
ruby-1.9.2-p180-fastrequire :062?> end | |
6 | |
12 | |
21 |
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
> f1 = Fiber.new{ loop{ Fiber.yield rand() } } | |
> f2 = Fiber.new{ ary = [true, false]; loop{ Fiber.yield(ary.sample) } } | |
> f1.resume | |
=> 0.39994797202857346 | |
> f2.resume | |
=> false | |
> f2.resume | |
=> false | |
> f1.resume | |
=> 0.9078216956199455 |