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" | |
gem "hiroshi-pony" | |
require "pony" | |
Pony.mail({ | |
:to => "[email protected]", | |
:subject => "subject", | |
:body => "body", | |
:via => :smtp, :smtp => { | |
:host => 'smtp.gmail.com', |
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
@zipcode = Zipcode.find_by_name("85023") | |
# Passing in a hash of search parameters is more convenient for my purposes, | |
# but searchlogic allows the second, chained method of searching also works. | |
@locations = Location.by_location(:origin => @zipcode, :within => 10).search(:name_like => "searchlogic", :city_is => "Phoenix") | |
@locations = Location.by_location(:origin => @zipcode, :within => 10).name_like("searchlogic").city_is("Phoenix") |
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' | |
require 'geonames' # ppe-ruby-geonames | |
class PostalCodeSearch | |
include Geonames | |
def initialize(postal_code, country_code = "US") | |
@postal_code = postal_code | |
@country_code = country_code | |
@response = nil |
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 User < ActiveRecord::Base | |
acts_as_authentic do |config| | |
config.validate_password_field :if => :require_password_on_signup? | |
end | |
def require_password_on_signup? | |
false | |
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
// Bind a checkbox to a with checked and unchecked callback functions | |
// and run the appropriate action on page load: | |
// | |
// Examples | |
// | |
// $("input[type=checkbox][name=thecheckbox]").bindCheckbox({ | |
// checked: function() { | |
// alert("the checkbox is checked!") | |
// }, | |
// unchecked: function() { |
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
// Works in conjunction with the generate_template helper to insert new | |
// objects into a form that has a collection of items. | |
$.fn.appendFromTemplate = function(template) { | |
return this.each(function () { | |
var newId = new Date().getTime(); | |
$(this).append(template.replace(/NEW_RECORD/g, newId)); | |
}); | |
}; |
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
# Assuming that :something is trusted | |
Mustache.render("<h1>template</h1> {{ something }}", {:something => "<h2>Testing</h2>" }) | |
# => <h1>template</h1> <h2>Testing</h2> | |
# Desired out is "<h1>template</h1> <h2>Testing</h2>" | |
# Solution, use the triple mustache - {{{ }}} - for content that shouldn't be escapes |
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 Post < ActiveRecord::Base | |
before_destroy :protect_from_destruction | |
def protect_from_destruction | |
if protected? | |
errors.add(:base, "Whoa this one is important") | |
false | |
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
require "active_record" | |
require "lib/duration" | |
class Event < ActiveRecord::Base | |
include Duration | |
end | |
describe Duration do | |
before do | |
ActiveRecord::Base.establish_connection( |
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
# where /dev/disk3 is the disk you want to reset | |
# GPT is the GUID partition table | |
# HFS+ is the Apple HFS format | |
diskutil partitionDisk /dev/disk3 GPT HFS+ newDiskName 100% |
OlderNewer