Skip to content

Instantly share code, notes, and snippets.

@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
Processing UserSessionsController#create (for 127.0.0.1 at 2010-11-01 14:12:23) [POST]
Parameters: {"action"=>"create", "authenticity_token"=>"rB6dLcQC55xOHF5Bl3R1/0Y3mqRSkZwYB6q7tyjhu0M=", "controller"=>"user_sessions", "login"=>"dce", "password"=>"[FILTERED]"}
User Load (14.4ms) SELECT * FROM `users` WHERE (`users`.`pseudo_user_token` = '05505517a648f628c45da6d97ece48ead0b21519') LIMIT 1
insider UserSessions#create
User Load (0.4ms) SELECT * FROM `users` WHERE (LOWER(`users`.login) = 'dce') LIMIT 1
SQL (0.1ms) BEGIN
Speaker Columns (1.6ms) SHOW FIELDS FROM `speakers`
Speaker Load (0.4ms) SELECT * FROM `speakers` WHERE (`speakers`.`id` = 2) AND (speakers.is_spam = 0 OR NULL)
User Update (0.3ms) UPDATE `users` SET `updated_at` = '2010-11-01 14:12:23', `perishable_token` = 'wizLh57sve3jPaAJBw', `last_login_at` = '2010-11-01 14:10:21', `current_login_at` = '2010-11-01 14:12:23', `login_count` = 4, `last_request_at` = '2010-11-01 14:12:23' WHERE `id` = 2
SQL (0.6ms) COMMIT
@dce
dce / given.rb
Created October 27, 2010 13:46
class Object
def given(meth)
yield self if send(meth)
end
end
Hi user33!
Here's what's been happening with your SpeakerRate profile lately.
You were added as a speaker to 2 talks:
* "TDD" (http://speakerrate.test/talks/1126-tdd)
* "TDD" (http://speakerrate.test/talks/1127-tdd)
New ratings on your talks: