Skip to content

Instantly share code, notes, and snippets.

#Keeps a list of registered names associated with classes at a "base" class
#Example:
#
# class Base
# extend Registerable
# end
#
# class Foo < Base
# register :foo
# end
module Kernel
def recurse(*a, &b)
send(caller(1).first[/`(.*?)'\Z/, 1], *a, &b)
end
end
class Foo
def bar(stop=false)
module ApplicationHelper
def labelled_form_for(*attrs, &proc)
options = attrs.last.is_a?(Hash) ? attrs.pop : {}
object = attrs.pop
options.reverse_merge!(
:builder => LabellingFormBuilder
)
# Norwegian, norsk bokmål, by irb.no
"no":
support:
array:
sentence_connector: "og"
date:
formats:
default: "%d.%m.%Y"
short: "%e. %b"
long: "%e. %B %Y"
require 'open3'
Open3.popen3 'bash' do |stdin, stdout, stderr, wait|
t=Thread.new{ stdout.each{|l| print l } }
stdin.puts 'ls'
stdin.puts 'exit'
wait.join
t.join
end
class GetData
@@logger = Logger.new('log.log')
def initialize
@yesterday = Date.today.prev_day
@token = xxx
end
def save_actions
with_database do |db|
@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
# /^(\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
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
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