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 / 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))
@r3ap3r2004
r3ap3r2004 / thubmnail_with_dimensions.rb
Created March 25, 2010 15:37
Paperclip processor to save dimensions of an image
# Filename: RAILS_ROOT/lib/paperclip_processors/thumbnail_with_dimensions.rb
# Required Configuration in the model
# has_attached_file :image,
# :styles => {
# :thumbnail => {
# :geometry => "100x100>",
# :format => :png,
# :processors => [:thumbnail_with_dimensions],
# :mystyle => :thumbnail
# },
@saimonmoore
saimonmoore / Gemfile
Created March 26, 2010 12:12 — forked from lifo/Gemfile
CRAMP Websocket example
gem 'cramp'
gem 'erubis', '2.6.5'
gem 'usher', "0.6.0"
Package: require('node-asset').Package
# Coffee files
coffee_package: new Package 'where/you/want/output.js', [
'where/is/coffee/dir'
'or/file.coffee'
'coffee/type/also/support/file.js'
], {
type: 'coffee'
# Watch for changes
@paulelliott
paulelliott / integration_example_group.rb
Created July 7, 2010 03:32
RSpec Integration Example Group for Capybara
require 'action_dispatch'
require 'capybara/rails'
require 'capybara/dsl'
module RSpec::Rails
module IntegrationExampleGroup
extend ActiveSupport::Concern
include ActionDispatch::Integration::Runner
include RSpec::Rails::TestUnitAssertionAdapter
@ilpoldo
ilpoldo / templator.rb
Created September 2, 2010 14:30
My rails 3 app template
# Cleaning up and extending the Gemfile
remove_file 'Gemfile'
create_file 'Gemfile', <<-GEMFILE
source 'http://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# 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
#!/usr/bin/env ruby
if ARGV.size < 2
puts "Usage: #{$0} <src dir> <dest dir> [branch name]"
puts " CAUTION! Running without a branch name, it will try to copy all 'local' branches, but this is probably not what you want, and is untested. Copy just those branches you really need."
exit
end
src_repo = File.expand_path(ARGV[0])
dest_repo = File.expand_path(ARGV[1])
require 'usb'
require 'betabrite'
###
# Get a betabrite sign:
#
# http://www.betabrite.com/
# http://www.amazon.com/Brite-Prism-Moving-Message-Display/dp/B000MQAI72
#
# Install gems:
@asengupta
asengupta / MapReduceBlockMatrixProduct.rb
Created November 11, 2011 01:28
MapReduce version of matrix multiplication using recursive block matrix decomposition
require 'rubygems'
require 'matrix'
require './matrix_block_mixin'
require './map_reduce'
require 'benchmark'
def map(key, value)
inputs = []
a = value[:a]
b = value[:b]