# This is what an application build with our framework would look like. # Run with: # rackup app.ru ...
<%= (@post.category ? @post.category.name : '') + ' ' + link_to(@post.title, post_path(@post)) %>
Ruby Handling nil object
@post.category can be nil, ...
tab() # new tab from current dir
{
osascript -e "
...
Bash Open a new tab in current d...
by macournoyer,
October 04, 2007 18:07,
2 refactorings
Here's a small script I wro...
var Rating = Class.create();
Rating.prototype = {
initialize: function(element, rating, options) {
...
JavaScript Rating system for this site
by macournoyer,
September 29, 2007 14:09,
3 refactorings
Here's the code of the rati...
Ruby On Random pronouncable password
by macournoyer,
September 29, 2007 13:49
Nice jonathantan86 && Point...
class CssObj < Struct.new(:selector, :attributes)
def self.read(filename)
File.read(filename).split(/\}/m).map { |token| CssObj.new(*token.split(/\{/m)) }
...
Ruby On Extracting style from a CSS...
by macournoyer,
September 29, 2007 13:45
Nice one hungryblank! Here ...
Ruby On restful_authentication role...
by macournoyer,
September 27, 2007 12:30
I don't think you need the ...
def self.requires_role(role, options={})
before_filter(options) { logged_in? && current_user.send("#{role}?") ? true : access_denied }
end
...
Ruby On restful_authentication role...
by macournoyer,
September 27, 2007 10:45
Really good idea James, but...
task :extract_style do
css = File.read 'public/stylesheets/code.css'
css.gsub! "{\n", '{'
...
Ruby Extracting style from a CSS...
by macournoyer,
September 25, 2007 21:18,
2 refactorings
Here's a Rake task I use to...
def code puts 'cool' ...
JavaScript On Is this year a leap year?
by macournoyer,
September 23, 2007 13:13
Nice tip Gary! I didn't kno...
class CodeFormatter cattr_reader :syntaxes @@syntaxes = Uv.syntaxes.sort ...
Ruby [FEATURE] Sections in code!
by macournoyer,
September 22, 2007 08:44,
No refactoring
Introducing a new feature: ...
JavaScript On Is this year a leap year?
by macournoyer,
September 21, 2007 08:20
I'll try to add sections wi...
def link_to_remote_with_spinner(title, options)
element_id = options.delete(:id) || ('link_to_' + title.underscore.tr(' ', '_'))
container_id = options.delete(:container_id) || element_id
...
Ruby On link_to_remote_with_spinner
by macournoyer,
September 21, 2007 07:42
With the above code you cou...
Dir["test/**/*_test.rb"].size.to_f / Dir["app/**/*.rb"].size.to_f
Ruby On Test file to code file ratio
by macournoyer,
September 21, 2007 07:34
Nice! Or even shorter, with...
Object.extend(Date.prototype, {
isLeap: function(){
var year = this.getFullYear();
...
JavaScript On Is this year a leap year?
by macournoyer,
September 21, 2007 07:30
I'm pretty sure the last ye...
puts `find test/ -name "*_test.rb" | wc -l`.to_f / `find app/ -name "*.rb" | wc -l`.to_f
Ruby Test file to code file ratio
by macournoyer,
September 20, 2007 09:19,
3 refactorings
Hackish script to get the t...
# With polymorphic URLs you could do url_for(items.parents + [item])
Ruby On Linking that doesn't suck a...
by macournoyer,
September 20, 2007 08:28
In edge Rails there's polym...

I'll be presenting http://r...