Skip to content

Instantly share code, notes, and snippets.

View acidlabs-snippets's full-sized avatar

acidlabs-snippets

View GitHub Profile
@acidlabs-snippets
acidlabs-snippets / acid-template.rb
Created January 13, 2013 04:58
Rails application template
# acid-template.rb
git :init
gitignore = run("curl https://gist.github.com/raw/3875160/5d2745ee9bcae0bb4addf4bc701d3fa9a48ce187/.gitignore")
file ".gitignore", gitignore
if yes?("Do you use RVM? (yes|no")
if yes?("Do you want to create a .rvmrc file for the project? (yes|no)")
# RVM
current_ruby = %x{rvm list}.match(/^=>\s+(.*)\s\[/)[1].strip
desired_ruby = ask("Which RVM Ruby would you like to use? [#{current_ruby}]")
@acidlabs-snippets
acidlabs-snippets / rspec_database_cleaner.rb
Created December 3, 2012 19:32
Rspec Database Cleaner
# Gemfile
group :test do
gem "database_cleaner"
end
# spec/support/database_cleaner.rb
RSpec.configure do |config|
DatabaseCleaner.strategy = :truncation
config.before(:each) do
@acidlabs-snippets
acidlabs-snippets / rspec_devise.rb
Created December 3, 2012 18:52
Rspec Devise - Sign In User
# spec/spec_helper.rb
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# spec/support/devise.rb
RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
end
# spec/controllers/whatever/controller/that/needs/authentication.rb
before :each do
@acidlabs-snippets
acidlabs-snippets / .bashrc
Created October 17, 2012 21:53
Nice to have .bashrc
#------------------------------------------------------------------------------
# Returncode.
#------------------------------------------------------------------------------
function returncode
{
returncode=$?
if [ $returncode != 0 ]; then
echo "[$returncode]"
else
echo ""
@acidlabs-snippets
acidlabs-snippets / .gitignore
Created October 11, 2012 20:06
.gitignore for Rails project
#----------------------------------------------------------------------------
# Ignore these files when commiting to a git repository
#
# The original version of this file is found here:
# https://github.com/RailsApps/rails3-application-templates/raw/master/files/gitignore.txt
#
# Corrections? Improvements? Create a GitHub issue:
# http://github.com/RailsApps/rails3-application-templates/issues
#----------------------------------------------------------------------------
@acidlabs-snippets
acidlabs-snippets / pg_dump.txt
Created October 11, 2012 17:40
PostgresSQL binary dump command #postgresql #dump
pg_dump -Fc | gzip -9 -c > dumpfile.gz
@acidlabs-snippets
acidlabs-snippets / revision.rb
Created October 10, 2012 16:15
Git Revision Middleware
# lib/rack/revision.rb
module Rack
class Revision
@@revision = nil
File = ::File
def initialize(app, &block)
@app = app
@block = block
@file = File.join(Dir.pwd, 'REVISION')
@acidlabs-snippets
acidlabs-snippets / wkhtmltopdf.txt
Created October 4, 2012 20:37
Install wkhtmltopdf 64 bit binary #pdf
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf
@acidlabs-snippets
acidlabs-snippets / capistrano.rb
Created October 4, 2012 16:15
Rails 3.1+ Multistage deployment with Capistrano #rails #deployment #capistrano
### This gist outlines a generic implementation of multistage deployment with Capistrano for Rails 3.1+.
#
# Usage:
#
# cap #{stage} deploy:setup
# cap #{stage} deploy:cold
# cap #{stage} deploy
#
# etc.
@acidlabs-snippets
acidlabs-snippets / gist:3829167
Created October 3, 2012 19:19
Softdelete for Rails models #rails #softdelete
module ModuleName
extend ActiveSupport::Concern
module InstanceMethods
def destroy
run_callbacks :destroy do
if self.respond_to? :deleted
self.deleted = true
self.save(validate: false)
else
raise "deleted attribute not found in model"