Skip to content

Instantly share code, notes, and snippets.

View brainopia's full-sized avatar

Ravil Bayramgalin brainopia

View GitHub Profile
@deepak
deepak / gist:356517
Created April 5, 2010 16:08 — forked from tmm1/gist:61762
> - In ruby 1.8.x, what is the functional difference between rb_thread_schedule and rb_thread_select?
rb_thread_schedule() is the guts of the thread scheduler, it traverses
over the linked list of threads (several times) to find the next one
to switch into. The function is long (250 lines) and messy, and covers
all the combinations of thread status (RUNNABLE, TO_KILL, STOPPED,
KILLED) and wait state (FD, SELECT, TIME, JOIN, PID).
If there are no threads doing i/o or waiting on a timeout,
rb_thread_schedule() picks another thread from the list (considering
@frsyuki
frsyuki / example.rb
Created July 13, 2010 08:23
rev-websocket 5,000-connection benchmark
require 'rubygems'
require 'rev'
$LOAD_PATH << File.join(File.dirname(__FILE__),'lib')
require 'rev/websocket'
$connections = {}
class MyConnection < Rev::WebSocket
def on_open
$connections[self] = nil
@0x0dea
0x0dea / ova.rb
Created March 23, 2015 20:29
"Real" method overloading in Ruby!
module Ova
# autovivifying map from [class][method][signature] to Method
@@Ova = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
# Wrap #respond_to? for parity with Class#===.
Responder = Struct.new(:method) do
def === obj
obj.respond_to?(method)
end
end
#!/usr/bin/env ruby
=begin
INSTALL:
curl http://github.com/defunkt/gist/raw/master/gist.rb > gist &&
chmod 755 gist &&
sudo mv gist /usr/local/bin/gist
#! /usr/bin/env ruby
status = DATA.flock(File::LOCK_EX | File::LOCK_NB)
if status == 0
puts "we have the lock..."
sleep
else
@wayneeseguin
wayneeseguin / gist:849058
Created March 1, 2011 12:29
Git checkout function that triggers project .rvmrc to be reloaded
#
# Call git checkout
#
gco()
{
git checkout $*
if [[ -s .rvmrc ]] ; then
unset rvm_rvmrc_cwd
cd .
fi
@sstephenson
sstephenson / gist:921992
Created April 15, 2011 16:33
REE vs 1.9.2 for a small Rails 3 app
ree-1.8.7-2010.02
-----------------
units: Finished in 0.930402 seconds.
functionals: Finished in 12.241386 seconds.
integration: Finished in 1.648589 seconds.
rake 20.19s user 4.96s system 98% cpu 25.588 total
ruby-1.9.2p180
--------------
units: Finished in 1.504977 seconds.
Rehearsal -----------------------------------------------
instan_eval 0.258967 0.019441 0.278408 ( 0.485533)
bind.call 0.078391 0.003822 0.082213 ( 0.124251)
-------------------------------------- total: 0.360621sec
user system total real
instan_eval 0.259275 0.004492 0.263767 ( 0.309966)
bind.call 0.042689 0.000107 0.042796 ( 0.043009)
# a little wrapper on yaml/store to give collection and record access to a
# transaction yaml store.
#
# sample usage
#
# require 'ydb'
#
# db = Db.new
#
# collection = db.collection(:posts)
@rbxbx
rbxbx / 1_oo.rb
Created November 17, 2011 01:48
Bootstrapping a lightweight Object System in Ruby
class Person
def initialize(name, age)
@name = name
@age = age
end
def set_name(new_name)
@name = new_name
end