Skip to content

Instantly share code, notes, and snippets.

View timlinquist's full-sized avatar

Tim Linquist timlinquist

View GitHub Profile
@timlinquist
timlinquist / iostat
Created March 24, 2011 18:36
stat over 3 minutes
iostat -xtm 3 /dev/sdc
Linux 2.6.18-164.11.1.el5 (tm26-s00225) 03/24/11
Time: 11:30:31
avg-cpu: %user %nice %system %iowait %steal %idle
0.36 0.00 0.09 0.15 0.00 99.40
Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await svctm %util
sdc 0.00 0.02 1.37 2.91 0.06 0.04 49.58 0.01 3.37 1.33 0.57
@timlinquist
timlinquist / Rails3 defaults
Created April 8, 2011 01:12
Optional in 2.2, defaults in Rails3
# Be sure to restart your server when you modify this file.
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true
end
@timlinquist
timlinquist / Rails3-ExtendController
Created April 14, 2011 23:08
A beautiful hack to extend Rails to allow custom actions for a controller instance & helpers for thew view.
def self.extended(controller)
controller.extend(ControllerMethods)
controller._helpers.module_eval { include HelperMethods }
existing_actions = controller.action_methods + ControllerMethods.public_instance_methods(true)
controller.class.class_eval do
cattr_accessor :actions_to_use
def self.override_action_methods(actions=[])
self.actions_to_use = actions
@timlinquist
timlinquist / gist:934929
Created April 21, 2011 16:31
Block with local scope
my_big_array = (0..10000000000000).to_a
object= some_object.new do
#Do some stuff
#Save block for later use
end
#Block holds a reference to my_big_array until it goes away
@timlinquist
timlinquist / monkey_patches.rb
Created April 21, 2011 19:01
Monkey patching examples
Inheritance
app/models/page.rb L 89 def clone...
(lib | lib/patches)/productize.rb L 62 def clone_with_nil_timestamps....
Composition
app/controllers/balances.rb L 209 def balances_by_industry......
vendor/plugins/to_csv.rb
DIP (Dependency Injection Principle)
lib/patches/extend_client_actions_and_helpers.rb
@timlinquist
timlinquist / theblock.ohhai.com
Created May 17, 2011 17:53
Queries for the block
Started GET "/" for 127.0.0.1 at Tue May 17 10:52:57 -0700 2011
SQL (2.0ms) describe `areas_stores`
SQL (1.4ms) describe `comarketing_pages_stores`
SQL (2.0ms) describe `pages_stores`
SQL (1.9ms) describe `areas_stores`
HERE OPTIONS={}
SQL (2.6ms) SHOW TABLES
HERE OPTIONS={:relationship_name=>:unit_attributes, :class_name=>"SelfStorageUnitAttributes"}
SQL (2.5ms) SHOW TABLES
Processing by ContentController#index as HTML
@timlinquist
timlinquist / cruise.sh
Created May 18, 2011 19:34
cruise control not restarting
g5search@sancho:/data/cruisecontrolrb/current$ ./cruise start
=> Booting WEBrick
=> Rails 2.3.2 application starting on http://0.0.0.0:3333
cruise data root = '/home/g5search/.cruise'
./lib/cruise_control/../../script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:99:in `requirement': undefined local variable or method `version_requirements' for #<Rails::GemDependency:0xb6f7e8b8> (NameError)
from /home/g5search/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/site_ruby/1.8/rubygems.rb:254:in `activate'
from /home/g5search/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/site_ruby/1.8/rubygems.rb:1204:in `gem'
from ./lib/cruise_control/../../script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:57:in `add_load_paths'
from ./lib/cruise_control/../../script/../config/../vendor/rails/railties/lib/initializer.rb:299:in `add_gem_load_paths'
from ./lib/cruise_control/../../script/../config/../vendor/rails/railties/lib/initializer.rb:299:in `each'
function jQueryLoaded(){
return (typeof(jQuery) != 'undefined');
}
if(jQueryLoaded()){
console.log('WTF jQuery?');
$('document').ready(function(){
jquery_link_to();
});
@timlinquist
timlinquist / gist:1019588
Created June 10, 2011 19:31
SAVE THE WORLD REMIX!!!
namespace :gts do
desc "get source of lead for client"
task(:source_for_client_lead => :environment) do
start_date = ENV['start_date'] || Date.parse('2011-01-01')
client_id = ENV['client_id'] || 1003
lead_types = LeadType.all(:select=>'id, name')
lead_types_by_id = {}
lead_types.each{|lead| lead_types_by_id[lead.id] = lead_types_by_id.name }
@timlinquist
timlinquist / gist:1054511
Created June 29, 2011 18:25
/engineyard/bin/unicorn not using bundle exec for rack apps
We couldn’t find that file to show.