View gist:89c44bcfd76f1add3b31
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
irb(main):003:0> require 'benchmark' | |
=> true | |
irb(main):004:0> numbers = nil | |
=> nil | |
irb(main):005:0> puts Benchmark.measure { numbers = 1_000_000.times.map {|i| i.to_f }; 1 } | |
1.110000 0.000000 1.110000 ( 0.448476) | |
=> nil | |
irb(main):006:0> numbers.length | |
=> 1000000 | |
irb(main):007:0> puts Benchmark.measure { numbers.inject(:+) } |
View -
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
2010-01-12 | |
2010-01-13 | |
2010-01-14 | |
2010-01-15 | |
2010-01-16 | |
2010-01-19 | |
2010-01-20 | |
2010-01-21 | |
2010-01-22 | |
2010-01-23 |
View gist:a838b57308cab7758a58
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 rescue_retry(tries = 2, options = {}, &block) | |
raise ArgumentError, 'gimme a block' unless block_given? | |
begin | |
tries -= 1 | |
yield | |
rescue => e | |
if tries > 0 | |
sleep(options[:sleep]) if options[:sleep] | |
retry |
View parse_moped.rb
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
#!/usr/bin/env ruby | |
File.readlines('./tmp/5.log').each.with_index do |line, i| | |
matches = line.match(/\s+MOPED: \S+ (\w+)/i) | |
next if matches.nil? | |
op = matches.to_a.last.downcase | |
t = line.match(/\(([.0-9]+)ms\)$/i).to_a.last | |
puts "#{i},#{op},#{t}" | |
end |
View complete_nary_tree.rb
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
#!/usr/bin/env ruby | |
class CompleteNaryTreeGenerator | |
def self.generate_dot(height, degree) | |
puts 'digraph {' | |
# Convenience. | |
d = degree | |
h = height | |
i = 1 |
View random
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/sh | |
# Generate n random numbers in [0, 999]. n defaults to 100 but override it with $1. | |
if [ "$1" == '' ]; then | |
upto=100 | |
else | |
upto=$1 | |
fi | |
for i in `seq 1 $upto`; do echo $(($RANDOM % 1000)); done |
View histogram
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/sh | |
# Plot an ASCII histogram of numbers from stdin. Uses gnuplot. | |
# Optionally specify bin size as an argument. | |
if [ "$1" == '' ]; then | |
binsize=100 | |
else | |
binsize=$1 | |
fi |
View id_dsa.pub
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
ssh-dss AAAAB3NzaC1kc3MAAACBAIE9R4sFArK2lrn0l0MLRFxn0ExUMIH/4VPg2gQxE9a1KwTr9nbQpL6H+mxxZLNm9+iKZeKrx+PEqNH6SmhYx0LUQ7FqaYhy89Leoy5uUW87CSd9x7KuxBChK9vvqyf8X7b2mGzWgs5XRzSiLHngn8XGHxVgXQoS1K/w7M+c4I2nAAAAFQDEhsSJQOzio1v8Jiy5ypALwxnaswAAAIB7STNNhWdkb7SeHs0zEEkwgs0nExzBFAZ3WAmZZnb8m9HWTLbwZpGGPRfcWi0cthHIwfzATvzUwEZuzjmeqhS9J7UxSaPOpzg4mTSQFvj6ZHzTg+ZwhNIRAOOaXV2lopq9KChV+ZSjtmZQDs6Js0oJEAuw5DCktKTnkZ1Kf8hsfQAAAIBattEuuohpFnTY5VM8B7mMVib1y1jQ0yPa+sORBFqzdGeJxoPZJvGXhO5L90KW20VtLGRbrrkdrZ75/7Cy1mISe6+Of7WBaZniL+kxUN4+hwuw/2aWjgOUstEhFOf3rilinMc/wBtCjpe5GLLEbDTGLAlZbS0/GwS+hh1GLKfdmg== huned@omg |
View activeresource_base_callable_user.rb
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 ActiveResource | |
class Base | |
class << self | |
# Monkey patch ActiveResource::Base.user a little. We want it to call | |
# @user if @user is callable, otherwise use the default behavior. | |
def user_with_lambda | |
if defined?(@user) && @user.respond_to?(:call) | |
@user.call(self) | |
else | |
user_without_lambda # default behavior |
View gist:417c103da6691fd60463
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 File.expand_path('../../config/environment', __FILE__) | |
require 'csv' | |
intermediaries = Person.intermediary.asc(:name).to_a | |
intermediaries.each do |person| | |
company = person.current_company | |
latest_activity = | |
if company.present? | |
company.activities.desc(:created_at).where(:kind.in => Activity::FOLLOWUPABLE_KINDS).first | |
else |