Skip to content

Instantly share code, notes, and snippets.

@toretore
toretore / h.rb
Last active August 29, 2015 13:56
class Foo
attr_reader :v
def initialize(v)
@v = v
end
def hash
v.hash
end
def eql?(o)
puts "Foo#eql? called"
class Storefront < ActiveRecord::Base
extend WebsiteValidation
validates_website :website
end
@toretore
toretore / mtool.rb
Last active August 29, 2015 13:57 — forked from Aeon/mtool.rb
require 'api/pools.rb'
module Mtool
extend Blather::DSL
#Blather.logger.level = Logger::DEBUG
Blather.logger.level = Logger::INFO
@@faye = nil
#!/usr/bin/env ruby
require 'socket'
require 'thread'
threads = Array.new
ports = [*(1..1024)]
mutex = Mutex.new
20.times do
require 'socket'
require 'fiber'
#A list of readables and writables for IO.select, and which fiber is waiting for which IO
watch = {
readable: {}, #{io => fiber}
writable: {}
}
class Library
attr_accessor :games
def each
games.each do |game|
yield game
end
end
end
class Server
def call(env)
req = Request.new('http://www.example.com/')
headers = nil
req.on_headers{|h| headers = h }
req.start
sleep 0.1 until headers
[200, headers, Enumerator.new(streamer, :on_body)]
end
require 'thread'
queues = Array.new(10){ Queue.new }
list_of_hosts.each_slice(10).map{|s| s.each_with_index{|h,i| queues[i] << h } }
threads = 10.times.map do |i|
Thread.new do
while host = queues[i].pop
check host
# /^(\d{2}\/\d{2}) (.*) (\-?\d+\.\d+)/
File.open ARGV[0], 'r' do |file|
file.each_line do |line|
if m = line.match(/^(\d{2}\/\d{2}) (.*) (\-?\d+\.\d+)/)
puts [m[1], m[2], m[3]].join(', ')
end
end
@toretore
toretore / act.rb
Last active August 29, 2015 14:18 — forked from mikecmpbll/act.rb
w_r, w_w = IO.pipe
t_r, t_w = IO.pipe
work = Thread.new { block.call; w_w.write('.') }
timeout = Thread.new{ sleep 10; t_w.write('.') }
io = IO.select [w_r, t_r]
if io == t_r
#Timeout