31 May 2008
Has the right idea about how to store files, but the lib it uses does not abstract things enough. Does not use http keep alive to avoid the slow startup of tcp. Does not have an easy way to iterate over all keys in a bucket, but this helps to do this:
def each_object(bucket_name)
next_marker = nil
while true do
response = CONN.list_bucket(bucket_name, {'marker' => next_marker, 'max-keys' => 10})
response.entries.each do |s3obj|
yield s3obj
end
break unless response.properties.is_truncated
next_marker = response.entries.last.key
end
end
Again no built in way to iterate over all keys. Has problems with ‘/’ at the start of file names.
Uses the same http connection, can iterate over all keys with a single method (though, it makes a full array of all the keys rather than allowing you to supply a block). Here’s my thumbnailer:
require 'rubygems'
require 'right_aws'
require 'RMagick'
require 'pp'
s3 = RightAws::S3.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
picture_bucket = s3.bucket('OurPictures')
thumbnail_bucket = s3.bucket('OurPicturesThumbnails')
picture_bucket.keys.each do |key|
thumbnail_key = RightAws::S3::Key.create(thumbnail_bucket, key.name)
next if key.name !~ /.jpg$/i
next if thumbnail_key.exists?
image = Magick::Image.from_blob(key.data).first
image.change_geometry!('256x256>') do |cols, rows, img|
img.thumbnail!(cols, rows)
end
thumbnail_key.put(image.to_blob, 'private')
p thumbnail_key.full_name
image = nil
GC.start
end
#ruby
31 May 2008
(mostly randy here again. I was putting up my first ec2 instance. :)
Saturday Keynotes
- funny video from the RailsEnvy guys about testing
DHH introducing Jeremy Kemper
- Jeremy has done a buttload of work lately in the Rails core
- dhh on a coding vacation?
- some people think about one part of rails Jeremy thinks about the whole thing
Jeremy’s talk about Rails 2… where it’s going, etc
- “it’s all about resources”
- “we shed a lot of fat” – split things off into plugins
- “we gained speed” – “i’m not concerned about rails being super super quick” — huh???
- 1600 patches… it’s hard to read all that code! so we embraced git and lighthouse instead of svn and trac
- Rails 2.1
- refactoring
- documentation
- thinner + faster
- (he looks exhausted… too much free five runs beer and cheese pies)
- he wants rails to look pretty.
- use rubyprof
- merging migrations
- making timezones fitter, happier, more productive
- migrations now have change_table block for modifying tables (just like create_table)
- gem dependencies
- improved memcache… making it a first-class citizen in rails. memcache-client now bundled with rails
- much of what he’s covering Myers read in this tutorial on rails 2.1
- dirty – AR now knows when an attribute has changed
- message.body_changed?
- message.body_was
- message.changed?
- enables partial updates
- smarter :include — it’s not as eager to join on the first query. this seems like it will be slower, but benchmarking supposedly proves that querying the join table on an as-needed basis is faster
- named_scope
- so you can say user.messages.recent instead of user.recent_messages by saying named_scope :recent, :order -> 'created_at desc’ in the Message model
- Message.scoped(:limit => 10)
- jruby -S jetty_rails (run rails on jruby)
- rbx script/server (run rails on rubinius)
- rails now runs on ruby 1.9
- rails 2.1 out today (a gem update at 10:14am didn’t do anything tho… it will be later… so not a Steve Jobs “and you can buy it right now”)
#railsconf2008