Skip to content

Instantly share code, notes, and snippets.

ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
mysql> SELECT 5 / NULL;
+----------+
| 5 / NULL |
+----------+
| NULL |
+----------+
1 row in set (0.00 sec)
>> c.preview_channels_json
=> ["{\"id\":1,\"network_label\":\"Facebook\"}", "{\"id\":720703596,\"network_label\":\"Twitter\"}"]
>> c.preview_channels_json.to_json
=> "[\"{\\\"id\\\":1,\\\"network_label\\\":\\\"Facebook\\\"}\",\"{\\\"id\\\":720703596,\\\"network_label\\\":\\\"Twitter\\\"}\"]"
>> c.preview_channels_json.to_json.to_json
=> "\"[\\\"{\\\\\\\"id\\\\\\\":1,\\\\\\\"network_label\\\\\\\":\\\\\\\"Facebook\\\\\\\"}\\\",\\\"{\\\\\\\"id\\\\\\\":720703596,\\\\\\\"network_label\\\\\\\":\\\\\\\"Twitter\\\\\\\"}\\\"]\""
>> c.preview_channels_json.to_json.to_json.to_json
=> "\"\\\"[\\\\\\\"{\\\\\\\\\\\\\\\"id\\\\\\\\\\\\\\\":1,\\\\\\\\\\\\\\\"network_label\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"Facebook\\\\\\\\\\\\\\\"}\\\\\\\",\\\\\\\"{\\\\\\\\\\\\\\\"id\\\\\\\\\\\\\\\":720703596,\\\\\\\\\\\\\\\"network_label\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"Twitter\\\\\\\\\\\\\\\"}\\\\\\\"]\\\"\""
# Wrap write_attribute to remember original attribute value.
def write_attribute_with_dirty(attr, value)
attr = attr.to_s
# The attribute already has an unsaved change.
if changed_attributes.include?(attr)
old = changed_attributes[attr]
changed_attributes.delete(attr) unless field_changed?(attr, old, value)
else
old = clone_attribute_value(:read_attribute, attr)
require 'rubygems'
require 'activesupport'
require 'harvest'
harvest = Harvest(:email => "lulz",
:password => "lulz",
:sub_domain => "lulz")
project = harvest.projects.find(:all).first
# BEFORE
>> a = User.new; a.valid?
>> a.errors.to_json
=> "[["name", "can't be blank"], ["password_confirmation", "can't be blank"], ["password", "can't be blank"], ["password", "is too short (minimum is 6 characters)"], ["email", "can't be blank"], ["email", "is too short (minimum is 6 characters)"], ["email", "should look like an email address."]]"
# config/initializers/sane_errors_to_json.rb
module ActiveRecord
class Errors
def to_json
class ActionMailer::Base
cattr_accessor :delayed_mail_handler
class << self
def method_missing_with_delayed_mail_handling(name, *args)
if @@delayed_mail_handler
@@delayed_mail_handler.to_s.classify.constantize.handle_mail(self, name, *args)
else
class Time
def with_interval_of(interval)
@interval = interval
self
end
def succ
@interval ||= 1
class Array
def detect_index(&block)
each_with_index do |e, i|
return i if yield e
end
end
end
~/projects/[project](master) $ git pull
Current branch master is up to date.
~/projects/[project](master) $ script/plugin install git://github.com/technoweenie/relative_time_helpers.git/
Initialized empty Git repository in /Users/nik/projects/[project]/vendor/plugins/relative_time_helpers/.git/
fatal: bad revision 'HEAD'
refusing to pull with rebase: your working tree is not up-to-date