Skip to content

Instantly share code, notes, and snippets.

View benhoskings's full-sized avatar

Ben Hoskings benhoskings

View GitHub Profile
class Object
def new_with &block
self.new.instance_eval {
yield
}
end
end
$logger = Object.new_with {
define_method :foo do
if (results = Parser.new.parse).nil?
# parse failure
else
# displaying help info and exiting is a valid execution method
execute_with_options results
end
def proclol arg
{
'a' => proc { true },
'b' => proc { do_something },
'c' => proc { your_money || your_fase }
}[arg]
end
proclol('b').call

For the package management you're talking about, it sounds like there are two cases:

  • Accept any version (1)
  • Require a specific version (2)
  • Require the latest version (3)

Babushka can already do (1) and (2). The third is fairly easy to add, but to do so in babushka core isn't really feasible until I refactor Babushka::BrewHelper.

For (1), you don't need to do anything: that's the standard behaviour. For example:

def self.cumulative_by_month model, column
tally = 0
count_by_month(model, column).map do |(month, count)|
[month, tally += count]
end
end
def self.cumulative_by_month_inject model, column
count_by_month(model, column).tap {|pairs|
pairs.inject(0) do |tally,pair|
@benhoskings
benhoskings / gist:3f9062dc20961291a230
Created October 6, 2014 07:59
英語の練習のオススメ
いい練習の番組:
Seinfeld (アメリカ、コメディー) 話が本当にアメリカの形。ユーモアが最高。一番有名なので英語が話せる人とたしかにしゃべれる。
Frasier (アメリカ、コメディー) 一杯あるし、Kelsey GrammerとDavid Hyde Pierceの英語がうまい。
The Office (UKとUSの番組だって、両方ある。とてもいいイギリスとアメリカの比べる事。)
Sherlock (イギリス、) 話がとても速いけど、いいイギリスの英語だと思う。
その他:(これは、僕がちょっとだけ見ましたけど、いい練習だと思う。)
Futurama
House
def self.define_the_methods name
(class << self; self; end).instance_eval {
define_method name do |account|
log 'class'
end
}
define_method name do |account|
log 'instance'
end
/* goes in ~/Library/KeyBindings */
{
/* page up/down */
"\UF72C" = "pageUp:";
"\UF72D" = "pageDown:";
/* Modifier keys: start with C-m */
"^m" = {
"^ " = ("insertText:", "\U2423"); /* C-space space */
class Lol
def where_am_i
"within #{self.class.to_s}"
end
def winproc
proc { "lol from #{where_am_i}" }
end
end
def where_am_i
# Where the hell did 'lol' get defined?
method_name = "lol"
ObjectSpace.each_object.each {|o| puts "#{o.is_a?(Class) ? o.name : o.class}: #{o.methods.grep method_name}" unless o.methods.grep(method_name).empty? }