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
pid = Process.pid | |
SimpleCov.at_exit do | |
SimpleCov.result.format! if Process.pid == pid | |
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
module MyModule | |
def pid | |
"MyModule.pid" | |
end | |
end | |
module ExtendModule | |
def pid | |
"ExtendModule.pid" | |
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
class Thread | |
def self.try_handle_interrupt *args | |
if respond_to?(:handle_interrupt) | |
self.handle_interrupt(*args){ yield } | |
else | |
yield | |
end | |
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
LIMIT = {} | |
def limit n | |
key = [caller,Thread.current] | |
LIMIT[key] ||= n | |
LIMIT[key] -= 1 | |
n = LIMIT[key] | |
if n > 0 | |
n | |
else | |
LIMIT.delete key |
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
#include <sys/types.h> | |
#include <sys/wait.h> | |
#include <ruby.h> | |
/* include/ruby/ruby.h */ | |
#ifndef IDTYPET2NUM | |
#define IDTYPET2NUM(v) INT2FIX(v) | |
#endif | |
#ifndef NUM2IDTYPET | |
#define NUM2IDTYPET(v) FIX2INT(v) |
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 Process | |
class ProcessError < StandardError; end | |
class Process | |
attr_reader :pid | |
def initialize(*args, &block) | |
raise ArgumentError.new("block must be given") unless block_given? |
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 Module | |
def wrap_package_private name | |
wraped_method = instance_method(name) | |
define_method(name) do |*args| | |
# check | |
puts "checking package_private: #{name}" | |
if true | |
e = NoMethodError.new("package private method is called from outside of the package") | |
e.set_backtrace caller |
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
s=%(s=%(X);s.sub!('X',s);puts s);s.sub!('X',s);puts s |
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 'socket' | |
require 'thread' | |
query = <<QUERY | |
M-SEARCH * HTTP/1.1 | |
HOST: 239.255.255.250:1900 | |
MAN: "ssdp:discover" | |
MX: 3 | |
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1 | |
QUERY |
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
# usage: ruby compress.rb icon.gif > myicon.rb | |
bit = 15 | |
data = File.open(ARGV[0]){|f| f.read } | |
encoded_data = nil | |
offset = 0 | |
bit_str = data.unpack("B*")[0] | |
(0x0000..0xffff).each do |i| |