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 String | |
def reindent(to, tabwidth=nil) | |
indenter = (tabwidth ? " "*tabwidth : "\t")*to | |
initial = self[/\A[\t ]*/] | |
gsub(/^(?:#{initial})?/, indenter) | |
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
$ ruby cgi.rb | |
(offline mode: enter name=value pairs on standard input) | |
sprache=java | |
Content-Type: text/html | |
Content-Length: 14 | |
code ist java | |
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
/* | |
$Id: strscan.c 11708 2007-02-12 23:01:19Z shyouhei $ | |
Copyright (c) 1999-2006 Minero Aoki | |
This program is free software. | |
You can distribute/modify this program under the terms of | |
the Ruby License. For details, see the file COPYING. | |
*/ | |
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 time matters | |
module CallInspectable | |
def self.included(by) | |
inherited_methods = by.public_instance_methods-by.public_instance_methods(false) | |
inherited_methods.sort.each { |name| | |
class_eval("def #{name}(*args); $stderr.puts \"Called '#{name}' in #{by}\"; super; 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
module CallInspectable | |
def intercept_all_calls(&block) | |
all_methods = superclass.public_instance_methods | |
m = Module.new do | |
all_methods.each { |method_name| | |
define_method(method_name) do |*args| | |
block.call(method_name) | |
super | |
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
SELECT cv.* FROM candidate_versions AS cv JOIN ( | |
SELECT lower_bound.candidate_id, MIN(lower_bound.updated_at) AS lower_updated_at, MAX(upper_bound.updated_at) AS upper_updated_at FROM ( | |
SELECT MAX(updated_at) as updated_at, candidate_id FROM candidate_versions WHERE updated_at <= '2009-01-01' GROUP BY candidate_id | |
UNION ALL | |
SELECT MIN(updated_at) as updated_at, candidate_id FROM candidate_versions WHERE updated_at BETWEEN '2009-01-01' AND '2010-01-01' GROUP BY candidate_id | |
) AS lower_bound JOIN ( | |
SELECT MAX(updated_at) as updated_at, candidate_id FROM candidate_versions WHERE updated_at <= '2010-01-01' GROUP BY candidate_id | |
) AS upper_bound ON lower_bound.candidate_id=upper_bound.candidate_id | |
WHERE lower_bound.candidate_id < 10020 | |
GROUP BY lower_bound.candidate_id |
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
#!/usr/bin/env ruby | |
require 'optparse' | |
utf8 = true | |
colors = false | |
opts = OptionParser.new("", 24, ' ') do |opts| | |
opts.banner = "Usage: #{$PROGRAM_NAME} [options] [directory]" |
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
FileString now lives in its own repository at http://github.com/apeiros/filestring |
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 Object | |
def chain_method(with_symbol, &new_method) | |
old_method = method with_symbol | |
eigenclass = class << self; self; end | |
eigenclass.class_eval do | |
define_method with_symbol do |*args| new_method[old_method, *args] end | |
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
$ time ruby1.8 bits.rb 16 > /dev/null | |
real 0m9.861s | |
user 0m8.977s | |
sys 0m0.872s | |
$ time ruby1.9 bits.rb 16 > /dev/null | |
real 0m1.742s | |
user 0m1.740s |