Skip to content

Instantly share code, notes, and snippets.

@scottwb
scottwb / application_controller.rb
Created February 17, 2012 06:12
Get a list of all the filters on a given Rails 3 controller.
# Add these methods to your ApplicationController. Then, any controller
# that inherits from it will have these methods and can programmatically
# determine what filters it has set.
class ApplicationController < ActionController::Base
def self.filters(kind = nil)
all_filters = _process_action_callbacks
all_filters = all_filters.select{|f| f.kind == kind} if kind
all_filters.map(&:filter)
end
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@ryanb
ryanb / chef_solo_bootstrap.sh
Created April 5, 2012 04:35
Bootstrap Chef Solo
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
@erlingwl
erlingwl / webserver.rb
Created April 18, 2012 18:27
Chef webserver role
name "webserver"
description "Systems that serve HTTP"
run_list(
"recipe[chef-client]",
"recipe[ssh_known_hosts]",
"recipe[apt]",
"recipe[git]",
"recipe[nginx]",
"recipe[unicorn]"
)
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@benjchristensen
benjchristensen / index.html
Created May 2, 2012 19:34
Simple Line Graph using SVG and d3.js
<html>
<head>
<title>Simple Line Graph using SVG and d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
/* tell the SVG path to be a thin blue line without any area fill */
path {
stroke: steelblue;
stroke-width: 1;
fill: none;
@haf
haf / gist:2843680
Created May 31, 2012 14:19
Get SSH working on Vagrant/Windows/Git

If you are using vagrant, you probably-statistically are using git. Make sure you have its binary folder on your path, because that path contains 'ssh.exe'.

Now, modify C:\vagrant\vagrant\embedded\lib\ruby\gems\1.9.1\gems\vagrant-1.0.3\lib\vagrant\ssh.rb to comment out the faulty Windows check and add a real SSH check:

# if Util::Platform.windows?
  # raise Errors::SSHUnavailableWindows, :host => ssh_info[:host],
                                       # :port => ssh_info[:port],
                                       # :username => ssh_info[:username],
 # :key_path =&gt; ssh_info[:private_key_path]
@kkdeploy
kkdeploy / gist:2950619
Created June 18, 2012 20:47
Capistrano fast assets precompile
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
if capture("diff -r #{latest_release}/app/assets/ #{current_release}/app/assets/ | wc -l").to_i > 0
run %Q{cd #{current_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
@joel
joel / .irbrc
Created July 9, 2012 09:21
Make all factory girl is available in your rails console
# mate ~/.irbrc
#!/usr/bin/env ruby
if defined? Rails
begin
require 'factory_girl'
Dir[Rails.root.join("spec/factories/**/*.rb")].each { |f| require f }
rescue LoadError
end
@iDiogenes
iDiogenes / gist:3231039
Created August 1, 2012 21:49
RADIUS with MySQL Support
Ubuntu MySQL & RADIUS Howto:
Install MySQL
# apt-get install mysql-server mysql-client
Secure MySQL
Mysql_secure_installation