Skip to content

Instantly share code, notes, and snippets.

#!/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
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
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 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>";
>> require 'builder'
=> true
>> x = Builder::XmlMarkup.new(:target => $stdout, :indent => 1)
<inspect/>
=> #<IO:0x2f7d8>
>> x.Hello "World"
<Hello>World</Hello>
=> #<IO:0x2f7d8>
@reinh
reinh / gist:180799
Created September 4, 2009 08:42 — forked from anonymous/gist:180794
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
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
# 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
# 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
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) }