Skip to content

Instantly share code, notes, and snippets.

View gustin's full-sized avatar
🦁
Happy

gustin gustin

🦁
Happy
View GitHub Profile
require 'rubygems'
require 'open-uri'
vids = []
f = open('http://feeds.feedburner.com/Rubyconf2008-Confreaks')
f.each do |l|
l =~ /enclosure url=\"([^\"]+)"/
vids << $1
end
vids.compact!.uniq!
require "rubygems"
require "hpricot"
require "open-uri"
url = "http://feeds.feedburner.com/Rubyconf2008-Confreaks"
(Hpricot(open url)/:enclosure).map {|x| x.attributes["url"]}.uniq.each do |vid|
filename = vid.gsub(/http:.+\//, '')
filename.gsub!(/-/, "_")
next if File.exist?(filename)
@gustin
gustin / gist:41505
Created December 30, 2008 04:04 — forked from damon/gist:41453
def whack(objects)
result = {}
objects.each do |o|
result[o.send("table_name")] = o.send("delete_all")
end
result
end
<div class="bigroundbox">
<div class="boxcontainer">
<table cellspacing="0" cellpadding="0" class="shoptable">
<tr>
<th class="prodcol">Power Supply:</th>
<th class="standcol">Quantity</th>
<th class="standcol">Price</th>
<th class="standcol">Total</th>
<th class="standcol"></th>
</tr>
# Run rake db:size to get a print of your database size in bytes.
# Run rake db:tables:size to get the sizes for individual tables
# Works for MySQL and PostgreSQL. Not tested elsewhere.
namespace :db do
desc 'Print data size for entire database'
task :size => :environment do
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database]
adapter = ActiveRecord::Base.connection.adapter_name.downcase
# # Be sure to install mustache gem and include mustache gem in project Gemfile.
#
# # Template Handler
require 'mustache_rails'
# Generator
Rails.application.config.generators.template_engine :mustache
module MustacheRailsPatch
# Overwrite render to have it render haml first when a template with .haml extension exist
@gustin
gustin / 0-readme.md
Created January 31, 2012 01:03 — forked from burke/0-readme.md
ruby-1.9.3-p0 cumulative performance patch.

Patched ruby 1.9.3-p0 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p0 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).

Huge thanks to funny-falcon for the performance patches.

@gustin
gustin / config.ru
Created March 3, 2012 09:14
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
require "rails"
@gustin
gustin / vim7.3_mac_install.rb
Created March 13, 2012 15:40 — forked from pengwynn/vim7.3_mac_install.rb
Script to install Vim 7.3 with ruby support for Mac OS X Lion
# requires root permissions in /usr/bin/
star = String.new
8.times { star += "*" }
Star = "\n#{star * 3}\n"
def newblock string
puts "\n#{Star}#{string}#{Star}\n"
end

Inheritance is a key concept in most object-oriented languages, but applying it skillfully can be challenging in practice. Back in 1989, M. Sakkinen wrote a paper called Disciplined inheritance that addresses these problems and offers some useful criteria for working around them. Despite being more than two decades old, this paper is extremely relevant to the modern Ruby programmer.

Sakkinen's central point seems to be that most traditional uses of inheritance lead to poor encapsulation, bloated object contracts, and accidental namespace collisions. He provides two patterns for disciplined inheritance and suggests that by normalizing the way that we model things, we can apply these two patterns to a very wide range of scenarios. He goes on to show that code that conforms to these design rules can easily be modeled as ordinary object composition, exposing a solid alternative to tradi