This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I want to turn this into a programming contest. Everyone should do this using their favorite technique and language. But, I want to add three more challenges (that admittedly stack the deck in my favor). | |
1. create a stats collecting query decorate that measures the time it takes to execute the query | |
(assume you have a stats object that responds to #measure and takes a block: stats.measure { sleep 1.second } | |
2. read "configuration" from a hash like: | |
{ :timeout => 1.second, :stats => true } | |
that adds the timeout and stats decorators to the factory if present in the hash, otherwise not. | |
3. at the end write a program that REVERSES the order of the decorators. So if you did Timeout(Stats(Query)) make it Stats(Timeout(Query)). Note that you must do this programmatically so write a generic decorator reversing function. You may expand the proxy interface to have a method called "underlying", "delegate" or some such. | |
The contest is: do this in your language in as "elegant" a way as you like. The goal is clarity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ParameterizedConcern | |
def extended(mod = nil, &block) | |
unless mod | |
@extended_block = block | |
return | |
end | |
mod.module_eval(&@extended_block) if @extended_block | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Blog post at | |
# http://pivotallabs.com/users/rolson/blog/articles/1162-redefine-a-method-from-a-module-like-a-gentleman | |
module Teacher | |
def self.included(base) | |
base.extend ClassMethods | |
base.overwrite_initialize | |
base.instance_eval do | |
def method_added(name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Newbie Programmer | |
def factorial(x) | |
if x == 0 | |
return 1 | |
else | |
return x * factorial(x - 1) | |
end | |
end | |
puts factorial(6) | |
puts factorial(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The following is a simple program to check for memory corrections in | |
* DRAM with ECC switched off. Accordingly to recend large scale studies | |
* such as http://www.cs.toronto.edu/~bianca/papers/sigmetrics09.pdf | |
* the error rate is of 25,000-75,000 errors per billion hours per Mbit. | |
* | |
* If this is true you should see at least one error after a few days | |
* running this program at max in a computer without ECC. | |
* | |
* Compile with: gcc -O2 -Wall -W -o dramerr dramerr.c | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- ruby -*- | |
require 'rubygems' | |
require 'daemon-spawn' | |
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) | |
class DelayedJobWorker < DaemonSpawn::Base | |
def start(args) | |
ENV['RAILS_ENV'] ||= args.first || 'development' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Critical default settings: | |
disable_system_gems | |
disable_rubygems | |
bundle_path ".gems/bundler_gems" | |
# List gems to bundle here: | |
gem "rails", "3.0.pre", :git => "git://github.com/rails/rails.git" | |
gem "arel", :git => "git://github.com/rails/arel.git" | |
gem "i18n" | |
gem "dm-appengine" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Critical default settings: | |
disable_system_gems | |
disable_rubygems | |
bundle_path ".gems/bundler_gems" | |
# List gems to bundle here: | |
gem "rails", "3.0.pre", :git => "git://github.com/rails/rails.git" | |
gem "arel", :git => "git://github.com/rails/arel.git" | |
gem "i18n" | |
gem "dm-appengine" |