Skip to content

Instantly share code, notes, and snippets.

@iain
iain / smotje.recipe.rdoc
Created July 13, 2009 17:07
Smotje, gerecht van mijn oma, erg lekker!

Smotje

Ingredienten

  • Speklappen

  • Uien

  • Zout

  • Peper

  • Sambal

  • Ketjap

@iain
iain / Automated Vim sessions
Created July 24, 2009 09:15
A piece of vimrc
" Save session and close vim by pressing SQ.
" When you open vim again, without arguments, it opens the saved session.
nmap SQ <ESC>:mksession! ~/.vim/Session.vim<CR>:wqa<CR>
function! RestoreSession()
if argc() == 0 "vim called without arguments
execute 'source ~/.vim/Session.vim'
end
endfunction
@iain
iain / colors.rb
Created August 30, 2009 12:15
CSS colors by name
# CSS colors supported by all major browsers.
# Source: http://www.w3schools.com/CSS/css_colornames.asp
module Colors
extend self
def alice_blue; "#f0f8ff"; end
def antique_white; "#faebd7"; end
def aqua; "#00ffff"; end
def aquamarine; "#7fffd4"; end
def azure; "#f0ffff"; end
@iain
iain / user.rb
Created October 19, 2009 19:05
Weird RSpec issue
1)
'User should get all active users' FAILED
expected any? to return false, got true
./spec/models/user_spec.rb:26:
@iain
iain / gist:243495
Created November 26, 2009 14:47
Using all as a scope
class ActiveRecord::Base
named_scope :all, lambda { |*options| options.first || {} }
end
# This a sample YML file from Rails 2.3. The objective is to propose a yml based on this
# one which will reduce error messsages duplication, as outline in this post:
#
# http://groups.google.com/group/rails-i18n/browse_thread/thread/3085a78831ed8fae
#
# Proposals are available below and also check the forks at the right.
en:
activerecord:
models:
admin: "Admin"
require File.join(File.dirname(__FILE__), 'config', 'environment')
require 'ya2yaml'
module PrettyYaml
class << self
def write(filename, hash)
File.open(filename, "w") do |f|
f.write(yaml(hash))
end
end
@iain
iain / jquery-bind.js
Created January 11, 2010 23:02
bind scopes to callbacks in jQuery
var MyClass = new Function();
MyClass.prototype = {
/**
* bind(Function) -> Function
*
* The problem with jQuery is that jQuery methods change +this+ inside their
* callbacks. This looses your reference to the current object. Pass the
* callback-function to +bind+ and it fixes it for you.
*
# Without Symbol#to_proc
[1, 2, 3].map { |it| it.to_s }
[3, 4, 5].inject { |memo, it| memo * it }
# With Symbol#to_proc
[1, 2, 3].map(&:to_s)
[3, 4, 5].inject(&:*)
# Writing Genesis in Ruby, for http://www.whatdigitalrevolution.com/?p=119
God = "God"
def God.performs &acts
instance_eval &acts
end
def God.create *stuff
"#{self} created #{stuff.join(' and ')}."