View logging.rb
require 'logger'
require 'fileutils'
require 'time'
require 'fiber'
module Logging
class Logger
View lb.rb
require 'thread'
state = {time: Time.now, status: "Flux Capacitor running"}
messages = Queue.new
class TimeChange
attr_reader :time
def initialize(t)
@time = t
end
View chrome_sockets_link.rb
View chrome_sockets.rb
require 'socket'
def log(s)
puts "#{Time.now.strftime('%H:%M:%S')}: #{s}"
end
server = TCPServer.new('', 1337)
loop do
socket = server.accept
View t.rb
require 'thread'
class WorkerPool
def initialize
@num = 10
@jobs = Queue.new
@results = Queue.new
@stopped = false
View now.rb
PIPELINE = %w[booked collected ironed delivered]
def state
PIPELINE[@pipeline_position]
end
def advance
@pipeline_position += 1
end
View sockets.rb
require 'socket'
server1 = TCPServer.new('0.0.0.0', 1337)
server2 = TCPServer.new('0.0.0.0', 1338)
servers = [server1, server2]
clients = []
loop do
readables, * = IO.select(servers+clients)
View s.rb
require 'socket'
class Page
attr_reader :body, :method, :path
def initialize(m, p, b)
@body, @method, @path = b, m, p
end
end
class Server
View flatten.rb
module Fluent
class TextParser
class StringifiedValuesJSONParser < JSONParser
Plugin.register_parser("stringified_values_json", self)
def parse(text)
time, record = super(text)
# replace all Hash (like a dict) values with stringified JSON
record = record.inject({}) { | new_hash, (key, value) |
View waiter.rb
class Waiter
def initialize
@m, @cv = Mutex.new, ConditionVariable.new
@signalled = false
end
def wait
@m.synchronize{ @cv.wait(@m) until @signalled; @signalled = false }
end
def signal
@m.synchronize{ @signalled = true; @cv.signal }