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
# simple fiber pool for EM::Synchrony (or same) | |
class FiberPool | |
def initialize(count) | |
@queue = EM::Queue.new | |
@count = count | |
count.times do | |
fib = Fiber.new do | |
fiber_loop(fib) | |
end | |
fib.resume |
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
diff --git a/common.mk b/common.mk | |
index eb89a2b..59cdfe4 100644 | |
--- a/common.mk | |
+++ b/common.mk | |
@@ -630,7 +630,8 @@ file.$(OBJEXT): {$(VPATH)}file.c $(RUBY_H_INCLUDES) {$(VPATH)}io.h \ | |
gc.$(OBJEXT): {$(VPATH)}gc.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h \ | |
{$(VPATH)}regex.h $(ENCODING_H_INCLUDES) $(VM_CORE_H_INCLUDES) \ | |
{$(VPATH)}gc.h {$(VPATH)}io.h {$(VPATH)}eval_intern.h {$(VPATH)}util.h \ | |
- {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h | |
+ {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h \ |
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
echo 1 > /sys/block/sd#/device/delete |
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 BitSet | |
def initialize | |
@bm = {} | |
end | |
def set(i) | |
n = i >> 4 | |
@bm[n] = @bm[n].to_i | (1 << (i & 0xF)) | |
end | |
def test(i) | |
@bm[i/16].to_i[i & 0xF] != 0 |
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
# This notebook is on Atom N270 1.33GHz, so that I use only 500000 iterations | |
~/tmp/ruby$ ruby test_queue.rb 500000 | |
Rehearsal ------------------------------------------------------------- | |
pure man queue 2 0.570000 0.000000 0.570000 ( 0.574775) | |
pure man queue 4 0.550000 0.000000 0.550000 ( 0.557201) | |
pure man queue 15 0.600000 0.000000 0.600000 ( 0.599789) | |
pure man queue 16 1.620000 0.000000 1.620000 ( 1.615062) | |
pure man queue 48 1.720000 0.000000 1.720000 ( 1.729971) | |
pure man queue 128 2.130000 0.000000 2.130000 ( 2.136135) | |
pure ruby smart queue 4 1.170000 0.000000 1.170000 ( 1.166562) |
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 'eventmachine' | |
EM.run do | |
i = 0 | |
myloop = ->{ | |
puts i | |
i += 1 | |
EM.next_tick(myloop) | |
} | |
EM.next_tick(myloop) |
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 'eventmachine' | |
require 'fiber' | |
module EM | |
module Synchrony | |
class Mutex | |
def initialize | |
@waiters = [] | |
end | |
def lock |
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 Enumerator | |
class Error < Struct.new(:error) | |
end | |
def feed(v) | |
@feed = v | |
end | |
class StopIteration < ::StopIteration | |
attr :result | |
def initialize(msg, result) | |
super(msg) |
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 | |
require 'yaml' | |
y=[] | |
(1..10000).each{|x| | |
#next unless x/2==(1.0*x)/2 | |
z=x | |
divisors=[1] | |
_continue=true |
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
export NGINX_DIR=../nginx | |
export LOG_DIR=$NGINX_DIR/log | |
export SOCK_DIR=$NGINX_DIR/socks | |
export APP=`basename "$(realpath "$(dirname "$0")")"` | |
PID_FILE=$SOCK_DIR/$APP.pid | |
if [ -e "$PID_FILE" ] ; then | |
PID=`cat $PID_FILE` | |
if [ -n `ps aux | awk '/rainbows/ && /$PID/ && !/awk/ {print $0}'` ] ; then | |
echo "Action: " $@ |