Skip to content

Instantly share code, notes, and snippets.

Tom Lea tomlea

Block or report user

Report or block tomlea

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tomlea
tomlea / xbox
Created Oct 27, 2014
Control your XBox One from the OS X command line!
View xbox
#!/usr/bin/env bash
if [ "x$1" == 'xoff' ]
then
$0 turn off
sleep 1
say yes
else
say X box $*
fi
View after_commit_with_transactional_fixtures.rb
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 / hero.sh
Created Aug 1, 2013
When you have multiple heroku apps, for one repo, you're going to need a hero! hero production run rake db:migrate
View hero.sh
function _hero_getRemoteNames(){
git config --get-regexp remote.*.url heroku.com |
sed -E 's/^remote\.([^\.]*)\.url .*$/\1/'
}
function _hero_herokuAppFor(){
git config --get remote.$1.url |
sed -E 's/^git@heroku.com:([^.]*)\.git/\1/'
}
View quick_bulk_select.rb
# Introduction:
We need to select large numbers of items (300k or more), based on active record associations (and selectors, and all that faff), but we only care about the ids.
This is easily solved by bla_bla_bla_scope.map(&:id). This however takes about 16s of CPU grinding ruby to get to the final answer via AR objects. AR objects that contain only an ID.
Why not just use the SQL generated by the scopes and other voodoo to just pump the SQL through? That's what this does, in the most complex way imaginable!
# Usage:
@tomlea
tomlea / start_sql_servers.sh
Created Mar 3, 2011
Start a MySQL master/slave pair.
View start_sql_servers.sh
rm -R $HOME/Desktop/server-{1,2}
mkdir -p $HOME/Desktop/server-{1,2}
mysql_install_db --datadir=$HOME/Desktop/server-1 && mysqld --server-id 1 -h ~/Desktop/server-1 --socket ~/Desktop/server-1/mysql.sock -P 10001 --log-bin &
mysql_install_db --datadir=$HOME/Desktop/server-2 && mysqld --server-id 2 -h ~/Desktop/server-2 --socket ~/Desktop/server-2/mysql.sock -P 10002 --master-port=10001 --master-host=127.0.0.1 --master-user=root &
alias sql-master="mysql -h127.0.0.1 -P10001 -uroot"
alias sql-slave="mysql -h127.0.0.1 -P10002 -uroot"
alias sql-master-admin="mysqladmin -h127.0.0.1 -P10001 -uroot"
View goviasGrid.js
javascript:
if( !window.goviasGrid ){
window.goviasGrid = document.createElement("div");
document.getElementsByTagName("body")[0].appendChild(window.goviasGrid);
window.goviasGrid.style.background = "url(http://tomlea.co.uk/assets/the-grid.png) repeat-y 50% 0";
window.goviasGrid.style.width = "100%";
window.goviasGrid.style.height = "100%";
window.goviasGrid.style.position = "fixed";
window.goviasGrid.style.top = "0";
window.goviasGrid.style.bottom = "0";
View List of Nabaztag Voices
AU-Colleen
AU-Jon
BE-Hendrik
BE-Minna
BE-Sofie
BR-Lygia
CA-Antonine
CA-Felix
CN-Pan
CZ-Zdenech
View s3secure.rb
# A secure S3 storage engine for Paperclip.
# Usage:
#
# require "paperclip/storage/s3secure"
# has_attached_file :image, :storage => :S3secure, …
module Paperclip::Storage::S3secure
def self.extended base
base.extend(Paperclip::Storage::S3)
base.options[:s3_permissions] = :private
View gist:279962
def sort_order
# Google was indexing "random" search orders, it parsed our javascript, badly.
SORT_METHODS[params[:sort_order]] or raise_redirect_to(@product, :status => 301)
end
def segment
segment = params[:segment]
segment = segment.to_sym if %w[all other].include?(segment)
segment = nil if segment == :all
# Bad or expired segments need 301ing
View raisable_redirections.rb
module RaisableRedirections
def self.included(other)
other.send(:around_filter, :handle_raisable_redirections)
end
protected
def raise_redirect_to(*args)
raise Redirect.new(*args)
end
You can’t perform that action at this time.