Doge log

Abby CTO 雑賀 力王のオフィシャルサイトです

Ruby

続Ruby libevent

テストをちょっと書いてみたら色々おかしかった。 githubに置いておこう。 GitHub - mopemope/rbevent: ruby extension library for libevent

Ruby libevent

rubyでlibeventを使うライブラリを書いてみた。 通常のeventも合わせてテスト全然してないお。 環境はruby1.9。1.8でも動くかな。 #include "ruby.h" #include <stdio.h> #include <sys/time.h> #include <event.h> VALUE mRubyEvent, mRubyEventConst, rb_cEvent, rb_cSignalEvent, rb_cTi</event.h></sys/time.h></stdio.h>…

heapq

標準でないのかな??? なのでpythonから引っ張ってくる。 Arrayに突っ込む。 class Array def heappush(item) self.push(item) siftdown(0, self.length - 1) end def heappop lastelt = self.pop() if self.length > 0 returnitem = self[0] self[0] = la…

bisect, bsearch

pythonから引っ張ってくる class Array def insert_right(item, lo=0, hi=nil) if lo < 0 raise IndexError.new('lo must be non-negative') end if hi == nil hi = self.length end while lo < hi mid = ((lo+hi)/2).truncate if item < self[mid] hi = mid…

RubyInline

RubyInlineを使うとCを埋め込めるらしいので試してみた。 $:.unshift File.dirname(__FILE__) require 'rubygems' require 'inline' VERSION = '0.0.1' class KQueue inline do |builder| builder.include "<sys/event.h>" builder.include "<sys/time.h>" builder.include "<unistd.h>" builder</unistd.h></sys/time.h></sys/event.h>…

Fiberメモ

require 'fiber' def io_switch f = Fiber.current $h.add_watch(:f, proc{ $h.remove_watch(:f) f.transfer }) $h.switch end class Hub def initialize @process @wait = Hash.new end def add_watch(key,block) @wait[key] = block end def remove_watch(…