Skip to content

Instantly share code, notes, and snippets.

class String
def reindent(to, tabwidth=nil)
indenter = (tabwidth ? " "*tabwidth : "\t")*to
initial = self[/\A[\t ]*/]
gsub(/^(?:#{initial})?/, indenter)
end
end
$ ruby cgi.rb
(offline mode: enter name=value pairs on standard input)
sprache=java
Content-Type: text/html
Content-Length: 14
code ist java
/*
$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.
*/
# 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
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
}
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
#!/usr/bin/env ruby
require 'optparse'
utf8 = true
colors = false
opts = OptionParser.new("", 24, ' ') do |opts|
opts.banner = "Usage: #{$PROGRAM_NAME} [options] [directory]"
@apeiros
apeiros / gist:229001
Created November 8, 2009 00:54
Treat a File like a String
FileString now lives in its own repository at http://github.com/apeiros/filestring
@apeiros
apeiros / gist:234189
Created November 13, 2009 21:36 — forked from dwt/gist:234180
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
@apeiros
apeiros / FIGHT!.txt
Created December 11, 2009 07:51 — forked from epitron/FIGHT!.txt
$ 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