Skip to content

Instantly share code, notes, and snippets.

View ilpoldo's full-sized avatar

Leandro Pedroni ilpoldo

  • Double Negative
  • London, UK
View GitHub Profile
@ilpoldo
ilpoldo / config.ru
Created September 1, 2012 17:31 — forked from granth/config.ru
# Rack file for local Rubygems server, using YARD
require "rubygems"
require "yard"
libraries = {}
Gem.source_index.find_name('').each do |spec|
libraries[spec.name] ||= []
libraries[spec.name] << YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)
end
@invalid_user = Factory.create(:user)
@invalid_user.stub(:valid?).and_return(false)
User.stub(:new).and_return(@invaild_user)
post :create, :user_name => "some user name that won't even be used"
@ilpoldo
ilpoldo / paperclip.rb
Created February 27, 2010 13:22 — forked from stympy/paperclip.rb
mongomapper paperclip
module Paperclip
module ClassMethods
def has_attached_file name, options = {}
include InstanceMethods
write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil?
attachment_definitions[name] = {:validations => []}.merge(options)
after_save :save_attached_files
before_destroy :destroy_attached_files
@ilpoldo
ilpoldo / .bashrc
Created February 26, 2010 11:40 — forked from henrik/.bashrc
Prompt when git branch is dirty
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
@ilpoldo
ilpoldo / image.rb
Created February 24, 2010 18:37 — forked from bhauman/image.rb
class Image < ActiveRecord::Base
before_create, :set_width_and_height
has_attached_file :img,
:url => "/system/images/:attachment/:id/:basename.:extension",
:path => "#{Rails.root}/public/system/images/:attachment/:id/:basename.:extension"
def set_width_and_height
# this next line is the magic line
geo = Paperclip::Geometry.from_file(img.to_file(:original))
@ilpoldo
ilpoldo / factories.rb
Created February 21, 2010 22:54 — forked from kris/factories.rb
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end