Skip to content

Instantly share code, notes, and snippets.

@apeiros
apeiros / car.rb
Created August 28, 2008 08:04 — forked from mlangenberg/car.rb
module Lib
def has_color
define_method(:color) do 'red' end
end
end
class Car
extend Lib
has_color
end
class String
def segments
segments = split(/\./)
while segments.size > 1
yield(segments.join('.'))
segments.pop
end
yield('.')
end
end
#!/usr/bin/env ruby
# hackery to simulate a file
require 'stringio'
RealFile = File
Object.send(:remove_const, :File)
File = StringIO
def StringIO.open(data); x=new(data);x.rewind; x; end
# end of hackery
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]"