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 'pp' | |
class Middleware | |
def initialize(app) | |
@app = app | |
puts "=-=-=- Initializing #{self.class}" | |
pp app | |
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 'thread' | |
class Enumerator | |
def in_threads(threads=4, &block) | |
queue = Queue.new | |
each { |*args| queue << args } | |
threads.times.collect do | |
Thread.new { block.call(*queue.pop) until queue.empty? } |
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
PubSub::Session#initialize(publisher_thread_limit=5, subscriber_thread_limit=5) | |
PubSub::Session#queue | |
PubSub::Session#publish(message) # Pull a thread from the publisher thread pool and in it, create a new Publisher instance and then push to the queue with it | |
PubSub::Session#wait # # Pull a thread from the subscriber thread pool and in it, create a new Subscriber instance and then pop from the queue with it, then perform the subscribers #on_message | |
PubSub::Session#publishers | |
PubSub::Session#subscribers | |
PubSub::Publisher#initialize(session) | |
PubSub::Publisher#session | |
PubSub::Publisher#publish(message) |
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
RyBookPro:Desktop ryguy$ ./slop_iterm_example | |
{:terminal=>"iTerm", :help=>nil} | |
RyBookPro:Desktop ryguy$ ./slop_iterm_example --help | |
Usage: slop_iterm_example [options] | |
-t, --terminal Terminal to use. (default: iTerm) | |
-h, --help Display this help message. | |
RyBookPro:Desktop ryguy$ ./slop_iterm_example --terminal=MyTerm | |
{:terminal=>"MyTerm", :help=>nil} | |
RyBookPro:Desktop ryguy$ ./slop_iterm_example --terminal MyTerm | |
{:terminal=>"MyTerm", :help=>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
[-242942.0, 137291.5, -94339.6015625, 720213.25, 618422.9375, -484450.5625, -458720.3125, -711049.875, 449504.1875, -1770862.5, 2975486.0, 207335.796875, 215908.3125, 11305.52734375, 62522.6484375, 127898.765625, 664322.75, -269724.96875, 402957.0625, -97711.53125, -196356.75, 492522.9375, -429303.78125, 90851.3046875, 97209.375, -414716.15625, 151576.921875, 105870.46875, 26088.39453125, 138286.4375, 153877.59375, -2632.970703125, 28394.94140625, 75804.0546875, -990.9619140625, -88740.53125, -47794.9609375, -24309.380859375, 101186.3125, 11203.7890625, 20218.685546875, -193312.03125, 130143.8359375, -9540.03125, -18865.931640625, 37143.68359375, -83075.015625, -67459.65625, 44172.6640625, 130646.609375, 50461.34375, 33891.34375, 70996.8359375, 17823.6171875, 35496.921875, 48788.984375, -2605.65625, 69496.2265625, 104941.34375, 27142.48828125, 59214.484375, 9483.03125, 74139.125, -78937.625, -9227.671875, 103007.53125, 21385.90625, 12472.0625, -1495.0625, 5286.8125, 14058.15234375, 919.9375, -78964.703125, -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
require 'rubygems' | |
require 'benchmark' | |
require 'rulebook' | |
class Foo | |
[:admin, :blah].each do |role| | |
define_method "is_#{role}?" do | |
true | |
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 DSL | |
def initialize(*args, &blk); call(*args, &blk); end | |
def call(*args, &blk); instance_exec(*args, &blk); end | |
end | |
class Klass | |
def foo | |
print 'foo' | |
DSL.new do | |
def bar |
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
Needs two 7-segment displays and a target finder. | |
Wire the 1 [ENT] to the chips 'Player' link and the 7-segments accordingly | |
----------------------------------------------------------------------------- | |
@name Speedometer | |
@inputs Player:entity | |
@outputs A1 B1 C1 D1 E1 F1 G1 A2 B2 C2 D2 E2 F2 G2 Speed FirstNum SecondNum |
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 Foo | |
def subject(&blk) | |
if block_given? | |
blk.call(@subject) # How do I pass by reference and not by value here? | |
else | |
@subject | |
end | |
end | |
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
test 'An Array containing numbers' do | |
p subject #=> <Subject @name='' @object=nil> | |
subject 'An Array' do | |
subject ['one', 'two', 'three'] | |
subject.pop | |
end | |
p subject #=> <Subject @name='An Array' @object=['one', 'two']> | |
end |
OlderNewer