Skip to content

Instantly share code, notes, and snippets.

View bdmac's full-sized avatar

Brian McManus bdmac

View GitHub Profile
{
"id":"cccd0eb3-2b9b-46b5-8f50-328846ba2bad",
"data":{
"error_type":"Guest Already Arrived",
"problem_description":null,
"guest_message":null
},
"created_at":"2015-06-06T03:00:08.475-07:00",
"status":"delivered",
"type":"Messages::CheckInError",
@bdmac
bdmac / gist:5de223d419e2696a46d9
Created June 8, 2015 16:33
message.created check_in_response payload
{
"id":"c9186f95-8e3c-4c61-a23b-f70cadb0b9b2",
"data":{
"check_in_time":"2015-06-05T03:00:00Z",
"room_number":"113",
"granted_room_upgrade":true,
"additional_details":null
},
"created_at":"2015-06-04T09:36:28.502-07:00",
"status":"delivered",
@bdmac
bdmac / gist:4f0b475fe859dd74d485
Created June 8, 2015 16:28
message.created ad-hoc webhook payload
{
"id":"06fde765-4526-46eb-ba1c-af109d7b9cc4",
"data":{
"message":"Welcome to Hotel Kabuki."
},
"created_at":"2015-05-29T10:58:37.852-07:00",
"status":"delivered",
"type":"Messages::AdHoc",
"category":"ad-hoc",
"compiled_template":{
@bdmac
bdmac / pre-commit
Last active August 29, 2015 14:12 — forked from dedico/pre-commit
#!/bin/bash
# source rvm and .rvmrc if present
[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"
[ -s "$PWD/.rvmrc" ] && . "$PWD/.rvmrc"
should_precompile=0
# check if anything changed in app/assets
if git diff-index --name-only HEAD | egrep '^app/assets' >/dev/null ; then
@bdmac
bdmac / gist:c4799e29f6a54cea45cf
Created August 19, 2014 23:44
Modification to assets:clean rake task to cleanup old assets from public/assets.
Rake::Task["assets:clean"].enhance do
return "can't run in dev" if Rails.env.development?
puts 'Running my assets:clean extension.'
manifest = Sprockets::Rails::Task.new(Rails.application).manifest
["#{Dir.pwd}/public/assets/"].each do |dir_path|
records = Dir.glob("#{dir_path}**/*")
records.each do |f|
if f =~ /.*.png$/ or
f =~ /.*.jpg$/ or
f =~ /.*.gif$/ or
@bdmac
bdmac / gist:10505604
Created April 11, 2014 22:09
Problem with timezone query
CREATE TEMP TABLE reservations (
reservation_id serial
, start_on timestamptz NOT NULL
, time_zone text); -- we don't need this
INSERT INTO reservations (start_on, time_zone) VALUES
('2014-04-11 00:00+10', 'Australia/Sydney') -- start date 4/11, use midnight in Sydney
, ('2014-04-12 00:00+10', 'Australia/Sydney') -- start date 4/12, use midnight in Sydney
, ('2014-04-11 00:00-07', 'America/Los_Angeles') -- start date 4/11, use midnight in SF
, ('2014-04-12 00:00-07', 'America/Los_Angeles'); -- start date 4/12, use midnight in SF
@bdmac
bdmac / gist:10496601
Last active August 29, 2015 13:59
Range Queries
d1k52r595ne826=> EXPLAIN SELECT "reservations".* FROM "reservations" WHERE (arrival_day && tsrange('2014-04-11 18:42:18.813381', NULL, '[]'));
QUERY PLAN
-----------------------------------------------------------------------
Seq Scan on reservations (cost=0.00..5733.91 rows=14230 width=1038)
Filter: (arrival_day && '["2014-04-11 18:42:18.813381",)'::tsrange)
(2 rows)
d1k52r595ne826=> EXPLAIN SELECT "reservations".* FROM "reservations" WHERE (arrival_day && tsrange('2014-04-11 18:42:18.813381', '2014-04-15 18:42:18.813381', '[]'));
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
@bdmac
bdmac / gist:8480492
Created January 17, 2014 20:07
Using ClientSideValidations middleware with StrongPassword.
module ClientSideValidations::Middleware
class PasswordStrength < ClientSideValidations::Middleware::Base
require 'strong_password'
def response
min_entropy = StrongPassword::StrengthChecker::BASE_ENTROPY
if request.params['min_entropy']
min_entropy = request.params['min_entropy'].to_f
end
entropy = StrongPassword::StrengthChecker.new(request.params['password']).calculate_entropy(use_dictionary: true)
is_strong = entropy >= min_entropy
Upgrading to localeapp:medium on checkmate-staging... failed
! en, controllers.heroku.resources.plan_change.invalid_plan
@bdmac
bdmac / gist:6176418
Last active December 20, 2015 18:29
{
"external_id":"12345qwert67890zxcvb",
"id":664,
"confirmation_number":"1234567890",
"state":"unauthorized",
"first_name":"Jane",
"last_name":"Doe",
"email":"[email protected]",
"room_code": "STDK",
"room_description":"AAA Rate, AAA Membership Card Required Guest - Room, 1 King Or 2 Double, Sofabed",