Skip to content

Instantly share code, notes, and snippets.

jwood / questions.rake
Created July 13, 2015 14:03
Example of rake task that migrates production data
namespace :question do
desc "Update Questions and Tasks to support newly added validations"
task :update_for_validations => :environment do
ActiveRecord::Base.transaction do
# Set question_type to "yesno" for following questions:
%w(need_long_term_rental need_short_term_rental find_eye_doctor cleaning need_home).each do |identifier|
q = Question.find_by_identifier(identifier)
q.update_attributes!(question_type: "yesno") if q.present?
nerdsrescueme / regex.txt
Created September 23, 2011 16:08
Common Regex
Perl and PHP Regular Expressions
PHP regexes are based on the PCRE (Perl-Compatible Regular Expressions), so any regexp that works for one should be compatible with the other or any other language that makes use of the PCRE format. Here are some commonly needed regular expressions for both PHP and Perl. Each regex will be in string format and will include delimiters.
All Major Credit Cards
This regular expression will validate all major credit cards: American Express (Amex), Discover, Mastercard, and Visa.
//All major credit cards regex