Skip to content

Instantly share code, notes, and snippets.

@marekjelen
marekjelen / gist:1605378
Created January 13, 2012 10:04
Packages
desc 'Instal packages'
task :packages do
`apt-get install libmysqlclient-dev`
end
@marekjelen
marekjelen / gist:1876985
Created February 21, 2012 15:16
Pygments for Ruby (benchmark)
require 'pygmentize'
require 'pygments.rb'
code = <<EOF
require 'sinatra'
get '/hi' do
"Hello World!"
end
EOF
@marekjelen
marekjelen / gist:2030087
Created March 13, 2012 17:33
Server log
INFO: [id: 0x017b79a6, /127.8.59.129:25961 => /127.8.59.129:8080] OPEN
INFO: [id: 0x017b79a6, /127.8.59.129:25961 => /127.8.59.129:8080] BOUND: /127.8.59.129:8080
INFO: [id: 0x017b79a6, /127.8.59.129:25961 => /127.8.59.129:8080] CONNECTED: /127.8.59.129:25961
INFO: [id: 0x017b79a6, /127.8.59.129:25961 :> /127.8.59.129:8080] DISCONNECTED
INFO: [id: 0x017b79a6, /127.8.59.129:25961 :> /127.8.59.129:8080] UNBOUND
INFO: [id: 0x017b79a6, /127.8.59.129:25961 :> /127.8.59.129:8080] CLOSED
------------
INFO: [id: 0x0015cd9a, /127.8.59.129:15843 => /127.8.59.129:8080] OPEN
@marekjelen
marekjelen / gist:2037173
Created March 14, 2012 15:15
Netty in Torquebox error
16:02:03,470 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "web"
16:02:03,473 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "netty-3.3.0.Final.jar"
16:02:05,113 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.deployment.unit."netty-3.3.0.Final.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."netty-3.3.0.Final.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "netty-3.3.0.Final.jar"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at j
@marekjelen
marekjelen / gist:2250529
Created March 30, 2012 10:00
Container?
container = ScriptingContainer.new(LocalContextScope::THREADSAFE)
container.setAttribute(AttributeName::SHARING_VARIABLES, false)
container.setCompatVersion(CompatVersion::RUBY1_9)
# run_scriptlet("")
container.clear
container.finalize

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]