Skip to content

Instantly share code, notes, and snippets.

@tjmcewan
tjmcewan / custom.rake
Created June 25, 2011 05:36
password resetter
namespace :db do
desc 'Reset all User passwords to "letmein"'
task :password_reset => :environment do
count = 0
User.all.each do |u|
u.password = u.password_confirmation = 'letmein'
if u.save
count += 1
print '.'
else
ruby-1.9.2-p180 :007 > Team.all.count
Team Load (1.6ms) SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`type` = 'Team' ORDER BY nodes.name DESC
=> 13
ruby-1.9.2-p180 :008 > Zone.all.count
Zone Load (2.2ms) SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`type` = 'Zone' ORDER BY nodes.name DESC
League Load (0.5ms) SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`type` = 'League' AND `nodes`.`id` = 1 ORDER BY nodes.name DESC LIMIT 1
Round Load (0.5ms) SELECT `rounds`.* FROM `rounds` WHERE (`rounds`.league_id = 1) ORDER BY rounds.starts_at DESC
SQL (0.4ms) SELECT COUNT(*) FROM `zone_configurations` WHERE (`zone_configurations`.zone_id = 5)
League Load (0.4ms) SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`type` = 'League' AND `nodes`.`id` = 1 ORDER BY nodes.name DESC LIMIT 1
Round Load (0.4ms) SELECT `rounds`.* FROM `rounds` WHERE (`rounds`.league_id = 1) ORDER BY rounds.starts_at DESC
(rdb:1) date
2010-09-26 05:02:10 UTC
(rdb:1) date.class
Time
(rdb:1) @league.rounds.current.start_date.utc
2010-09-26 05:02:10 UTC
(rdb:1) @league.rounds.current.start_date.utc.class
Time
(rdb:1) @league.rounds.current.start_date.utc == date
false
class Node < ActiveRecord::Base
validates :name, :presence => true
end
class Team < Node
delegate :name, :to => :profile
after_initialize do |team|
team.build_profile(:name => team[:name]) if team.new_record? && team.profile.nil?
end
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::RecordNotUnique:
Mysql2::Error: Duplicate entry '1' for key 'PRIMARY': INSERT INTO `nodes` (`type`, `ancestry`, `parent_id`, `name`, `ancestry_depth`, `created_at`, `updated_at`, `active`, `id`) VALUES ('Team', NULL, 2, 'Team 1', 0, '2011-06-26 10:19:42', '2011-06-26 10:19:42', 1, 1)
# ./spec/support/custom.rb:18:in `setup_league_structure'
# ./spec/support/controller_macros.rb:5:in `block in login_user'
@tjmcewan
tjmcewan / mass_assignment_exception.rb
Created July 13, 2011 14:29
raise exception on attempted mass assignment of a protected attribute
# monkey-patch to raise an exception when attempting to mass-assign a protected attr
# more info: http://is.gd/MiA1mn
module ActiveModel
module MassAssignmentSecurity
module Sanitizer
protected
def warn!(attrs)
self.logger.debug "WARNING: Can't mass-assign protected attributes: #{attrs.join(', ')}" if self.logger
raise RuntimeError, "these attributes are protected from mass assignment, use `attr_accessible :#{attrs.join(', :')}`"
end
Loaded Taps v0.3.23
Receiving schema
Schema: 0% | | ETA: --:--:--
Schema: 6% |== | ETA: 00:00:48
Schema: 13% |===== | ETA: 00:00:46
Schema: 20% |======== | ETA: 00:00:41
Schema: 26% |========== | ETA: 00:00:38
Schema: 33% |============= | ETA: 00:00:34
Schema: 40% |================ | ETA: 00:00:30
Schema: 46% |=================== | ETA: 00:00:27
@tjmcewan
tjmcewan / backtrace.txt
Created January 7, 2013 05:49
jasminerice-runner error backtrace
Running jasmine specsrake aborted!
Modal dialog present
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@googlecode.com/components/command_processor.js:10287:in `nsCommandProcessor.execute'
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@googlecode.com/components/driver_component.js:7328:in `Dispatcher.executeAs/<'
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@googlecode.com/components/driver_component.js:7488:in `Resource.handle'
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@googlecode.com/components/driver_component.js:7435:in `Dispatcher.dispatch'
[remote server] file:///var/folders/0r/jzw528_d75gbznxsjfnn4sz80000gn/T/webdriver-profile20130107-27002-3feaho/extensions/fxdriver@g
@tjmcewan
tjmcewan / successful install.sh
Created February 17, 2013 23:43
The words "fatal error" and "1 error generated" should generally _not_ be followed by "Successfully installed..."
$ pip install pyyaml
Downloading/unpacking pyyaml
Downloading PyYAML-3.10.tar.gz (241kB): 241kB downloaded
Running setup.py egg_info for package pyyaml
Installing collected packages: pyyaml
Running setup.py install for pyyaml
checking if libyaml is compilable
cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c build/temp.macosx-10.8-x86_64-2.7/check_libyaml.c -o build/temp.macosx-10.8-x86_64-2.7/check_libyaml.o
build/temp.macosx-10.8-x86_64-2.7/check_libyaml.c:2:10: fatal error: 'yaml.h' file not found