Skip to content

Instantly share code, notes, and snippets.

Stefan Rusterholz apeiros

Block or report user

Report or block apeiros

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View car.rb
module Lib
def has_color
define_method(:color) do 'red' end
end
end
class Car
extend Lib
has_color
end
View gist:15036
class String
def segments
segments = split(/\./)
while segments.size > 1
yield(segments.join('.'))
segments.pop
end
yield('.')
end
end
View gist:23413
#!/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
View gist:25229
class String
def reindent(to, tabwidth=nil)
indenter = (tabwidth ? " "*tabwidth : "\t")*to
initial = self[/\A[\t ]*/]
gsub(/^(?:#{initial})?/, indenter)
end
end
View gist:30775
$ ruby cgi.rb
(offline mode: enter name=value pairs on standard input)
sprache=java
Content-Type: text/html
Content-Length: 14
code ist java
View gist:33310
/*
$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.
*/
View gist:77670
# 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
View gist:77814
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
}
View gist:172234
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
View gist:207646
#!/usr/bin/env ruby
require 'optparse'
utf8 = true
colors = false
opts = OptionParser.new("", 24, ' ') do |opts|
opts.banner = "Usage: #{$PROGRAM_NAME} [options] [directory]"
You can’t perform that action at this time.