Skip to content

Instantly share code, notes, and snippets.

module ActiveRecord
module ConnectionAdapters
module DatabaseStatements
#
# Run the normal transaction method; when it's done, check to see if there
# is exactly one open transaction. If so, that's the transactional
# fixtures transaction; from the model's standpoint, the completed
# transaction is the real deal. Send commit callbacks to models.
#
# If the transaction block raises a Rollback, we need to know, so we don't
@tomlea
tomlea / xbox
Created October 27, 2014 03:01
Control your XBox One from the OS X command line!
#!/usr/bin/env bash
if [ "x$1" == 'xoff' ]
then
$0 turn off
sleep 1
say yes
else
say X box $*
fi
@tomlea
tomlea / Info.plist
Created October 29, 2008 13:21
An Info.plist for IE6 Installed with CrossOver Mac to allow it to work with ChoosyOSX. Note that you will need to create a c_drive/windows/hosts file if you wan't it to work with localhost.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
select @session := COALESCE(max(session), 0) + 1 from product_invalidations;
insert product_invalidations(product_id, session) select p.id, @session from products p inner join product_types pt on pt.id = p.product_type_id where pt.name = 'mobile-phones';
@tomlea
tomlea / per_partial_render_time.rb
Created December 2, 2008 17:52
Script to parse rails logs and summarise total partial rendering times.
data = Hash.new(0)
while line = gets
if m = line.match(/Rendered (\S+) \(([\d\.]+)\)/)
data[m[1]] += m[2].to_f
end
if line =~ /Completed/
data.sort_by{ |name, value| value }.each do |name, value|
puts "%.04f : #{name}" % value
#!/usr/bin/env ruby
require "rubygems"
gem "beanstalk-client"
require "beanstalk-client"
port = ARGV.last or raise "GIVE ME A PORT NEXT TIME!"
beanstalk = Beanstalk::Pool.new(["0.0.0.0:#{port}"])
require 'drb'
module RemoteRunner
module Runner
def eval(code)
Kernel.eval(code)
end
end
def load_app(app)
# t(:foo) now looks for admin.blog_controller.foo, then if not found it then goes for admin.foo, then finally just foo.
def ApplicationController.has_controler_specific_translation_helper_fu
def t(key, options = {})
controller_name = self.controller_name + "_controller"
defaults = [[:admin, controller_name, key], [:admin, key], [key]].map{|a| a.join(".").to_sym}
key, defaults = *defaults
options[:default] = defaults
I18n.t(key, options)
end
helper_method :t
@tomlea
tomlea / github-backup.rb
Created January 13, 2009 17:38
Command line app to backup all your github repos. You can then use the local path just like a remote one when github goes down.
#!/usr/bin/env ruby
gem 'mbleigh-ruby-github'
require "ruby-github"
unless username = ARGV.first and username =~ /[a-zA-Z0-9]+/
puts "Usage: #{$0} <github_username>"
exit(1)
end
BASE_PATH=File.expand_path("./repos")
namespace :deployment do
desc "Mark the deployment as locked, preventing further deployments (until deployment:unlock)"
task :lock, :roles => :app do
run "touch -f #{shared_path}/locked"
end
desc "Unmark the deployment as locked, allowing further deployments (until deployment:lock)"
task :unlock, :roles => :app do
run "rm #{shared_path}/locked"
end