By tag: ruby

Start a webserver in current working directory using Ruby

If you’re working on a website and want to test the site and serve your current working directory as the website root, you can do it with Ruby:

ruby -r webrick -e "s = WEBrick::HTTPServer.new...
*

Set content expires and cache-control metadata for AWS S3 objects with Ruby

You can set the HTTP Expires and Cache-control headers for S3 bucket objects with the Ruby SDK for AWS. This will help site performance by enabling browsers to cache content which is not updated frequently such as stylesheets, javascript files and images.

This assumes you already have the AWS Ruby SDK installed.

...
*

Time.parse undefined method error in Ruby

You may get this error when trying to use Time.parse in a Ruby script:

undefined method `parse' for Time:Class (NoMethodError)

If so, try adding this line to the top of your script:

require ...
*

How to enumerate the items in an AWS S3 bucket with Ruby

You can iterate through the items in an S3 bucket and print the names with this Ruby snippet. It assumes you already have the AWS Ruby SDK installed. Remember to set the details for your_access_key, your_secret_access_key and bucket_name as appropriate for your bucket.

...
*

Using Time.parse in Ruby

There are some Time extension methods, for example Time.parse, which are not automatically imported into Ruby scripts as part of the standard library. To use these methods you probably need to add this line to the top of your script:

requi...
*