Skip to content

Instantly share code, notes, and snippets.

@pochi
pochi / io_select_spec.rb
Created October 29, 2012 11:41
Sample IO.select
# coding: utf-8
require 'socket'
describe IO do
describe 'memo' do
before do
@test = nil
Thread.new { @test = "test" }.join
end
@pochi
pochi / fiber_spec.rb
Created October 26, 2012 00:39
Fiber sample
# coding: utf-8
require 'rspec'
require 'fiber'
describe 'FiberTest' do
let(:fiber) do
Fiber.new do |name|
last_name = Fiber.yield("#{name}")
"#{name} #{last_name}"
@pochi
pochi / fiber_spec.rb
Created October 25, 2012 12:21
Fiber sample
# coding: utf-8
require 'rspec'
require 'fiber'
describe 'FiberTest' do
let(:fiber) do
Fiber.new do |name|
last_name = Fiber.yield("#{name}")
puts "#{name} #{last_name}"
@pochi
pochi / MyException.java
Created August 13, 2012 00:41
Custom Java Exception
class MyException extends Exception {
public String errMsg;
MyException(String msg) { errMsg = msg; }
}
@pochi
pochi / gist:3312530
Created August 10, 2012 08:10
AR::has_many can use like 'scoped'
class User < AR::Base
has_many :birthday_events, ->(user) { where starts_on: user.birthday }, class_name: 'Event'
end
@pochi
pochi / gist:3312524
Created August 10, 2012 08:08
lambda sample
->(name) { puts "Pochi " + name }.call("garu")
# coding: utf-8
require "net/http"
require "uri"
def ping_pong(num)
loop do
puts "#{num.to_s}"
uri = URI.parse 'http://localhost:8080/waiting'
res = Net::HTTP.start(uri.host, uri.port).get(uri.path)
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
port = 8080
port = ARGV.shift.to_i if ARGV.size > 0
@@comet_timeout = 60
@@comet_timeout = ARGV.shift.to_i if ARGV.size > 0
# coding: utf-8
require "eventmachine"
require "em-http"
clients = 120
HOST = "localhost"
PORT = 4567
class Client < EM::Connection
require "eventmachine"
require "net/http"
clients = 100
HOST = "localhost"
PORT = 4567
class Client < EM::Connection
attr_accessor :client_id