Skip to content

Instantly share code, notes, and snippets.

View synth's full-sized avatar

Peter Philips synth

View GitHub Profile
@synth
synth / gist:3292441
Created August 8, 2012 05:29
Sometimes you need to slow down Capybara until certain things have loaded(like javascript assets loaded with RequireJS), here's a solution I came up with:
#/spec/support/asynchronous_helper.rb
module AsynchronousHelper
def wait_until_remote_events_are_bound
page.wait_until do
page.evaluate_script("typeof($assetsloaded) === 'object'")
end
end
def wait_until_overlay_has_popped_up
@synth
synth / gist:3329212
Created August 12, 2012 02:42
weird rails association behavior
$> rails new mynewapp
$> cd mynewapp
$> rails g model User
$> rails g model Whatever
$> rake db:migration
#user.rb
belongs_to :whatever
$> rails c
@synth
synth / assets.rb
Last active December 17, 2015 06:29
Local Asset Precompilation with Capistrano and AssetSync
#
# = Capistrano Assets recipe
#
# Provides a couple of tasks for precompiling assets locally
# Assumes usage of AssetSync to deploy to CloudProvider or CDN
#
# Inspired by http://www.rostamizadeh.net/blog/2012/04/14/precompiling-assets-locally-for-capistrano-deployment
namespace :deploy do
@synth
synth / application_pusher.rb
Last active December 20, 2015 17:39
ActionPusher customizations - Higher level customization of the ActionPusher gem https://github.com/agoragames/action_pusher
# NOTE: this architecture hinges on the channels being specific to the user
# this allows us to know what permissions context to render templates under
# seeing as how this may need to be run in a background task without a "current user" context
# so the "current user" is really the recipient of the notification
class ApplicationPusher < ActionPusher::Base
attr_accessor :channel, :event, :current_user
include ActionController::HideActions
include Authorization::AuthorizationInController
@synth
synth / nice_errors
Created January 19, 2014 21:32
A recursive algorithm for generating nested error messages in rails
def nice_errors(object, errors)
object.errors.each do |key|
error_obj = object.send(key)
if error_obj.kind_of?(Array)
errors[key] = {}
error_obj.each {|item| nice_errors(item, errors[key])}
elsif error_obj.kind_of?(ActiveRecord::Base)
errors[error_obj.id] = {}
nice_errors(error_obj, errors[error_obj.id])
else
Shiva:recognize pete$ direnv status
direnv exec path /usr/local/Cellar/direnv/2.3.0/bin/direnv
DIRENV_CONFIG /Users/pete/.config/direnv
No .envrc loaded
Found RC path /Users/pete/work/recognize/.envrc
Found RC mtime 1399402756
Found RC allowed true
Found RC allowPath /Users/pete/.config/direnv/allow/ff6c702ed5d2ddd9c0c25dc39583506d3fe5944604480c51eb7473287e7d7d48
@synth
synth / gist:3f7f4e4726b8e3db2539
Last active August 29, 2015 14:01
rails 4.1.0 bug when finding multiple records while joining a has_many association
rails g model Post
rails g model Comment post_id:integer comment:string
rails c
p1 = Post.create
p2 = Post.create
p1.comments.create(comment: "1")
p1.comments.create(comment: "2")
p2.comments.create(comment: "3")
p2.comments.create(comment: "4")
@synth
synth / activerecord-joins-find-multiple-bug.rb
Last active August 29, 2015 14:01
ActiveRecord bug when joining has_many association and finding multiple records
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@synth
synth / keybase.md
Created June 24, 2014 21:53
keybase.md

Keybase proof

I hereby claim:

  • I am synth on github.
  • I am synth (https://keybase.io/synth) on keybase.
  • I have a public key whose fingerprint is 21F3 1810 5912 3776 C65E B287 C33D 7669 E2A2 3723

To claim this, I am signing this object:

@synth
synth / gist:02bae8f2453de3d43353
Last active August 29, 2015 14:04
Ruby constant lookup hell
module Foo
def print_hello
puts HELLO
end
end
class Bar
HELLO="hi there!"
include Foo
end