Skip to content

Instantly share code, notes, and snippets.

View Breefield's full-sized avatar

Bree Hoffman Breefield

View GitHub Profile
@Breefield
Breefield / dj.rb
Created March 4, 2013 22:59
Way 2
class User < ActiveRecord::Base
after_create :notify_user_created
def notify_user_created
# Things happen in here
end
handle_asynchronously :notify_user_created
end
require 'net/http'
Net::HTTP.start("example.com") do |http|
resp = http.get("/path/file.blah")
open("file.blah", "wb") do |file|
file.write(resp.body)
end
end
// Show the event map
var $map = $('.location-map');
if($map.length) {
var approx_location = $map.attr('approx-location');
var approx_city = $map.attr('approx-city');
var location = new google.maps.LatLng(
$map.data('latitude'),
$map.data('longitude')
);
# Logs are saying:
#
# Cache read: geocoded/New York, NY
# Cache fetch_hit: geocoded/New York, NY
# Google Geocoding API error: over query limit.
#
# Seems to hit a match, then query google anway
def self.geocode(address)
location = Rails.cache.fetch("geocoded/#{address}") do
class UserSession < Authlogic::Session::Base
validate :check_presence
# Without the following method, calling persisted? on UserSession fails,
# which is needed for polymorphic_url when called with a UserSession.
def destroyed?
false
end
@Breefield
Breefield / init.rb
Created November 14, 2013 01:34
s.files = Dir['lib/*.rb'] + Dir['locales/*']
Gem::Specification.new do |s|
s.files = 'lib/cold_shoulder.rb'
end
class Message < ActiveRecord::Base
validates :body, cold_shoulder: true
end
twitter_regex = /(@[A-Za-z0-9_]{1,15})/i
formatted_phone_regex = /((?:\+?(\d{1,3}))?[- (]*(\d{3})[- )]*(\d{3})[- ]*(\d{4})(?: *x(\d+))?\b)/i
email_regex = /(\b[^\s]+?\s*(@|at)\s*[^\s]+?\.[^\s]+?\b)/i # Very general so as to catch BS
Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
end
class CreateLocations < ActiveRecord::Migration
def change
create_table :locations do |t|
t.string :address
t.float :latitude
t.float :longitude
t.integer :located_id
t.string :located_type
t.timestamps