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
#!/bin/env ruby -wdK | |
# Given an array, print it as a bar graph | |
# Use FOR SPEED!!! | |
class VerticalAsciiGraph | |
WIDTH = 72 | |
STEPS = WIDTH/6 | |
def self.draw(sample) | |
new(sample).draw | |
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
events: wall_time | |
fl=/Users/jasonn/sources/services/service-leads/ruby_runtime | |
fn=Array::size | |
0 3 | |
fl=/Users/jasonn/sources/services/service-leads/ruby_runtime | |
fn=Kernel::respond_to? | |
0 127 |
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 Rack | |
# | |
# A Rack middleware for automatically removing the format token at the end | |
# of a request path and adding its media type to the HTTP_ACCEPT header. | |
# | |
# MIT-License - Rein Henrichs | |
# | |
class FormatAccepts | |
def initialize(app) | |
@app = app |
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
* This is the Parser 2 API version of the LetMeGoogleThatForYou * | |
* Ubiquity script compatible with Ubiquity 0.5+. * | |
* The Legacy parser version is available at * | |
* http://gist.github.com/45201 * | |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
var icon = "http://letmegooglethatforyou.com/favicon.ico"; | |
var tu_desc = "<a href=\"http://www.tinyurl.com\">TinyUrl</a>"; | |
var lmg_desc = "<a href=\"http://lmgtfy.com\">Let Me Google That For You</a>"; |
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
>> require 'builder' | |
=> true | |
>> x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1) | |
<inspect/> | |
=> #<IO:0x2f7d8> | |
>> x.Hello "World" | |
<Hello>World</Hello> | |
=> #<IO:0x2f7d8> |
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
def do_something | |
action = case | |
when self.play?: true ? 'play football' : 'do nothing' | |
when self.work?: 'go to work' | |
when self.sleep?: 'sleep' | |
else: 'What?' | |
end | |
return action | |
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 Facter | |
def self.add(name, &block) | |
collection.add(name, &block) # eventually becomes Factor::Util::Resolvers.instance_eval(block) | |
end | |
end | |
class Factor::Util::Resolvers | |
class << self | |
def setcode(string=nil, &block) | |
return Facter::Util::Resolvers::Exec.new(string) if string |
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
# Compute an average for <back> elements from the end of the results | |
def average_value(back, results) | |
return results['values'].last['value'] if back.zero? | |
values = results['values'].map { |item| item['value'] } | |
average[-back, back].inject {|sum, i| sum + i} / range_of_interest.size.to_f | |
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
# Compute an average for <back> elements from the end of the results | |
def average_value(back, results) | |
return results['values'].last['value'] if back.zero? | |
values = results['values'].map { |item| item['value'] } | |
values[-back, back].inject {|sum, i| sum + i} / range_of_interest.size.to_f | |
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
describe Node do | |
describe 'attributes' do | |
before :each do | |
Node.generate! | |
@node = Node.new | |
end | |
it { should have_many(:node_class_memberships) } | |
it { should have_many(:node_classes).through(:node_class_memberships) } | |
it { should have_many(:node_group_memberships) } |