Skip to content

Instantly share code, notes, and snippets.

Project

Student implements a framework for building asynchronous (event-driven) network applications that will be compatible with all major Ruby implementations - JRuby, MRI, Rubinius. The framework will support multiple networking adapters and provide compatibility layer for EventMachine based applications.

Problem

There are many ways to implement asynchronous applications using low-level libraries - nio4r, java nio, netty, libuv and others. The challenge is to choose the right one and be able to switch it based on a deployment model.

Solution

@marekjelen
marekjelen / gist:2272749
Created April 1, 2012 07:35
Loader & Sinatra
Dead ;)
uninitialized constant Rack::Protection
org/jruby/RubyModule.java:2642:in `const_missing'
/Users/marek/.rbenv/versions/jruby-1.6.7/lib/ruby/gems/1.8/gems/rack-protection-1.2.0/lib/rack/protection.rb:23:in `new'
org/jruby/RubyBasicObject.java:1730:in `instance_eval'
/Users/marek/.rbenv/versions/jruby-1.6.7/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
/Users/marek/.rbenv/versions/jruby-1.6.7/lib/ruby/gems/1.8/gems/rack-protection-1.2.0/lib/rack/protection.rb:22:in `new'
/Users/marek/.rbenv/versions/jruby-1.6.7/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb:82:in `use'
require 'socket'
s = TCPSocket.new ENV['OPENSHIFT_INTERNAL_IP'], 8080
while l = s.gets
puts l
end
s.close
@marekjelen
marekjelen / config.ru
Created April 1, 2012 15:30
Simple Sinatra
require 'sinatra/base'
class Application < Sinatra::Base
get '/' do
'Hello from Sinatra'
end
end
[1186, 3128, 3306, 3528, 3529, 4447, 4712, 4713, 5432, 5445, 5455, 7600, 8118, 8123, 8255, 8389, 8787, 9123, 9352, 9353, 9374, 9472, 9923, 9926, 9949, 9950, 9990, 9996, 9999, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009, 10010, 10715, 10716, 10717, 14170, 14171, 14248, 15000-35530, 60417, 63132-63164]
#!/bin/env ruby
require 'erb'
result = ERB.new(File.read(File.expand_path('../nginx.template', __FILE__))).result(binding)
File.open(File.join(ENV['OPENSHIFT_TMP_DIR'], 'env', 'conf', 'nginx.conf'), 'w') do |file|
file.write(result)
end
@marekjelen
marekjelen / gist:2693521
Created May 14, 2012 11:42
POM with Rubygems
<repositories>
<repository>
<id>rubygems-proxy</id>
<name>Rubygems Proxy</name>
<url>http://rubygems-proxy.torquebox.org/releases</url>
<layout>default</layout>
</repository>
</repositories>
@marekjelen
marekjelen / nginx.erb
Created May 24, 2012 12:42
Nginx configuration for Ruby @ OpenShift
# ==== .openshift/action_hooks/start
cd ${OPENSHIFT_DATA_DIR}
ENV=${OPENSHIFT_DATA_DIR}env
PATH=$ENV/bin:$PATH
if [ ! -d "$ENV" ]; then
mkdir $ENV
@marekjelen
marekjelen / gist:2786454
Created May 25, 2012 07:45
On using ERB
require 'erb'
i = 5
template = ERB.new('<%= i %>')
template.result(binding)
# => "5"
@marekjelen
marekjelen / example.yml
Created June 30, 2012 17:05
Presentation demos automator
- description: Provide a description of command you need to run and have it run
command: sleep 1; echo "a"; sleep 2; echo "b"
clear: true
- description: And when the program failes, you will be notified
command: exit 1