This file contains hidden or 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 bash | |
mate .autotest app/ features/ config/ lib/ db/ vendor/gems/ vendor/plugins/ public/ test/ spec/ Rakefile README; |
This file contains hidden or 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 String | |
def to_name | |
firstname,middlename,lastname = nil,nil,nil | |
name = self | |
name_ary = name.split(" ") | |
if name_ary.size > 2 | |
firstname,middlename,lastname = name_ary[0],name_ary[1],name_ary[2..name_ary.size].join(" ") | |
else | |
firstname,lastname = name_ary[0],name_ary[1] | |
end |
This file contains hidden or 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 quicktime_movie(url, options = {}) | |
filename = url.scan(/\w+\.mov$/) | |
url.gsub!(filename) | |
object_tag_options = { | |
:CLASSID => "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B", | |
:width => "320", | |
:height => "256", | |
:codebase => "http://www.apple.com/qtactivex/qtplugin.cab" | |
}.update(options) | |
This file contains hidden or 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 'rubygems' | |
begin | |
gem 'gem_name' | |
rescue LoadError | |
require 'gem_name' | |
end | |
This file contains hidden or 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
## app/controllers/users_controller.rb | |
class UsersController < ApplicationController::Base | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
SomeMailer.deliver_activation_email(@user, self) # pass in the controller object | |
redirect_to some_path | |
end | |
end | |
end |
This file contains hidden or 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/ruby | |
class Foo | |
attr_accessor :name, :age | |
def initialize | |
@options = {:name => "Tim", :age => 28} | |
end | |
def work(h) |
This file contains hidden or 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
# Adds a convienence method to the Hash class | |
# Allows you to check if a hash has a valid key and value. | |
class Hash | |
def assert_valid_key?(key) | |
self.symbolize_keys.has_key?(key.to_sym) && !self[key].blank? | |
end | |
end | |
# Test it |
This file contains hidden or 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 String | |
def to_hex | |
hex_chars = [] | |
self.size.times do |n| | |
char = self.slice(n,n+1) | |
hex_chars.push(char.unpack('U')[0].to_s(16).upcase) | |
end | |
hex_chars.join(" ") | |
end | |
end |
This file contains hidden or 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 HerokuLogger | |
def initialize | |
@keep_processing = true | |
@log = nil | |
stop_tailing = Proc.new do | |
puts "---------------------- Terminating ------------------------" | |
@keep_processing = false | |
end |
This file contains hidden or 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
# Examples | |
# [1,1,2,1,1,2,2].moving_average(2) => [1, 1, 1, 2] | |
class Array | |
# Calculates the moving average | |
# given a Integer as a increment period | |
def moving_average(increment = 1) | |
return self.average if increment == 1 | |
a = self.dup | |
result = [] |
OlderNewer