class String
def to_proc
Proc.new { |n| self.split(".").inject(n) { |n, method| n.send(method) } }
end
end
>> Person.first(2).map(&"name.downcase.reverse.capitalize")
# Adapted for Rails 4 from http://trevorturk.com/2008/09/20/validating-your-fixtures/ | |
# I put this in test/models/. Trevor put his in test/integration/. | |
require 'test_helper' | |
class FixtureValidationTest < ActiveSupport::TestCase | |
test "fixtures should be valid" do | |
models = ActiveRecord::FixtureSet.all_loaded_fixtures.keys | |
models.each do |model| |
class String
def to_proc
Proc.new { |n| self.split(".").inject(n) { |n, method| n.send(method) } }
end
end
>> Person.first(2).map(&"name.downcase.reverse.capitalize")
def find_and_replace_in_source_files(find, replace) | |
extensions = %w[.rhtml .rxml .erb .builder .rb .css .js .rake] | |
files = Dir["**/*"] | |
files.each do |file_name| | |
next if (file_name =~ /^vendor/) || !extensions.include?(File.extname(file_name)) | |
text = File.open(file_name, 'r'){ |file| file.read } | |
changed = text.gsub!(find, replace) | |
File.open(file_name, 'w'){|file| file.write(changed)} if changed | |
end |
function convertDateTimeSelectTo12Hour() { | |
var translate = {"00":"Midnight","01":"1am","02":"2am","03":"3am","04":"4am","05":"5am","06":"6am","07":"7am","08":"8am","09":"9am","10":"10am","11":"11am","12":"Noon","13":"1pm","14":"2pm","15":"3pm","16":"4pm","17":"5pm","18":"6pm","19":"7pm","20":"8pm","21":"9pm","22":"10pm","23":"11pm"}; | |
$("select[name$='(4i)]'] option").each(function() { | |
$(this).text(translate[$(this).text()]); | |
}); | |
} |
require 'test_helper' | |
class UsersTest < ActionController::IntegrationTest | |
setup do | |
reset! | |
@conn = Faraday::Connection.new do |b| | |
b.adapter :action_dispatch, @integration_session | |
b.response :rails_json | |
end | |
end |
# Resque::Reattempt | |
# | |
# The simplest auto-retry on failure (ala DJ) for Resque | |
# | |
# Just extend your job with the module and then instead of defining perform, | |
# define `perform_with_reattempt`: | |
# | |
# class MyReattemptJob | |
# extend Resque::Reattempt | |
# |
Host heroku.com | |
HostName heroku.com | |
User git | |
IdentityFile ~/.ssh/heroku.identity | |
IdentitiesOnly yes |
Ever wondered how to login as another user within Devise? | |
Recently we had a feature request that would provide Admins with the ability | |
to sign is as another user. You could imagine live demonstrations or even production | |
support calls where you would like to be signed in as another user, yet not | |
have to ask for or decrypt their current password. After stewing for a bit, we found a | |
pretty nice solution with Devise. | |
Here's the Cucumber feature... |
#!/usr/bin/env ruby | |
%w{rubygems hmac-sha1 base64 cgi net/https uri openssl}.each{ |f| require f } | |
KEY = '<YOUR KEY>'; | |
SECRET = '<YOUR SECRET>'; | |
# encodes strings that make twitter oauth happy | |
def encode( string ) | |
URI.escape( string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]") ).gsub('*', '%2A') | |
end |
(($) -> | |
regex = /http:\/\/(.*youtube\.com\/watch.*|.*\.youtube\.com\/v\/.*|youtu\.be\/.*|.*\.youtube\.com\/user\/.*#.*|.*\.youtube\.com\/.*#.*\/.*|.*justin\.tv\/.*|.*justin\.tv\/.*\/b\/.*|www\.ustream\.tv\/recorded\/.*|www\.ustream\.tv\/channel\/.*|www\.ustream\.tv\/.*|qik\.com\/video\/.*|qik\.com\/.*|.*revision3\.com\/.*|.*\.dailymotion\.com\/video\/.*|.*\.dailymotion\.com\/.*\/video\/.*|www\.collegehumor\.com\/video:.*|.*twitvid\.com\/.*|www\.break\.com\/.*\/.*|vids\.myspace\.com\/index\.cfm\?fuseaction=vids\.individual&videoid.*|www\.myspace\.com\/index\.cfm\?fuseaction=.*&videoid.*|www\.metacafe\.com\/watch\/.*|blip\.tv\/file\/.*|.*\.blip\.tv\/file\/.*|video\.google\.com\/videoplay\?.*|.*revver\.com\/video\/.*|video\.yahoo\.com\/watch\/.*\/.*|video\.yahoo\.com\/network\/.*|.*viddler\.com\/explore\/.*\/videos\/.*|liveleak\.com\/view\?.*|www\.liveleak\.com\/view\?.*|animoto\.com\/play\/.*|dotsub\.com\/view\/.*|www\.overstream\.net\/view\.php\?oid=.*|www\.livestream\.com\/.*|www\.worldstarhiphop\.com\/vide |