Skip to content

Instantly share code, notes, and snippets.

View bdmac's full-sized avatar

Brian McManus bdmac

View GitHub Profile
@bdmac
bdmac / gist:6176395
Last active December 20, 2015 18:29
{
"reservations":[
{reservation JSON object}
],
"page":1,
"total":9,
"total_pages":2,
"links":[
{
"rel":"next_page",
@bdmac
bdmac / gist:6175557
Last active December 20, 2015 18:19
{
"id":16,
"name":"New York Marriott Marquis",
"phone":"1 212-3981900",
"full_address":"1535 Broadway, New York, NY, 10036, US",
"latitude":40.758408,
"longitude":-73.985517,
"checkout_time":null,
"time_zone":"America/New_York",
"address":{
@bdmac
bdmac / gist:5032984
Last active December 14, 2015 05:09
Proposal to modify rails-core with optimistic locking enhancements or turn this into a gem.
# Automatically adds lock_version to model forms if the underlying
# model has locking_enabled.
module ActionView
module Helpers
module OptimisticLockingFormFor
def self.included(base)
base.alias_method_chain :form_for, :optimistic_locking
base.alias_method_chain :fields_for, :optimistic_locking
end
@bdmac
bdmac / gist:3362839
Created August 15, 2012 19:28
Place JSON response
{ "address" : { "city" : "Sao Chingcha",
"country" : "TH",
"postcode" : null,
"state" : "Krung Thep Mahanakhon",
"street" : null
},
"featured_article" : { "copy" : "Thailand may be best known for post-collegiate backpacking and beach-bumming, but thousands jet there each year for the endless spa and wellness offerings, not to mention the welcoming Buddhist vibe, cheaper prices, and jaw-dropping beaches. Find nirvana—spiritually and physically—at two of Bangkok's plushest pampering destinations, both recently pimped out with huge expansions. All treatments at the uber-plush Peninsula begin with a tea ritual and ginger foot buff, while the The Oriental Bangkok's debut of its Ayurvedic Penthouse means you'll be covered from head to toe with rejuvenating mind-body bliss.",
"credit_name" : "Tracie Broom",
"credit_url" : "https://openplac.es/users/traciebroom"
},
@bdmac
bdmac / gist:2311191
Created April 5, 2012 13:57
JSON Response Example
{ "next_page" : "https://api.openplac.es/api/places.json?page=2",
"page" : 1,
"places" : [ { "address" : { "city" : "Sao Chingcha",
"country" : "TH",
"postcode" : null,
"state" : "Krung Thep Mahanakhon",
"street" : null
},
"featured_article" : { "copy" : "Thailand may be best known for post-collegiate backpacking and beach-bumming, but thousands jet there each year for the endless spa and wellness offerings, not to mention the welcoming Buddhist vibe, cheaper prices, and jaw-dropping beaches. Find nirvana—spiritually and physically—at two of Bangkok's plushest pampering destinations, both recently pimped out with huge expansions. All treatments at the uber-plush Peninsula begin with a tea ritual and ginger foot buff, while the The Oriental Bangkok's debut of its Ayurvedic Penthouse means you'll be covered from head to toe with rejuvenating mind-body bliss.",
"credit_name" : "Tracie Broom",
@bdmac
bdmac / gist:1714732
Created February 1, 2012 02:37
Heroku memory problem
coordinate_map = Destination.only(:id, :coordinates).all.inject({}) {|h, d| h[d.id.to_s] = d.coordinates.reverse; h}
user_count = User.where(destination_id: nil).count
0.step(user_count, BATCH_SIZE) do |offset|
User.where(destination_id: nil).limit(BATCH_SIZE).skip(offset).each do |user|
next unless user.coordinates.present?
# This used to be a one-liner but broke it up to see if it helped mem-usage
distances = coordinate_map.each_with_object({}) {|(k,v), h| h[k] = user.distance_from(v)}
destination_id = distances.min_by(&:last).first
user.update_attribute(:destination_id, destination_id) rescue nil
distances = nil
# The problem below is that the JS responses were not being cached properly
# but the HTML responses were fine.
caches_action :show, :layout => false, :expires_in => 24.hours
def show
respond_to do |wants|
wants.html
wants.js {
# What... the... fuck... After tracing why the JS responses to this action
> db.collection.find( { latlng : { $near : [50,50] , $maxDistance : 5 } } )
> db.collection.find( { latlng : { $maxDistance : 5 , $near : [50,50] } } )
error: {
"$err" : "missing geo field (latlng) in : { latlng: { $maxDistance:
5.0, $near: [ 50.0, 50.0 ] } }",
"code" : 13042
}
Scenario: Signup page - logged out # features/signup.feature:7
Given I am not logged in # features/step_definitions/signup_steps.rb:1
When I visit the signup page # features/step_definitions/signup_steps.rb:4
Then I should see the signup page # features/step_definitions/signup_steps.rb:8
WORLD:
Cucumber::Rails::World
WithinHelpers
NavigationHelpers
Capybara
Cucumber::Web::Tableish
testing