Skip to content

Instantly share code, notes, and snippets.

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
class Library
attr_accessor :games
def each
games.each do |game|
yield game
end
end
end
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: {}
}
#!/usr/bin/env ruby
require 'socket'
require 'thread'
threads = Array.new
ports = [*(1..1024)]
mutex = Mutex.new
20.times do
@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
class Storefront < ActiveRecord::Base
extend WebsiteValidation
validates_website :website
end
@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"
@toretore
toretore / HOWTO.md
Last active December 26, 2015 03:09

Here's a quick introduction to how to get the best help in #rubyonrails (or any other programming medium). There are competent people who want to help you, but if you follow a few pointers you will make it much easier for them to do so and will get answers to your question much faster.

1. Show us your code

This is the most critical part. You absolutely must show us the code you're having problems with. It is incredibly important that you show us the relevant code. Trying to figure out a programming problem without code is like trying to fix a car without a car.

Use Gist to paste your code. Do not paste your code directly in the channel. Do not use Pastebin. Read this handy guide to learn how to use Gist properly.

Again, just to make sure you understand how incredibly important it is, you must show us your code, no way around it.

@toretore
toretore / README.md
Last active December 19, 2015 10:49
Rails 0MQ logger

These files work together to extract useful data from a Rails application and publish it through a ZeroMQ PUSH socket as JSON.

The code in application_controller.rb will automatically log every request and exception, but you're free to log other things. If you're inside a controller, you can use log_message(atts) or emit_event(atts). These controller methods simply delegate to the global object $ZMQ_LOGGER, which responds to log(atts) and emit(atts). They add the data.http.request-id key if not already present.

The difference between logging and emitting is somewhat blurry, but I like to think of log messages as something that will be saved somewhere and emitted events as ephemeral.

All attributes are expected to use strings as keys. If you use symbols, you may experience issues.

You may use these files as you wish, with one exception: You may not package them into a reusable library and publish it. This is not easily reusable code, and any attempt to make it into a pre-packaged library will result

@toretore
toretore / foo.sh
Last active December 18, 2015 04:18
Installing ruby-build, ruby, unicorn, bundling and running a rails app on a server
#sudo as necessary
#First, install ruby-build to /opt/ruby-build
git clone git://github.com/sstephenson/ruby-build.git /opt/ruby-build
#it's a good idea to make sure you have these installed before compiling ruby
#apt-get install libssl-dev libreadline6-dev zlib1g-dev
#All ruby installations/versions are going to live in /opt/rubies
mkdir /opt/rubies