Folders in AWS:S3

October 29th, 2010

I’ve been using S3 and Cloudfront from AWS to host images lately and enjoying them a lot. I use the AWS:S3 gem to access my buckets.

One of the interesting things about S3 is that there’s not really anything like a ‘folder’. A lot of GUI tools will make something that looks an awful lot like a folder, but it’s really just a key with a bunch of slashes in it.
ex: this/is/just/a/key.txt

I use Panic’s Transmit for my uploads and when I did the initial load I just copied a directory up and Transmit did all the heavy lifting, created the folder keys from the paths. No muss, no fuss. If I want to create an empty ‘folder’, I just right click and select new folder. However, if I want to do the same thing programatically, that’s a fish of a different feather. Doing some digging on the intertubes led me to a lot of people talking about how some GUIs for S3 use _$folder$ to mark a folder.

I gave this a whirl, then took a look in my Transmit pane and saw new_folder_name_$folder$. Not exactly what I’d wanted. When I tried to add something like new_folder_name/file.txt I would now have 2 folders: new_folder_name and new_folder_name_$folder$. And new_folder_name wouldn’t respond properly to a get info request from Transmit.

Doing a little more digging, I found some records of people simply adding a / to the end of the key to give them their folder. When I tried this, it works like a charm:

AWS::S3::S3Object.store(“#{id}/”, “”, “bucket”, :access => :public_read);

Basically, I’m creating an empty, dynamically named folder in “bucket” with public read on it.

I dropped an image file in there to test and make sure it works and it does. So now I can create a new “folder” in my S3 bucket on every create in my app and they’re there waiting for me. It was a small annoyance, but satisfying to fix, nonetheless.

The _$folder$ trick might work for other GUIs, but this is what worked for my tool.

Ruby Koans

October 29th, 2010

Just finished off Ruby Koans. A great way to brush up on your ruby basics and uncover some things you might not have ever known.

One of the odder things for people coming to ruby might be the concept of blocks. I know I struggled with them when I first started ruby and the ruby koans probably has the clearest examples I’ve ever seen.

WebSVN

October 19th, 2010

Though more and more projects are moving to GIT, there’s still a lot of code out there using SVN for version control and sometimes you need to have a quick way to view your repo. TRAC is a long time favorite, but it can be a lot more full featured than you really need.

My buddy Dave pointed out WebSVN to me and I had it installed and up and running in 5 minutes.

Simply download the compressed file and expand it in your public_html directory.

Next, you’ll need to copy include/distconfig.php to include/config.php

inside you’ll find a plethora of options and settings, but the important one is this:

// $config->addRepository(‘NameToDisplay’, ‘URL to repository (e.g. file:///c:/svn/proj)’);

Simply uncomment this line and add the url to your repo.

Remote repos are similar, needing a username and password as well.

Take the time to read through the file and tweak settings as necessary.

Action caching

October 15th, 2010

sigh, remember that if you use action caching to move any after_filters to a before_filter since action caching uses a special around filter and will kill you!

RVM

October 1st, 2010

If you’re still using ruby 1.8.7 for some apps built in older versions of Rails, but you want to start playing with Rails 3.0 and Ruby 1.9.1 you can easily sandbox directories on your dev machine with different version of Ruby using RVM.

RVM is the Ruby Version Manager. You can find it here.

Once installed, you can simply use it to install the ruby version you want to use and even set up a specific gemset:

rvm install 1.9.1
rvm gemset create new_proj

If you want to automatically use the rvm when you cd into your new_proj directory, simply add a .rvmrc file with the following

rvm ruby-1.9.1@new_proj

So when you cd into new_proj and check the ruby version, you’ll see 1.9.1

Of course, there’s much more you can do with the rvmrc file, check it out here

RVM gives you a very nice way to create multiple sandboxes for Ruby development on the same machine without any headaches.

Rails 3.0 nearly ready

August 24th, 2010

According the the Riding Rails Blog the final release for Rails 3.0 should be this week. Lots of tweaks and bug fixes, but the things most people (including me!) are excited about are the new methods for handling gems (Bundler) and ARel. Accessing models using relational algebra. Should be much more efficient!

Array dereferencing in PHP

August 3rd, 2010

Just saw this: neat PHP feature.

Many is the time I wanted to just grab something from an array returned by on of the many great core PHP array methods without having to assign it. And now I can.

Built in sanitizing with PHP

July 19th, 2010

A friend of mine just sent me this link about built in validation/sanitizing with php 5.2

This is one of those nice features that veteran php devs have always wanted and have probably missed in the updates.

Zend has always had a pretty nice filter module but this is built into PHP core, so no need to worry about library dependencies.

Check out the list of filters here. Finally, built in IP validation.

action caching and content_for

June 16th, 2010

So as happy as I am with my action caching over on Alternity, there is one problem that’s bugging me.

I’d like each world and category to have a title that reflects the content. I put the content_for :title in my views, threw a yield :title in my layout and as expected, each of my pages had an appropriate title. Committed the change and didn’t think about it too much afterward until I noticed that there was no custom title on my live site. Duh, the content_for method is called when the view is rendered and since my action caching was fetching the pre-rendered *.cache files from my cache, naturally there was no :title for the layout to render. One solution would be to simply include the layout in the action cache, but I have reasons for not wanting to do that. It makes cache invalidation a bear.

I looked up how content_for worked and found that it simply saved the text into an instance variable:
@content_for_{name_of_the_content_block}
@content_for_title in my case.

It seems like the way to fix this would be to have the action cacher check for those instance variables and append them to the bottom of the *.cache files, then check for them when rendering and put them back into an instance variable.

Say, a chunk of text at the bottom of the file:

content_for_title blah blah blah
content_for_nav blah blah blah

Anybody done anything similar? I’m planning it out, but I want to wait until Rails 3 drops to see if there’s changes to the caching.

Amazon adds S3 to AWS console

June 13th, 2010

The AWS Management Console now provides a simple and intuitive web interface for managing your Amazon S3 resources. You can manage your existing Amazon S3 resources, as well as create new buckets and upload objects to your buckets using the console.

The console simplifies managing your Amazon S3 resources by enabling you to:

  • Access your Amazon S3 resources from anywhere using a web-based user interface.
  • Log in using your AWS account name and password. If you’ve enabled AWS Multi-Factor Authentication, the console will prompt you for your devices authentication code. No need to look up and enter your Access Key ID and Secret Access Key.
  • Oversee your AWS resources in a single, convenient location. The AWS Management Console now supports Amazon S3, Amazon EC2, Amazon CloudFront, Amazon Elastic MapReduce, and Amazon RDS.
  • Manage buckets with billions of objects. The console also works with folders and objects created using many popular third party tools.

To start managing your Amazon S3 resources through the AWS Management Console today, go to console.aws.amazon.com/s3. For more information about Amazon S3 go to aws.amazon.com/s3.

This is great news, I use Panic’s Transmit for my day to day management of my S3 buckets, but having a handy web interface is great when I’m on the go.  If you’re not using Amazon’s S3 and CloudFront for your CDN right now, give it a shot.  It’s reduced my image loading time by about a 6th and generally costs less than 5 bucks a month.