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 'net/http' | |
require 'uri' | |
# Restore original url from the url made from some url shortening services. | |
# | |
# Currently tested: | |
# bit.ly(j.mp), ustre.am, tinyurl | |
class URLExtractor | |
def self.expand_url(short_url) |
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 BubbleValue | |
def initialize(hash, key, timeout = 3) | |
@hash = hash | |
@key = key | |
Thread.new { | |
sleep timeout | |
@hash[@key] = nil | |
} | |
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
# sis2lite.rb | |
class RepoRep | |
def initialize() | |
@repomap = {} | |
end | |
def save_state(group, members, writable, readonly) | |
a_members = members.strip.split(/\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
# encoding: utf-8 | |
require 'open-uri' | |
require 'yaml' | |
require 'rubygems' | |
require 'nokogiri' | |
class LangsBuilder | |
def dump_langs(writer_or_file) | |
if writer_or_file.is_a? String |
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 'net/http' | |
require 'uri' | |
require 'json' | |
class Dozens | |
API_BASE = 'http://dozens.jp/api/' | |
ZONE_BASE = API_BASE + 'zone' | |
RECORD_BASE = API_BASE + 'record' |
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
Mac OS X 10.6.6 において | |
rvm install 1.9.2-p180 | |
で readline.c がエラーになったので、 | |
rvm package install readline | |
をやって |
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 Integer | |
def to_cs(numcol = 3) | |
unit = 10 ** numcol | |
reps = '\d' * numcol | |
neg = false | |
str = self.to_s | |
if self <= -unit | |
neg = true | |
str = (-self).to_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
var SCRIPT_NAME = 'my_name.js'; | |
function getScriptPath(target) { | |
var list = document.getElementsByTagName("script"); | |
var i = list.length; | |
while (i--) { | |
var src = list[i].src; | |
if (src) { | |
var result = src.match(/^(.*)([^\/]+\.js)$/); | |
if (result) { | |
if (result[2] == SCRIPT_NAME) { |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>cx.pow.firewall</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>sh</string> | |
<string>-c</string> |
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
# pathable_hash.rb | |
# Add Hash#path method to lookup deep stuructured hash value. | |
# e.g) | |
# h0 = {a: {b: {c: 1}}} | |
# h0.path '/a/b/c' => 1 | |
# h0.path 'a/b/c' => 1 # heading slash has no meaning. | |
# h1 = {a: {b: [1,2,{c: 3}]} | |
# h1.path '/a/b[2]/c' => 3 # [\d] means picking up array item. | |
# path syntax is inspired by xpath, but not same. :-) |