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 'date' | |
# Ruby implementation of algorithm for approximating | |
# sunrise and sunset for a given date, latitude, and longitude. | |
# Ported from instructions at http://users.electromagnetic.net/bu/astro/sunrise-set.php | |
# I think this is accurate to within about 10 minutes. | |
class SunriseSunset | |
def sunset | |
@sunset ||= begin | |
jd = (julian_sunset + 0.5).to_i |
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 | |
while line = STDIN.gets | |
puts line if ARGV.include?('-v') | |
system('notify-send', line) | |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
gem 'starling-starling' | |
require 'starling' | |
unless ARGV.length == 1 | |
STDERR.puts('Usage: starping <host>:<port>') | |
exit(1) | |
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
class CallLogged | |
def hey | |
puts 'hey' | |
end | |
def double(i) | |
i*2 | |
end | |
public_instance_methods(false).each do |method| |
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
# Tiny framework for writing one-line tests. Just call expect with a block. The | |
# block evaluates to true if the test passes and false if it doesn't. | |
# | |
# Example: | |
# class ExpectTest < Test::Unit::TestCase | |
# include Expect | |
# | |
# expect { 1 == 1 } | |
# expect { 1 == 2 } | |
# 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
class Airmigo | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :from, :class_name => 'User' | |
belongs_to :to, :class_name => 'User' | |
before :save do | |
Airmigo.first_or_create(:conditions => { :from => to, :to => from }) |
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
# | |
# Usage: | |
# rake db:rollback_to_common branch=production | |
# git checkout -m production | |
# rake db:migrate | |
# | |
namespace :db do | |
desc 'Rolls back database to common migration state between current branch and another' | |
task :rollback_to_common do | |
FileUtils.cd(RAILS_ROOT) do |
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
############### Named filter issues. | |
# | |
# 1) The table aliases for explicit joins are hacky. Obviously this is an easy fix, but we should | |
# talk about the best alternative. In this example, the resulting alias should not be "posts_blogs". | |
# | |
# => Agreed, although I can't think of anything really clever at the moment... | |
Post.filter do | |
join(Blog, :left, :posts_blogs) do |
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
FixActiveRecordValidationsFullMessages.install |
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 | |
require 'rubygems' | |
require 'parse_tree' | |
require 'ruby2ruby' | |
count = 0 | |
for file in ARGV | |
file_count = Ruby2Ruby.translate(IO.read(file), nil).count("\n") | |
count += file_count |
OlderNewer