Skip to content

Instantly share code, notes, and snippets.

Scott W. Bradley scottwb

View GitHub Profile
@scottwb
scottwb / application_controller.rb
Created Feb 17, 2012
Get a list of all the filters on a given Rails 3 controller.
View application_controller.rb
# 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 Apr 22, 2010
Get the SHA of some git branch.
View get_git_branch_sha.sh
# 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 Jan 25, 2011
Nginx config to route domain and subdomains, except for explicit virtual hosts, to the www subdomain.
View nginx_subdomain.conf
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...
View keybase.md

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:

View bootstrap-windows.rb
#!/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 — forked from cypher/gist:150248
Git pre-commit hook to verify only valid ruby.
View gist:398321
#!/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 Jul 30, 2010
Ruby mixin overriding instance methods.
View gist:499673
#!/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 Feb 24, 2012
Rakefile for Middleman with an rsync deploy task.
View Rakefile
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 Jan 3, 2016
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.
View pear.rb.diff
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 Jan 2, 2016
A javascript function banks can use to determine if they should log out a user session for being idle.
View idle.js
function shouldLogOutIdleSession() {
return false;
}
You can’t perform that action at this time.