Skip to content

Instantly share code, notes, and snippets.

View hammerdr's full-sized avatar

Derek Hammer hammerdr

View GitHub Profile
@hammerdr
hammerdr / what_i_have_to_do.rb
Created February 26, 2012 04:58
Rails PRO vs AR
class PRO
def self.create a, b, c
obj = build(a, b, c)
obj.save
obj
end
def self.build a, b, c
Model.new params(a, b, c)
end
@hammerdr
hammerdr / gist:1868144
Created February 20, 2012 06:35
Hammer's Code Critique Rules
1. We evaluate the code from the beginner's perspective. We can assume
mediocre Ruby and mediocre Rails knowledge but we try to look at the
code as if it is the first time we have seen it. This allows us to try
to bring fresh perspectives to the code (and, hopefully, improve the
code for people that are reading it for the first time).
2. As in a retrospective, we assume that everyone involved was doing
the best that they can with the knowledge that they had at the time.
This is not a session to assign blame or to even feel guilty. We are
all trying to improve. That being said, it is expected that the
#!/bin/sh
USER=$(git config --global user.name)
EMAIL=$(git config --global user.email)
if [ -z "$USER" ]; then
echo "Please set your name in your git config:"
echo " git config --global user.name <name>"
exit 1
fi
class User
include Mongoid::Document
field :name
end
users = User.all.cache
users.each { |u| puts u } # Database hit
users.each { |u| puts u } # No database hit
class Post
module First
def hello; "FIRST"; end
end
Speak.send :include, First
@hammerdr
hammerdr / Event.j
Created May 22, 2011 22:17 — forked from Synvox/Event.j
Cappuccino Instance Variables Problem
/*
* Event.j
* Canvas Creator
*
* Created by Ryan on May 21th, 2011.
* Copyright 2011, Synvox rights reserved.
*/
@import <Foundation/CPObject.j>
@import <AppKit/CPView.j>
def create
@receipt = Receipt.new(
... (several params here)
:store => Store.find_or_create_by_name(params[:receipt][:store_name])
... (more fucking parameters here))
end
- (id)init
{
...
loginController = [LoginController createWithDelegate:self];
...
var controllers = [loginController, stepOneController, stepTwoController];
[bodyView addSubview:[loginController view]];
...
}
DH6256s-MacBook-Pro:~ ThoughtWorks$ rvm install rbx
rbx-1.1.0-20100923 installing #dependencies
rbx-1.1.0-20100923 #downloading (rubinius-1.1.0-20100923.tar.gz), this may take a while depending on your connection...
rbx-1.1.0-20100923 - #extracting
rbx-1.1.0-20100923 - #configuring
rbx-1.1.0-20100923 - #compiling
Error running '/Users/ThoughtWorks/.rvm/wrappers/ruby-1.8.7-p302/rake install', please check /Users/ThoughtWorks/.rvm/log/rbx-1.1.0-20100923/rake.error.log
There has been an error while running '/Users/ThoughtWorks/.rvm/wrappers/ruby-1.8.7-p302/ruby ./configure --prefix=/Users/ThoughtWorks/.rvm/rubies/rbx-1.1.0-20100923 --skip-system'.
Halting the installation.
DH6256s-MacBook-Pro:~ ThoughtWorks$ more ~/.rvm/log/rbx-1.1.0-20100923/rake.error.log
var methods = [];
for(var i = 0; i < 10; i++)
{
methods.push(function() {
require("system").print(i);
});
}
for(var k = 0; k < 10; k++)