Skip to content

Instantly share code, notes, and snippets.

View brainopia's full-sized avatar

Ravil Bayramgalin brainopia

View GitHub Profile
@tmm1
tmm1 / fbr.rb
Created August 8, 2008 22:16
Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8) [http://github.com/tmm1/fiber18/tree/master]
# Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
# (c) 2008 Aman Gupta (tmm1)
unless defined? Fiber
require 'thread'
class FiberError < StandardError; end
class Fiber
def initialize
@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
#!/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
@igrigorik
igrigorik / webapp.rb
Created November 13, 2010 21:28
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
#! /usr/bin/env ruby
status = DATA.flock(File::LOCK_EX | File::LOCK_NB)
if status == 0
puts "we have the lock..."
sleep
else
@ahoward
ahoward / net-http-debug.rb
Created December 10, 2010 20:06
a simple way to debug tons of libs that use ruby's net/http
BEGIN {
require 'net/http'
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
@blister
blister / gist:740829
Created December 14, 2010 18:19
Bash script to add a delay to the localhost interface on Linux machines
#!/bin/bash
# Copyright 2010 Eric Ryan Harrison <me@ericharrison.info>
# Inspired by:
# http://daniel.haxx.se/blog/2010/12/14/add-latency-to-localhost/
if [ -n "$1" ]
then
if [ "$1" = "off" ]
then
tc qdisc del dev lo root
@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
@balupton
balupton / ajaxify-html4.js
Created March 7, 2011 04:58
Ajaxify a Website using the HTML4 HashChange Functionality
(function(window,undefined){
// Prepare our Variables
var
document = window.document,
$ = window.jQuery;
// Wait for Document
$(window).bind(function(){
// Prepare Variables