Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
files = `grep -lir :focus spec`.split(/\n/) - ["spec/spec_helper.rb"]
if files.any?
puts "FOCUS: #{files.inspect}"
exit 1
end
<% list_items_for @products do |product| %>
<%= link_to product.name, product %>
<% end %>
<!--
<li class="first"><a href="/products/1">Product #1</a></li>
<li><a href="/products/2">Product #2</a></li>
<li class="last"><a href="/products/3">Product #3</a></li>
-->

Rails 3.1 Asset Pipeline

  • The new asset pipeline in Rails 3.1 makes assets first class citizens in Rails
  • Assets now in app/assets rather than public (also lib/assets, vendor/assets)
  • Asset files can inline other asset files using requires
  • Asset packages are defined in manifests
/*
@dce
dce / clone.js
Created September 4, 2011 21:44
var util = require("util");
var clone = function(obj) {
var f = function() { };
f.prototype = obj;
return new f;
};
var person = {
name: "Person",
@dce
dce / fold.io
Created June 22, 2011 21:17
Even though it already has `reduce`...
my_fold := method(list, coll, lambda,
if (list size == 0) then (
return coll
) else (
return fold(list rest,
lambda call(coll, list first),
lambda)
)
)
@dce
dce / closure.io
Created June 22, 2011 13:31
How to make a closure in IO (http://www.iolanguage.com/)
Io> make_adder := method(x, block(y, x + y))
==> method(x,
block(y, x + y)
)
Io> add5 := make_adder(5)
==> method(y,
x + y
)
Io> add5 call(3)
==> 8
@dce
dce / flac2mp3.rb
Created April 12, 2011 03:33
convert a bunch of FLAC files to MP3
require "rubygems"
require "mp3info"
`ls -1 *.flac`.split(/\n/).each do |flac|
filename = flac.gsub("flac", "mp3")
`flac -d -c "#{flac}" | lame - converted/"#{filename}"`
Mp3Info.open("converted/#{filename}") do |mp3|
mp3.tag.title = filename[16..-5]
mp3.tag.artist = "Artist"
@dce
dce / gist:911813
Created April 9, 2011 21:52
Vim for Rails Developers notes
def PostsController < ActionController::Base
def create
@post = Post.new(params[:post])
if @post.save
redirect_to posts_path
else
render :action => "new"
end
end