Skip to content

Instantly share code, notes, and snippets.

View col's full-sized avatar
👨‍💻

Col col

👨‍💻
  • Jiva Ag
  • Melbourne, Australia
View GitHub Profile
@col
col / ubuntu-ruby-192-install
Created April 23, 2012 01:04
Install Ruby 1.9.2 from source (Ubuntu 10.04)
To install ruby 1.9.2 from source quickly just run:
sudo curl https://raw.github.com/gist/2467938/c420a710e78164e4b9443faba8b5e0dd4e5eac16/ubuntu-ruby-192-install | bash
@col
col / import_users.rb
Created August 30, 2012 03:43
Simple rake task to import data from CSV
#
# Taken from "Ten Things You Didn't Know Rails Could Do by James Edward Gray"
# http://www.youtube.com/watch?v=GRfJ9lni4QA
#
require 'csv'
namespace :users do
desc "Import users from a CSV file"
task :import => :environment do
@col
col / commands
Created October 5, 2012 04:45
Fix ruby-1.9.3-p194 Segmentation fault when running bundle install
rvm uninstall ruby-1.9.3-p194
rvm pkg install openssl
rvm install ruby-1.9.3-p194 --with-openssl-dir=~/.rvm/usr
@col
col / passenger
Last active October 11, 2015 10:18
Apache passenger config file contents when using rvm (Edit: updated ruby and passenger versions)
LoadModule passenger_module /home/passenger/.rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
PassengerRoot /home/passenger/.rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19
PassengerRuby /home/passenger/.rvm/wrappers/ruby-1.9.3-p392/ruby
@col
col / controller.rb
Last active December 10, 2015 04:18
Improved scaffold controller generator template. The comments and the json format has been removed and a before filter has been added to fetch the resource. The controller has now also been updated to use the strong parameters gem. This can be added to an existing application at: lib/templates/rails/scaffold_controller/controller.rb
<% if namespaced? -%>
require_dependency "<%= namespaced_file_path %>/application_controller"
<% end -%>
<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApplicationController
include ActiveModel::ForbiddenAttributesProtection
before_filter :find_user, :only => [:show, :edit, :update, :destroy]
@col
col / deploy.rb
Last active February 26, 2019 20:13
Example Capistrano deploy file. This is a basic example that I plan to improve soon. Update 1: Added :admin_runner option to ensure deployment directories are created with the correct owner. Update 2: Added better support for multiple environments and added rails:console rails:dbconsole tasks.
require 'rvm/capistrano'
require 'bundler/capistrano'
require 'capistrano/ext/multistage'
load 'deploy/assets'
set :stages, ["staging", "production"]
set :default_stage, "production"
set :user, '?'
set :admin_runner, '?'
@col
col / backup.rb
Last active December 11, 2015 10:18
Example config/backup.rb file for use with the backup gem
Backup::Model.new(:app_name_backup, 'Backup for App Name') do
database MySQL do |database|
database.name = 'app_name_production'
database.username = 'app_name'
database.password = 'password!'
end
#database PostgreSQL do |database|
# database.name = 'app_name_production'
# database.username = 'app_name'
@col
col / rails.rb
Created January 31, 2013 04:43 — forked from benedikt/rails.rb
# encoding: UTF-8
namespace :rails do
desc "Remote console"
task :console, :roles => :app do
run_interactively "bundle exec rails console #{rails_env}"
end
desc "Remote dbconsole"
task :dbconsole, :roles => :app do
@col
col / gist:4680947
Created January 31, 2013 07:11
Quick command to add my public jey to a remote servers authorized keys.
ssh user@host 'echo '`cat ~/.ssh/id_rsa.pub`' >> ~/.ssh/authorized_keys'
@col
col / gist:4688122
Created February 1, 2013 00:39
Some useful unix commands for managing processes. Basic stuff but very useful.
# List all processes of type for a user
pgrep -u <user> <process name>
# Example:
pgrep -u app_user ruby
# Kill all processes of type for a user
killall -u <user> <process name>