Skip to content

Instantly share code, notes, and snippets.

<<-BUMBLEBEE
The bumblebee hovers around an object,
looking for a flower with some pollen.
It goes from flower to flower,
trying each method in order,
and when it finds one that isn't empty,
it returns it to the hive.
@tomlea
tomlea / beanstalker-the-debeaning.rb
Created January 30, 2009 14:19
Beanstalker is back, and it's hungry for beans!
#!/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}"])
@tomlea
tomlea / bean-bandit.rb
Created February 4, 2009 14:34
Bean Bandit: Puts beanz on ze queue.
#!/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}"])
{ scopeName = 'source';
patterns = (
{ name = 'source.invalid.trailing-whitespace';
match = '\S(\s{1,})$';
captures = { 1 = { name = 'invalid.trailing-whitespace'; }; };
},
{ name = 'source.invalid.just-whitespace';
match = '^(\s{1,})$';
captures = { 1 = { name = 'invalid.trailing-whitespace'; }; };
@tomlea
tomlea / gist:60830
Created February 9, 2009 15:39
TextMate whitespace error highlighting.
{ scopeName = 'source';
comment = '
You will need to add a { include = "source"; } within the patterns = (...) segment of each of your languages.
Eugh!
';
patterns = (
{ name = 'source.invalid.trailing-whitespace';
match = '\S(\s{1,})$';
captures = { 1 = { name = 'invalid.trailing-whitespace'; }; };
},
set :deploy_via, :copy
set :copy_cache, true
set :copy_exclude, [".git/*", ".svn/*"]
set :copy_strategy, :export
set :repository, Dir.pwd
@tomlea
tomlea / .bashrc
Created February 27, 2009 12:20
Prevent textmate exploding when you do a "mate /" by accident.
function mateforce(){
`which mate` $*
}
function mate(){
if find $* -type f | ~/line_count_less_than 1000
then
mateforce $*
else
echo "Too many files!"
# The data setup inside the block may take upto a second to be ready to pass the test. But probably much less.
def retrying_for(secconds = 1)
limit = Time.now + secconds
begin
yield
rescue
if Time.now < limit
sleep 0.05
retry
else
@tomlea
tomlea / twitter_echo_bot.rb
Created April 27, 2009 00:33
A script to retweet any direct messages sent to the account.
require "rubygems"
gem "twitter4r"
require "twitter"
require "active_support"
Twitter::Client.configure do |conf|
conf.application_name = "Twitter Echo"
end
username, password = ARGV.shift, ARGV.shift
# Example:
# # Fish has a has_been_caught_by_someone_called(...) scope that is too complex (several joins, and group bys)
# Fish.count # => 999,999,999
# my_fish = Fish.has_been_caught_by_someone_called("bubba")
#
# my_fish.count # => 999,999
# my_fish.update_all(:color => "green") # Too complex, too many joins, group by etc... mysql will not play ball.
# my_fish.all... # => OUT OF MEMORY!!!!!!
# my_fish.each_in_batches{|f| f.update_attribute(:color => "green") } # => Takes more than a decade.
# my_fish.complex_update_all(:color => "green") # => 999,999