Skip to content

Instantly share code, notes, and snippets.

View bryanstearns's full-sized avatar
⁉️

Bryan Stearns bryanstearns

⁉️
View GitHub Profile
#!/usr/bin/python
#
# startvpn: Automatically connect to a VPN when associating with a
# wireless network
#
# Once you've successfully set up an OpenVPN connection in NetworkManager,
# configure the settings below, then install this script as
# /etc/NetworkManager/dispatcher.d/02startvpn (it seems to be happiest
# when chowned root:root)
#
module EnumeratedAttributes
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def enumeration(attr_name, options)
# Declare a mapping of symbols to integer values for an attribute:
#
# enumeration :ghost,
# :in => {:past => 0, :present => 12, :yet_to_come => -5},
# In spite of the proscription at the end of Recipe 69, "Upload Custom Maintenance
# Pages" in Mike Clark's excellent Advanced Rails Recipes, I wanted to generate my
# maintenance page with the full awesome power of Rails (ok, well, I wanted to use
# a real template, to avoid having to maintain the look of the maintenance page
# separately).
#
# My solution was to render the page using this rake task, which goes in:
# lib/tasks/render_maintenance.rake
task :render_maintenance => :environment do
# Render the maintenance page into tmp/maintenance.html,
@bryanstearns
bryanstearns / delayed_job.rb
Created August 30, 2009 20:44
config/initializers/delayed_job.rb with conditional mail delaying
# Conditionally delay outgoing mail
class DelayedMailerBase < ActionMailer::Base
class << self
def method_missing(method_symbol, *parameters)
# If this is "deliver_xx", maybe delay it; if we do, change
# its name so that we don't delay in the worker.
method_name = method_symbol.to_s
if matches_deliver_method?(method_name) and delaying_mail?
return self.send_later("delayed_#{method_name}".to_sym, *parameters)
end
@bryanstearns
bryanstearns / ascertain_revision.rb
Created April 15, 2010 21:03
config/initializers/ascertain_revision.rb
# "Ascertain" the revision we're running (so named so it'll come before
# the cache initializer, which uses this info).
def determine_revision
# Note the revision number we're running, and a
# more-informative string containing it.
revision_path = File.dirname(__FILE__) + "/../../REVISION"
begin
digits = 8
if File.exist? revision_path
#!/usr/bin/env ruby
#
# Don't run this - it's a waste of time...
#
# We got ourselves into a situation where we had several undeployed migrations
# that depended on intermediate versions of our models to evolve production
# data, which prevented easy deployment.
#
# I wrote this script, assuming that it could "figure out" how to check out
# intermediate revisions and migrate in several steps. Unfortunately, this
module ManualUpdate
def self.by(login_name)
ActiveRecord::Base.transaction do
ActiveRecord::Base.current_user = User.find_by_login!(login_name)
PaperTrail.whodunnit = login_name
puts "Running update..."
yield
puts "Checking database validity..."
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
ManualUpdate::by('stearns') do
# We got this from a tenant:
## I made my first online payment using your website this afternoon. Somehow
## two payments in the amount of $1150 were processed and are scheduled to
## come out of my checking account tomorrow. Can you please cancel one of
## the payments to my account?
LineItem.delete(3471)
@bryanstearns
bryanstearns / gist:850235
Created March 2, 2011 00:52
rvm --trace rubygems 1.4.1
root@vbox3:~# rvm info
ree-1.8.7-2011.03:
system:
uname: "Linux vbox3 2.6.32-29-generic-pae #58-Ubuntu SMP Fri Feb 11 19:15:25 UTC 2011 i686 GNU/Linux"
bash: "/bin/bash => GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)"
zsh: " => not installed"
rvm:
root@vbox3:/usr/local/rvm/src/rubygems-1.4.1# ls -R
.:
bin cruise_config.rb hide_lib_for_update lib Manifest.txt Rakefile README.rdoc test
ChangeLog GPL.txt History.txt LICENSE.txt pkgs README setup.rb util
./bin:
gem update_rubygems
./hide_lib_for_update:
note.txt