This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> - 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
status = DATA.flock(File::LOCK_EX | File::LOCK_NB) | |
if status == 0 | |
puts "we have the lock..." | |
sleep | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Call git checkout | |
# | |
gco() | |
{ | |
git checkout $* | |
if [[ -s .rvmrc ]] ; then | |
unset rvm_rvmrc_cwd | |
cd . | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def initialize(name, age) | |
@name = name | |
@age = age | |
end | |
def set_name(new_name) | |
@name = new_name | |
end |
OlderNewer