When building Elemental Beats I wanted to make sure that the download links I gave my customers for their purchase where protected and had an expiration date.
There are a number of ways to implement secure download links in rails, but I think the best option is to use the ngx_http_secure_link_module for nginx. Its actually quite straight forward to implement and provides you with secure time expiring download links, and the best part is that since nginx is serving the files you don't tie up a rails process to serve the file so your site can stay extra fast.
Here is how to implement it with Rails.
First you'll need to compile nginx with the secure link module. So this means you can't just use the standard nginx package from
apt-get without any customization. Don't worry though its easy to compile nginx just download the source and pass this option to your configure script.
Once you have nginx compiled and installed with the http secure link module, you'll need to set it up.
First add a server block like this to your nginx.conf. Just make sure to change the server_name and root directives to match your site. Also change the DOWNLOAD_SECRET string to something unique and secret.
Now restart nginx, and thats all you will have to do with nginx. Now make sure to place all your files in the downloads directory of your files.domain path.
Now on to Rails.
In your Rails code you basically need to generate the required params that nginx expects for each file you serve from your files subdomain. To do this I have a method in my Order model that looks like this:
Just note that my Order model in the code above has a
file_path method that when called returns the path to the file inside the downloads directory folder. Also note the DOWNLOAD_SECRET env variable, that should match the string you put in your nginx config file.
And thats all it takes to have nginx serve secure download links from your rails app.
Below is a list of websites I worked on in 2013 (so far):
Open Source Contributions
Below is a list of websites I worked on in 2012:
Open Source Contributions
I have released a new gem for rails called S3 Direct Upload. I suppose I have been interested in direct uploading to s3 for sime time now.
The inspiration (and some core code) for this gem came from Ryan Bates excellent RailsCast #383 where he explains (at the end) a pattern for uploading directly to S3 from the client side. I was quite enthusiastic about this and decided to turn this basic pattern into a gem.
I hope you enjoy the gem, if you have any questions send me a note on github.
Below is a list of websites I produced in 2011:
Complete Design & Development:
I wrote a simple Sinatra app to upload files directly to Amazon S3 using SWFUpload, check it out on GitHub Most of the inspiration (and a lot of the core code) came from Tom Pesman's post on how to do the same thing, just in rails. I ported Tom's code to use jQuery and the jQuery swfupload plugin. I also converted most of the views to HAML.
A couple of notes about the code: The ruby code I borrowed from Tom used a couple Rails specific helper functions like 'hours' but thankfully these helper functions are all easily accessible in sinatra by including the active_support gem.
Also, you must put the crossdomain.xml file in the root of your S3 Bucket and give it read privileges.
This is my first open source contribution! If you have any questions, ideas on how to make the code better, or even feature requests let me know! Its pretty bare bones right now, maybe I'll add some styling and some progress indicators later.
The Sinatra App is available on github. It is uses by these libraries:
Ruby: sinatra active_support/core_ext base64
After analyzing other keyboard layouts like colemak, workman, and norman, I came to find that I could get most of the benefits of these layouts without switching to them by simply swapping the I and U keys on my current layout, Dvorak. In fact Dvorak with IU swapped performed better than some of these layouts in certain situations.
So I created (I wasn't the first) the Dvorak keyboard layout with the IU keys swapped. I have been using this modified keyboard layout sense 2009 and have been pleased.
It makes sense because 'I' is much more frequent in English than 'U' so putting it directly under a finger on the home row seems obvious. With this new layout I theoretically move my fingers less than on the traditional Dvorak layout.
It took me about a week and a half of using this new layout until I was up to my old speed on the official Dvorak layout.
If you are interested here are the layout files for Mac and PC:
For Mac: Download this file Dvorak IU Switch Mac and run the package. It will place the keyboard layout file in /Library/Keyboard Layouts/ . Next logout and log back in and then select the keyboard layout in Settings -> Keyboard -> Input Sources
For PC Download this file Dvorak IU Switch PC Open setup.exe. Then select the keyboard layout in the input sources.
For Linux Download this file Dvorak IU Switch for Linux Replace the
us file here
/usr/share/X11/xkb/symbols with the one downloaded above. Then in your settings choose the regular dvorak layout, it will be the dvorak i-u switched version. The dvorak part has been replaced by the IU switch version. This is the quickest way to do this I have found.