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 / gist:3802268
Created September 28, 2012 21:52
Migration Functions #rails #migration #db
def change
add_column :table_name, :column_name, :column_type, default: 'default value'
remove_column :table_name, :column_name
rename_column :table_name, :old_name, :new_name
change_column :table_name, :column_name, :column_type
end
@acidlabs-snippets
acidlabs-snippets / app.conf
Created October 1, 2012 14:21
nginx config for thin #server #nginx #thin
upstream app_name {
server 127.0.0.1:4000; #port examples
server 127.0.0.1:4001;
}
server {
server_name example.com;
listen 80;
access_log <acces_log_path>;
error_log <error_log_path;
@acidlabs-snippets
acidlabs-snippets / pre-commit
Created October 3, 2012 18:42
#GIT #Hook #tests
#!/usr/bin/env ruby
#
tests = [
{:name => "RSPEC", :command => "rake spec"},
{:name => "JASMINE", :command => "jasmine-headless-webkit --color"}
]
tests.each do |test|
puts "\e[33mEXECUTING #{test[:name]} TESTS\e[0m"
test[:result] = system test[:command]
@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"
@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 / 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 / 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 / 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 / .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 / .bashrc
Created October 17, 2012 21:53
Nice to have .bashrc
#------------------------------------------------------------------------------
# Returncode.
#------------------------------------------------------------------------------
function returncode
{
returncode=$?
if [ $returncode != 0 ]; then
echo "[$returncode]"
else
echo ""