Skip to content

Instantly share code, notes, and snippets.

@scharfie
scharfie / gemspec-usage.md
Created February 27, 2012 13:36
test/spec/mini

Just install this in your apps like so:

gem 'test-spec-mini', :git => 'git://gist.github.com/1806986.git', :require => 'mini'

@scharfie
scharfie / gist:1574577
Created January 7, 2012 12:01
password-protect staging server
# config/environments/staging.rb
# Credit: http://olemortenamundsen.wordpress.com/2011/04/05/ruby-secure-staging-environment-of-your-public-app-from-users-and-bots/
MyApp::Application.configure do
config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Staging") do |username, password|
[username, password] == ['username', 'password']
end
end
@scharfie
scharfie / gist:1038368
Created June 21, 2011 17:21
how to install mysql gem
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -v 2.7 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr
@scharfie
scharfie / yaml.vim
Created May 16, 2011 11:11 — forked from iangreenleaf/yaml.vim
Dumb-smart indentation for Yaml
" Vim indent file
" Language: Yaml
" Author: Ian Young
if exists("b:did_indent")
finish
endif
"runtime! indent/ruby.vim
"unlet! b:did_indent
let b:did_indent = 1
# Factory girl, relaxed.
#
# Factory.define :user do |f|
# f.login 'johndoe%d' # Sequence.
# f.email '%{login}@example.com' # Interpolate.
# f.password f.password_confirmation('foobar') # Chain.
# end
#
# Factory.define :post do |f|
# f.user { Factory :user } # Blocks, if you must.
@scharfie
scharfie / gist:764709
Created January 4, 2011 12:12
Bookmarklet for skipping annoying Steam age-check
javascript:(function(){document.cookie='birthtime=-2000000000; expires=Wed, 1 Jan 2020 00:00:00 UTC; path=/';document.location=document.location})();
namespace :db do
task :rebuild => ['db:drop', 'db:create', 'db:migrate']
namespace :test do
task :rebuild => :environment do
RAILS_ENV = 'test'
ActiveRecord::Base.establish_connection(:test)
Rake::Task['db:rebuild'].invoke
end
end
@scharfie
scharfie / gist:309412
Created February 20, 2010 01:08 — forked from dburger/gist:28214
# modifications from standard capistrano deploy as taken from:
# http://devthatweb.com/view/deploy-any-project-using-capistrano-2
set :application, "name removed"
set :repository, "url to trunk of repo"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/var/www/#{application}"
# A very simplistic "presenter" implementation. It works by simply extending
# an object with a presenter module
# presenter.rb
module Presenter
def self.for_class(klass)
Object.const_get(klass.name + 'Presenter') rescue nil
end
# extends the given record with the presenter module for the object type
module SortableBy
module ClassMethods
# defines a 'sorted_by' named scope, which accepts a column name and optional direction
# example: sortable_by :columns => %w(id name)
# usage: SomeModel.sorted_by('name', 'asc')
def sortable_by(options)
class_eval "def self.sortable_columns; #{options[:columns].inspect}; end"
named_scope :sorted_by, Proc.new { |column, direction|
if sortable_columns.include?(column)