Skip to content

Instantly share code, notes, and snippets.

View dgilperez's full-sized avatar
🌊
Build that!

David Gil dgilperez

🌊
Build that!
View GitHub Profile
module Paperclip
class Geometry
def self.from_file file
parse("100x100")
end
end
class Thumbnail
def make
src = Test::FileHelper.fixture_file('white_pixel.jpg')
dst = Tempfile.new([@basename, @format].compact.join("."))
@rgo
rgo / gist:1173243
Created August 26, 2011 11:36 — forked from diecrf/gist:1170410
Delete unused images in a rails project
images = Dir.glob('public/images/*')
images.each do |image|
unless File.directory?(image)
puts "Checking #{image}..."
if IO.popen("ack-grep -1 -G '(app|public)' --ruby --html --css #{File.basename(image)}").eof?
IO.popen("svn delete #{image}")
puts " Deleted"
end
end
@tddium
tddium / capybara_debug.rb
Created November 16, 2011 19:54
Trap Capybara Stack Trace
### Show stack trace for 500 errors
### (adapted from https://gist.github.com/1079020)
# Given an application, yield to a block to handle exceptions
class ExceptionRaiserApp
def initialize(app)
@app = app
end
def call(env)
@bsodmike
bsodmike / gist:1698390
Created January 29, 2012 11:32
git diff between Rails 3.2.0 and Rails 3.1.0 generated apps
diff --git a/.gitignore b/.gitignore
index 923b697..eb3489a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,15 @@
-.bundle
-db/*.sqlite3
-log/*.log
-tmp/
-.sass-cache/
@chsh
chsh / appapp_delegate.rb
Created May 10, 2012 08:41
RubyMotion Localization sample.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
alert = UIAlertView.new
alert.message = t('start')
alert.show
true
end
def t(key)
NSBundle.mainBundle.localizedStringForKey(key, value:nil, table:nil)
@ParkinT
ParkinT / uilabel_adjustable.rb
Created July 8, 2012 04:28
RubyMotion class to auto-size font for text in a multi-line UILabel
class UILabel_Adjustable
# Borrowed and modified the excellent example at http://www.11pixel.com/blog/28/resize-multi-line-text-to-fit-uilabel-on-iphone/
# adapting it for RubyMotion
# This applies only to a multi-line label. You can use '.adjustsFontSizeToFitWidth = true' for a single-line label
# usage is:
# text = "It's bad luck to be superstitious"
# text_label = UILabel.alloc.initWithFrame([[20, 20], [70, 120]])
# text_label.numberOfLines = 0 # set 0 for word wrap
# text_label.lineBreakMode = UILineBreakModeWordWrap
@jrochkind
jrochkind / gist:4342817
Created December 20, 2012 03:48
Still SimpleDelegator based Decorator, but with an ActionView::Context view_context passed in too
require 'delegate'
class Base
def foo
"foo"
end
def bar
"bar"
end
end
@felipeelias
felipeelias / spec_helper.rb
Last active December 10, 2015 17:48
Simple 'database cleaner' approach using `config.around`. Was able to cut down some seconds out of the suite. Thanks to @brandonhilkert
RSpec.configure do |config|
config.around do |example|
# For examples using capybara-webkit for example.
# Remove this if you don't use it or anything similar
if example.metadata[:js]
example.run
ActiveRecord::Base.connection.execute("TRUNCATE #{ActiveRecord::Base.connection.tables.join(',')} RESTART IDENTITY")
else
ActiveRecord::Base.transaction do
@dhenze
dhenze / bootstrap-typeahead.js
Created January 10, 2013 13:55
This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions. For example, process typeahead list asynchronously and return objects This is an adoption of gudburgurs gist to Version 2.2.2 of Bootstrap. See https://gist.github.com/1866577
/* =============================================================
* bootstrap-typeahead.js v2.2.2
* http://twitter.github.com/bootstrap/javascript.html#typeahead
* =============================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@ankane
ankane / README.md
Last active December 14, 2015 03:39 — forked from panthomakos/benchmark.rb

Benchmark Bundler

Because loading gems can take longer than you think

Now available as a gem - get it here