Posted by Matt
on May 16, 2008
Neat little snippet of code in those odd times you need to loop over every model in your application programmatically.
This exact snippet loops over every model, and converts each timestamp (created_at, updated_at) to UTC. It can be quite helpful if you're adding Time Zone support to your Rails 2.1 application and you have existing non-UTC timestamps.
all_models = Dir.glob( File.join( RAILS_ROOT, 'app', 'models', '*.rb') ).map{|path| path[/.+/(.+).rb/,1] }
ar_models = all_models.select{|m| m.classify.constantize < ActiveRecord::Base}
*Please note: I haven't tested this very thoroughly, but it does seem to do the trick. As we know, Dates and Times can be total PITAs!
Posted by Matt
on May 16, 2008
In the application I'm currently developing a User has_many Jobs, and each Job has a bunch of nested resources. The application calls for a Dashboard, filled with the latest changes to any Job the currently logged-in user is assigned to.
Sounds difficult huh?
def self.get_latest_items_for(current_user)
assigned_job_ids = current_user.jobs.collect(&:id)
find(:all, :conditions => ["job_id in (?)", assigned_job_ids])
end
In order to get the currently logged-in user's list I just do:
RecentItem.get_latest_items_for(current_user)
Simple, elegant, understandable, and concise.
Posted by Matt
on May 15, 2008
I spent a greater part of this day attempting to get nginx, SSL, and EC2 to play nice together. The funny thing was that nginx (which was hosting a mongrel_cluster) would serve standard HTTP requests just fine, but HTTPS requests just kind of hung there.
I could see that nginx was in fact listening to port 443 and could connect locally, but the whole shebang fizzled out anywhere outside the local box. No firewall either.
After pulling my hair out for a bit, I happened across this article that alluded to the 'ec2-authorize' command.
Seems as though you have to remotely manage the "firewall" of a running instance!
Anyhow; cutting to the chase: To enable HTTPS on your EC2 instance just run:
ec2-authorize default -p 443
Posted by Matt
on May 12, 2008
One of Rails' greatest strengths lies with the plugin system. Git is the new source control kid on the block that all the girls are talking about, but Git breaks existing systems to manage plugins, such as Piston and the great './script/plugin install -x' command.
Git giveth and Git taketh away.
Git has the supernatural ability to track submodules in your application. The below command adds RESTful_ACL as a submodule to your application inside the vendor/plugins directory, checks the project out for you, and commits changes in your application (added info in .gitmodules).
git submodule add git://github.com/mdarby/restful_acl.git vendor/plugins/restful_acl
git commit -a
When you go to clone to a different machine, just run the following two commands to checkout all of your submodules:
git submodule init
git submodule update
You're off and running!
Posted by Matt
on March 28, 2008
I've suddenly realized that while I do really like my fulltime gig, I'm not getting paid for the insane amount of overtime I normally put in. I'm not asked to do this work, but I do as I get bored and hey, I really like to code.
So I logged onto workingwithrails.com and sent my resume out to a few prospective clients that allow telecommuting developers. Why the blog post? I don't know, I guess I'm kind of excited about the process. I will be nice to use my craft on different problem domains for once.
I have been attending meetings with the Columbus Ruby Brigade for the last three months and this month's meeting was about freelancing. One thing that member Joe O'Brien said stuck in my head. To paraphrase; "If you waited until you were sure you were the top expert in your field, you would never get started".
I really respect Joe from afar as he's a super bright guy with a solid history of experience. Wisdom is learning from others, so I've decided to throw my hat in the ring.
Wow, I've referenced myself 21 times in this post. My (22) high school English teacher is probably freaking out somewhere.
Posted by Matt
on March 26, 2008
Oh man, how awesome is this. Nary two hours after releasing Scribd_fu, it is already featured on Scribd's Resources page! I hope this will help to drum up usage of Scribd_fu across the Rails community.
A big thanks to Scribd for the nod, and the link!
Posted by Matt
on March 26, 2008
I'm pleased to announce my latest plugin: Scribd_fu.
What it does:
Scribd_fu hides out in the shadows like a document converting ninja, just waiting to process your data into a convenient Flash format (like YouTube) with the help of the black majick of Scribd.com. Imagine imbedding huge documents right inline with your web UI, no downloading, no necessary programs on the client side to view your data. It’s pretty damned cool, and it works with Attachment_fu!
Full write-up, repository, etc is here
Posted by Matt
on March 25, 2008
HOW FAST IS IT?
git is so fast that it makes me feel like I haven't done much work. I used to wait so long for Subversion to checkin that I felt like I had accomplished something!
Posted by Matt
on March 24, 2008
I'm more than slightly amused to announce the birth of a new Ruby on Rails plugin, Scribd_fu.
Scribd is basically the YouTube for Documents. It's super awesome when you have a huge PDF that would take quite a tick to download; with this you can view your document in Flash format online, inline, and quick. Scribd_fu will allow you to seamlessly CRUD any document to a Scribd Document. The aim is to also feature full integration with the venerable Attachment_fu plugin. Scribd is a really great service with a ton of potential. It's fast and reliable to boot.
If you're a githubber, click that 'watch' tab and we'll see where this goes!
Posted by Matt
on March 23, 2008
With the latest firmware release for Apple's Airport Extreme Base Station router comes the ability to use a connected USB drive as a Time Machine backup disk. I (and many others) have waited for this feature since Leopard's release six months ago.
The big question is if it would work as expected. In my case, my Macbook easily found the drive and Time Machine recognized it. The initial backup (50G) took all night even with a supposed 100MB throughput. Subsequent backups were slow to complete, if they even started at all. Most of the time (80% or so), Time Machine would hang with "Preparing Backup".
One other thing that slightly annoyed me was that Time Machine creates a sparse bundle image on the AirDisk containing your backups. I assume this is done as many people can potentially use the AirDisk for backups. This causes two mounts on your system instead of one. Not a huge deal, but it's just one more thing that can fail. I don't like things that can fail in a backup process, especially one that is designed to be so behind the scenes.
Right now, Time Machine is doing its initial backup again as a USB connected drive to my trusty Macbook. The AirDisk seems to still have some quirks that need to be ironed out.
Also of note, I suffered a hard drive crash last week and luckily I did have Time Machine backups. I have to say that restoring Leopard from Time Machine was effortless and it was also the very first time I've had a full restore of an operating system actually work in over a decade of Windows, Linux, and Mac usage!