Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile
@wtaysom
wtaysom / where_is.rb
Created September 23, 2011 08:57
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))
@teddyzetterlund
teddyzetterlund / dead-center.css
Created December 10, 2011 19:28
CSS utility classes
/**
* Dead center an image both vertically and horizontally inside
* a containing element.
*
* Notes:
* The dead-center container needs height and width set,
* and the image to be centered can't exceed those dimenstions.
*
* Example:
* <div class="example dead-center">
@kagemusha
kagemusha / gist:1569836
Created January 6, 2012 09:20
Dump Heroku Postgres DB and load locally
Get the Heroku db as detailed here:
http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup
1. heroku pgbackups:capture
2. heroku pgbackups:url <backup_num> #=>backup_url
- get backup_num with cmd "heroku pgbackups"
3. curl -o latest.dump <backup_url>
Then locally do:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
@joakimk
joakimk / controller.rb
Created February 17, 2012 10:40
A way to lazy load partials in Rails 3
class Controller
include LazyLoad
def show
@model = Model.find(...)
respond_to do |format|
format.html do
@html_specific_data = Model.find(...)
end
@coreyhaines
coreyhaines / .rspec
Last active April 11, 2024 00:19
Active Record Spec Helper - Loading just active record
--colour
-I app
@wrburgess
wrburgess / gist:2086949
Created March 19, 2012 00:20
Setting up New Relic for Sinatra on Heroku #newrelic #sinatra #heroku
@avdi
avdi / apology101.markdown
Created March 22, 2012 17:36
How to apologize

Chances are your head's spinning right now. That accusation of bias caught you off guard, you got kind of defensive, and now all hell has broken loose. You're feeling attacked on all sides. You're a good person at heart, and having all these people treat you like the antichrist is pretty upsetting.

You need to say something, but you're probably not in the best headspace to write copy right now. So to help you along, here's my 100% guaranteed-or-you-money-back scandal defusement apology template:

@swrobel
swrobel / gemfile_changelog.rb
Created March 23, 2012 01:21
Get Changelogs for outdated gems in Gemfile
#!/usr/bin/env ruby
def changelog_for_gem(gem)
changelogs = `bundle exec gem contents #{gem}`.lines.grep(/history|changelog|news/i)
if changelogs.empty?
puts "No changelog found for gem #{gem}"
return nil
end
@joakimk
joakimk / script-bootstrap.rb
Created March 31, 2012 10:01
Bootstrap script (script/bootstrap) from a small rails project I'm working on. Designed to be quick to run when nothing changed. Intended to be used in CI builds and on dev machines.
$ time script/bootstrap
Bundler missing, installing.
Fetching: bundler-1.1.3.gem (100%)
Successfully installed bundler-1.1.3
1 gem installed
Gemfile changed, bundling.
Schema changed, updating databases.
real 0m9.163s
user 0m3.762s
@peterhellberg
peterhellberg / Gemfile
Created April 10, 2012 11:51
Sinatra acceptance testing, using minitest/spec and capybara-webkit
source :rubygems
gem "sinatra", "~> 1.3.2"
group :test do
gem "minitest", "~> 2.10"
gem "rack-test", "~> 0.6.1"
gem "capybara", "~> 1.1"
gem "capybara-webkit", "~> 0.11"
gem "capybara_minitest_spec", "~> 0.2"