Skip to content

Instantly share code, notes, and snippets.

Something change in Rails 2.3.2 since 2.1.2, and I'm not sure what, or how to handle it.
Watch how the 'role' column (which the below shows that it is a private method, even though
it's just a column in the users table) gets handled by the different versions.
Rails 2.3.2 throws an error when first getting it, 2.1.2 doesn't.
Both update their classes to show that its not a private method after it has been set once!
In Rails 2.3.2:
=====================================
Loading development environment (Rails 2.3.2)
>> cols = User.columns.map {|c| c.name}
module Hobo
module Permissions
def self.included(klass)
klass.class_eval do
Hobo::Permissions::Associations.enable
extend ClassMethods
alias_method_chain :create, :permission_check
@harmon
harmon / LiveReload Max Error
Created October 30, 2010 04:49
This is the error after installing livereload and running it on the command line on Mac OSX 10.5.8
project % livereload 9:44
Version: 1.4 (compatible with browser extension versions 1.4.x)
Port: 35729
Watching: /Users/user/sandbox/active/project
- extensions: .html .css .js .png .gif .jpg .php .php5 .py .rb .erb
- excluding changes in: */.git/* */.svn/* */.hg/*
- with a grace period of 0.05 sec after each change
LiveReload is waiting for browser to connect.
@harmon
harmon / gist:745470
Created December 17, 2010 18:44
Rake Task: Rails Date Formats (v2.3.10)
# Outputs the default formats for Date, Datetime, and Time Ruby classes.
# Stolen from http://onrails.org/2008/08/20/what-are-all-the-rails-date-formats
desc "Show the date/time format strings defined and example output"
task :date_formats => :environment do
now = Time.now
[:to_date, :to_datetime, :to_time].each do |conv_meth|
obj = now.send(conv_meth)
puts obj.class.name
puts "=" * obj.class.name.length
@harmon
harmon / gist:745472
Created December 17, 2010 18:45
Rails: logging helpers (v2.3.10)
def log_debug(text)
RAILS_DEFAULT_LOGGER.debug("\e[41m #{text} \e[0m")
end
def db(text)
log_debug(text)
end
@harmon
harmon / gist:1760473
Created February 7, 2012 16:13
GP App Dev Interview: Vinay
Interview Questions:
What does the following evaluate to: “int a=((1<<7)|(1));”
@harmon
harmon / 1. Diff of test file
Last active December 13, 2015 16:28
RubyProf test method to demonstrate odd CallInfo behavior
diff --git a/test/call_info_test.rb b/test/call_info_test.rb
index 5914da4..f9839e1 100644
--- a/test/call_info_test.rb
+++ b/test/call_info_test.rb
@@ -22,9 +22,37 @@ class CallInfoTest < Test::Unit::TestCase
# assert_equal(call_info.total_time, call_info_clone.total_time)
# end
+ class AceOfSpades
+ def initialize
@harmon
harmon / gist:7296169
Created November 3, 2013 23:53
XBMC Sample Script
import xbmc, xbmcgui
#get actioncodes from keymap.xml
ACTION_PREVIOUS_MENU = 10
class MyClass(xbmcgui.Window):
def __init__(self):
self.strActionInfo = xbmcgui.ControlLabel(100, 120, 200, 200, '', 'font13', '0xFFFF00FF')
self.addControl(self.strActionInfo)
self.strActionInfo.setLabel('Push BACK to quit')
@harmon
harmon / patch_test_helper.py
Last active August 29, 2015 13:57
This wraps the python "Mock" library "patch" function into something that is less verbose.
# This helper module provides Mock library "patch" abilities
# while integrating with the unittest test classes in a way
# to reduce the verbosity of their API.
#
# Use like so:
#
# from sync.mocking_helper import patch_me
#
# class MyClassTest(object):
# def setUp(self):
@harmon
harmon / ipython_setup.sh
Last active August 29, 2015 13:57
Setup ipython notebook
##
# This installs virtualenv-wrapper via virtualenv-burrito.
# It allows for creating centralized virtualenvs in your HOME directory, creating a custom one
# for ipython notebook, installing the notebook, and setting up a command to run it.
##
# Install virtualenv-burrito
curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | $SHELL
source ~/.venvburrito/startup.sh