Skip to content
View pull_all.rb
Dir['*/'].each do |dir|
root = File.dirname __FILE__
cmd = "cd #{root}/#{dir} && git pull"
puts cmd
View index.html
<!DOCTYPE html>
<title>Capybara race condition with `text` matcher</title>
<script type="text/javascript" src="/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
View ruby_meta.rb
# Two great articles allow to understand Ruby better
class A; end
A.instance_eval { define_method(:hoge) { "hoge" } }
A.class_eval { define_method(:fuga) { "fuga" } }
A.instance_eval { def piyo ; "piyo"; end }
A.class_eval { def foo ; "foo"; end }
View build_tree.rb
# Got from:
def build_tree(i, edges)
list = {}
out_nodes = {|e| e[0] == i}.map {|e| e[1]}.uniq
out_nodes.each {|n| list[n] = build_tree(n, edges)}
edges = [[1,2],[1,6],[1,9],[2,3],[3,10],[4,7]]
View ews_ntml.rb
require 'ntlm/http'
require 'open-uri'
require 'net/https'
http =, 443)
http.use_ssl = true
http.verify_mode = OpenSSL:SSL::VERIFY_NONE
request ='/ews/Services.wsdl')
View persistent.rb
require 'net/http'
require 'net/http/faster'
require 'uri'
require 'cgi' # for escaping
require 'http_configuration'
# Persistent connections for Net::HTTP
# Net::HTTP::Persistent maintains persistent connections across all the
View chef-redeploy.txt
How to redeploy rails application in case of deployment went wrong.
rm /var/chef/cache/revision-deploys/app
rm file and the latest release directory.
View psych_check.rb
# encoding: utf-8
require 'erb'
require 'psych'
require 'yaml'
puts YAML # => 'psych'
Dir.glob('**/*.yml').map do |file|
puts file
Psych.load( file) unless file =~ /cucumber/
$sudo apt-get update
#notice line like: "The following signatures were invalid: BADSIG 40976EAF437D05B5 Ubuntu Archive.."
#install public key above
$sudo apt-key adv --recv-key --keyserver 40976EAF437D05B5
#thanks to:
View string_distace.rb
def distance(str1, str2)
pairs1 = (0..str1.length-2).collect {|i| str1[i,2]}.reject {
|pair| pair.include? " "}
pairs2 = (0..str2.length-2).collect {|i| str2[i,2]}.reject {
|pair| pair.include? " "}
union = pairs1.size + pairs2.size
intersection = 0
pairs1.each do |p1|
Something went wrong with that request. Please try again.