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 Enumerable | |
DEFAULT_PARALLEL = 8 | |
def parallel_each(num = DEFAULT_PARALLEL) | |
threads = [] | |
queue = Queue.new | |
num.times do | |
threads << Thread.new do | |
while (a = queue.pop) != 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
class UUID | |
def initialize | |
@timestamp = timestamp | |
@clockseq = clockseq | |
@node = node | |
end | |
def to_s | |
t = @timestamp | |
sprintf("%08x-%04x-%04x-%04x-%012x", t[0], t[1], t[2] | version, @clockseq | variant, @node) |
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
THREADS = 8 | |
THREAD_TIMEOUT = 180 | |
def xyield(q, &block) | |
t = Thread.new(Thread.current) do |u| | |
sleep THREAD_TIMEOUT | |
puts "-- timeout --" | |
u.raise | |
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
helpers do | |
include Rack::Utils | |
alias_method :h, :escape_html | |
alias_method :u, :escape | |
def partial(renderer, template, options = {}) | |
options = options.merge({:layout => false}) | |
template = "_#{template.to_s}".to_sym | |
m = method(renderer) | |
m.call(template, options) |
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 'mysql' | |
DB_DEFAULT_USER = 'root' | |
DB_DEFAULT_PASS = 'hogehoge' | |
DB_REFRESH = 60 * 60 # 1hour | |
MYSQL_INT_TYPES = [ | |
Mysql::Field::TYPE_TINY, Mysql::Field::TYPE_SHORT, | |
Mysql::Field::TYPE_LONG, Mysql::Field::TYPE_INT24, | |
Mysql::Field::TYPE_LONGLONG, Mysql::Field::TYPE_DECIMAL, |
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
<input type="checkbox" id="checkall" onchange=" | |
for (i = 0; i < document.f.elements.length; i++) { | |
if (document.f.elements[i].name == 'selected[]') { | |
document.f.elements[i].checked = document.getElementById('checkall').checked; | |
} | |
} | |
"> |
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
def gantt_start_compare(x, y) | |
def cmp(a, b) | |
if a != nil && b != nil | |
a <=> b | |
else | |
0 | |
end | |
end | |
def effective_date(x) |
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 PhpDataParser | |
def initialize(data_string) | |
@tokens = [] | |
lines = data_string.split("\n") | |
lines.each do |line| | |
line.gsub!(%r{//.*$}, '') | |
@tokens.concat(line.split(/\s+|(=>)/)) | |
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
def vectorize(msg) | |
vector = {} | |
words = msg.split(/\s+/) | |
words.each do |w| | |
h = w.hash | |
vector[h] = 1 if vector[h] == nil | |
vector[h] += 1 | |
end | |
vector | |
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
require 'dbus' | |
MYNAME = 'com.example.skype_api_client' | |
class SkypeAPI | |
def initialize(name = MYNAME) | |
bus = DBus.session_bus | |
service = bus.service("com.Skype.API") | |
objs = service.object("/com/Skype") | |
objs.introspect |
NewerOlder