Skip to content

Instantly share code, notes, and snippets.

View scottwb's full-sized avatar

Scott W. Bradley scottwb

View GitHub Profile
@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
@scottwb
scottwb / get_git_branch_sha.sh
Created April 22, 2010 08:34
Get the SHA of some git branch.
# Get the SHA of some branch. There must be a better way to do this.
git log -1 --pretty=oneline origin/somebranch | sed -E "s/^([^[:space:]]+).*/\1/"
@scottwb
scottwb / nginx_subdomain.conf
Created January 25, 2011 16:38
Nginx config to route domain and subdomains, except for explicit virtual hosts, to the www subdomain.
http {
# Default virtual host for www.example.com. This will pick up all HTTP
# requests to port 80 that are not for one of the other virtual hosts.
server {
listen 80;
server_name www.example.com;
# ...your server config here...

Keybase proof

I hereby claim:

  • I am scottwb on github.
  • I am scottwb (https://keybase.io/scottwb) on keybase.
  • I have a public key ASDC8tX5gl6bMMaEnHY4UeW1PDECJCiF7S2vqTuQLWSt7wo

To claim this, I am signing this object:

#!/usr/bin/env/ruby
require 'socket'
# AWS API Credentials
AWS_ACCESS_KEY_ID = "your-aws-access-key-id"
AWS_SECRET_ACCESS_KEY = "your-aws-secret-access-key"
# Node details
NODE_NAME = "webserver-01.example.com"
@scottwb
scottwb / gist:398321
Created May 12, 2010 08:09 — forked from cypher/gist:150248
Git pre-commit hook to verify only valid ruby.
#!/usr/bin/env ruby
#
# A hook script to verify that only syntactically valid ruby code is commited.
# Called by git-commit with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# Put this code into a file called "pre-commit" inside your .git/hooks
# directory, and make sure it is executable ("chmod +x .git/hooks/pre-commit")
#
@scottwb
scottwb / gist:499673
Created July 30, 2010 01:35
Ruby mixin overriding instance methods.
#!/usr/bin/env ruby
#
# Example showing how to make including a mixin override instance methods.
#
module TalksLikeMrT
def self.included(klass)
(klass.instance_methods & self.instance_methods).each do |method|
klass.instance_eval{remove_method method.to_sym}
end
@scottwb
scottwb / Rakefile
Created February 24, 2012 17:21
Rakefile for Middleman with an rsync deploy task.
SSH_USER = 'root'
SSH_HOST = 'www.example.com'
SSH_DIR = '/var/www/html/www.example.com'
desc "Build the website from source"
task :build do
puts "## Building website"
status = system("middleman build --clean")
puts status ? "OK" : "FAILED"
end
@scottwb
scottwb / pear.rb.diff
Last active January 3, 2016 20:09
Illustrates bug (and fix) in the php::module_apc cookbook from https://github.com/opscode-cookbooks/php/blob/master/providers/pear.rb that occurs on centos.
diff --git a/cookbooks/php/providers/pear.rb b/cookbooks/php/providers/pear.rb
index ca473b5..db90e17 100644
--- a/cookbooks/php/providers/pear.rb
+++ b/cookbooks/php/providers/pear.rb
@@ -258,13 +258,13 @@ def pecl?
@pecl ||= begin
# search as a pear first since most 3rd party channels will report pears as pecls!
search_cmd = "#{node['php']['pear']} -d"
- search_cmd << " preferred_state=#{can_haz(@new_resource, preferred_state)}"
+ search_cmd << " preferred_state=#{can_haz(@new_resource, "preferred_state")}"
@scottwb
scottwb / idle.js
Last active January 2, 2016 13:19
A javascript function banks can use to determine if they should log out a user session for being idle.
function shouldLogOutIdleSession() {
return false;
}