Skip to content

Instantly share code, notes, and snippets.

Avatar

Tyler Rick TylerRick

  • USA
View GitHub Profile
@TylerRick
TylerRick / git-merge-better
Created Sep 14, 2010
An early version of git-merge-better, part of http://github.com/TylerRick/tyler-git
View git-merge-better
#!/usr/bin/env ruby
#---------------------------------------------------------------------------------------------------
# TODO:
# doesn't handle if multiple conflict markers!!
#---------------------------------------------------------------------------------------------------
require 'pathname'
require 'facets/file/rewrite'
require 'quality_extensions/pathname'
@TylerRick
TylerRick / javascript_code.rb
Created Oct 6, 2010
Proc#to_json, JavascriptCode#to_json
View javascript_code.rb
# This allows you to represents a JavaScript function with a proc. When converted to JSON, it will
# automatically wrap the method body with "function(){" and "}" and list as many arguments as you
# had listed in your proc, automatically giving them the names a, b, c, etc.
#
# This is convenient when you want to create a Ruby hash representating options to be passed to
# a JavaScript method, which you plan to call to_json on when you actually output the method call
# to the web page. If you tried to represent your JavaScript function with a string value in the
# hash, then when you called to_json on the hash, it would in turn call String#to_json, which
# returns an escaped copy of the string surrounded by quotes.
#
@TylerRick
TylerRick / backtrace.txt
Created Oct 5, 2011
mysql2 crash with error "ruby: double free or corruption (!prev)" while running cucumber
View backtrace.txt
When I press "Continue »" # features/step_definitions/web_steps.rb:52
Then I should see "Membership information successfully saved" # features/step_definitions/web_steps.rb:106
*** glibc detected *** ruby: double free or corruption (!prev): 0x0000000008899790 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x78a8f)[0x7f0fd98cda8f]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x73)[0x7f0fd98d18e3]
/usr/lib/libmysqlclient_r.so.16(free_root+0xd0)[0x7f0fd5a89c00]
/usr/lib/libmysqlclient_r.so.16(mysql_free_result+0x4f)[0x7f0fd5aaf60f]
/home/tyler/.rvm/gems/ruby-1.9.2-p290@gemset/gems/mysql2-0.2.10/lib/mysql2/mysql2.so(+0x35b4)[0x7f0fd5e425b4]
/home/tyler/.rvm/rubies/ruby-1.9.2-p290/lib/libruby.so.1.9(+0x17b356)[0x7f0fda84c356]
@TylerRick
TylerRick / en.yml
Created Dec 15, 2011
Custom Validator that automatically provides the %{allowed_options} interpolation variable for use in your error messages
View en.yml
en:
activerecord:
errors:
messages:
restrict_to: "is not one of the allowed options (%{allowed_options})"
@TylerRick
TylerRick / bootstrap-rvm-erb.sh
Created Mar 2, 2012
Bootstrap script for chef-solo that installs rvm, ruby, bundler, and chef (within a gemset)
View bootstrap-rvm-erb.sh
#!/bin/bash
# Actual filename: bootstrap/rvm.erb
# vim: set ft=sh
# This script automatically bootstraps the system with everything it needs to run chef-solo.
# Note: This should only do the absolute minimum necessary to get chef-solo (and your recipes)
# working. All else should be done via chef recipes.
#===================================================================================================
# Config
View spree_export_import.rake
namespace :spree do
desc "Export Products to CSV File"
task :export_products => :environment do
require 'csv'
products = Product.where(:deleted_at => nil).all
puts "Exporting to #{RAILS_ROOT}/products.csv"
CSV.open("#{RAILS_ROOT}/products.csv", "w") do |csv|
csv << [
@TylerRick
TylerRick / gist:2501826
Created Apr 26, 2012
composite_primary_keys test failures
View gist:2501826
1) Error:
test_to_key_with_composite_keys(TestAttributeMethods):
ActiveRecord::RecordNotFound: Couldn't find ReferenceCode with ID=1,1 WHERE `reference_codes`.`reference_type_id` = 1 AND `reference_codes`.`reference_code` = 1
/home/tyler/dev/rails/composite_primary_keys/lib/composite_primary_keys/relation/finder_methods.rb:111:in `block in find_with_ids'
/home/tyler/dev/rails/composite_primary_keys/lib/composite_primary_keys/relation/finder_methods.rb:91:in `map'
/home/tyler/dev/rails/composite_primary_keys/lib/composite_primary_keys/relation/finder_methods.rb:91:in `find_with_ids'
/home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.3/lib/active_record/relation/finder_methods.rb:107:in `find'
/home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.3/lib/active_record/querying.rb:5:in `find'
/home/tyler/dev/rails/composite_primary_keys/test/test_attribute_methods.rb:27:in `test_to_key_with_composite_keys'
@TylerRick
TylerRick / gist:2510696
Created Apr 27, 2012
composite_primary_keys: association.build for has_many should populate newly built child record with owner's PK values
View gist:2510696
The FK attributes in the new record used to be set by set_belongs_to_association_for
(which the composite_primary_keys was overriding to work with CPK in its AR 3.0 series),
until this change in ActiveRecord:
commit e8ada11aac28f0850f0e485acacf34e7eb81aa19
Author: Jon Leighton <j@jonathanleighton.com>
Date: Fri Dec 24 00:29:04 2010 +0000
Associations: DRY up the code which is generating conditions, and make it all use arel rather than SQL strings
@TylerRick
TylerRick / group-required-by-name.js
Created May 22, 2012
'group-required-by-name' to require at least one checkbox in a group to be checked
View group-required-by-name.js
//--------------------------------------------------------------------------------------------------
// This is based on the 'group-required' rule from js-webshim/dev/extras/custom-validity.js but
// allows you to specify a group name, in case you need checkboxes with different names in the same
// group.
var groupTimer = {};
$.webshims.addCustomValidityRule('group-required-by-name', function(elem, val){
var $elem = $(elem);
var name = $elem.data('group-required');
var filter = '[data-group-required="' + name + '"]'
if (!name || elem.type !== 'checkbox') { return; }
View showing_how_long_it_took_and_how_many_retries.txt
> rake cucumber
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/home/tyler/.rvm/rubies/ruby-1.9.3-p125/bin/ruby -S bundle exec cucumber --profile default
Using the default profile...
Feature: Cucumber step definitions
@javascript
Scenario: When I do a capybara search that triggers the nested synchronize bug # features/reproduce_bug.feature:3
0 retries=40 e=#<Capybara::ElementNotFound: Unable to find css ".some_div_that_doesnt_exist">