1
2
3
4
5
<h1>hello world</h1>

apropos

'fitting words'

(our blog)

Test Spec and the Double-R

April 14th, 2008

by David South Jr

Last year we did a project with substantial business logic requirements. The Rails testing framework saved us. We could create tests for all the different uses of the system and ensure that these rules were always followed. As wonderful as it was, there was a bitter aspect to Rails testing—fixtures.

Using fixtures to test the database layer for an individual model was fine. However, we built a class that would manipulate a half-dozen models. Ensuring that all the fixtures were perfectly synchronized was beyond painful. If we added a fixture to test some small new feature, the additional fixture would ripple through the tests causing failures on code that had nothing to do with the new feature.

We needed something better.

Read the rest of this entry

by David South Jr

There are several ways to set up a system for Ruby on Rails development. Leopard comes pre-installed with Ruby and Rails and is perfectly fine for most users. For me, however, I kept running into troubles. Trying to do a free standing install of graphic libraries (FreeImage or ImageMagick) proved too painful. I switched back to using MacPorts.

Read the rest of this entry

by David South Jr

I was sightseeing around San Francisco one very rainy day. It was 1990 and I wanted a CD player. I was also broke. CD players were still rather expensive. So I’d been shopping around for a while. I knew the prices, but they were just barely out of my reach. So I was biding my time, checking every electronics store I saw.

That day, as I wandered around downtown, I found a small shop at the base of a skyscraper. It had a window front on the street with electronics from top to bottom. Inside, it was packed. I’ve never seen so many electronics in such a small space. It felt like a sardine can of circuits, chrome and black plastic.

I made my way over to the CD players and found the exact portable CD player I wanted to buy.

In my research, I found that the player sold for $250. Some places down about $215. Others as much as $300. But $250 was the normal amount. My hope was that it might, just one day, drop to around $150.

So I picked up the player and turned it over to see the price. I nearly dropped it. The sticker said $1000—a 400 percent markup compared to all other stores.

Read the rest of this entry

Upgrade to SuperRedCloth

February 22nd, 2008

by David South Jr

RedCloth doesn’t properly parse correctly. A big problem is the way it handles dashes. A double dash -- is supposed to be converted to an em dash. However, if you use two double dashes in a sentence -- like how Freda commonly does and like I am doing now -- it converts them into a strike. Yuck. Strike is so rarely used. This - is how it looks - with two double hyphens.

Read the rest of this entry

by David South Jr

Having a current copy of your credit record is vital to protect yourself from credit errors and identity theft. And, thanks to Congress, getting a copy is extremely easy. By law, everyone is allowed to download an annual copy of their report. But be warned. The website advertised on TV, freecreditreport.com, is not the right place to go. It is a scam run by Experian to get people to sign up for an unnecessary yearly service. The correct website is annualcreditreport.com.

Read the rest of this entry

by David South Jr

Updated: Saturday, 7 June 2008, 2:37 PM

SWFUpload

SWFUpload is a fantastic application which makes short work of a hard problem—how to upload multiple files to a website. Most solutions using Ruby on Rails revolve around multiple fields and complex ajax calls to monitor the upload progress. These are all hard to implement because they lack compatibility across browsers, require difficult server set up, and usually fail to update quick enough to give real upload progress feedback to the user.

SWFUpload elegantly solves this problem by using a hidden Flash movie, clever Javascript callbacks, and CSS. It is cross-platform (Mac, Linux or Windows) and cross-browser (Safari, Firefox, IE) compatible.

For example, the process for a photograph website works something like this:

  1. The user clicks an “Upload photos” button.
  2. Instead of the standard browser “open file” dialog, a javascript call initiates the hidden flash movie’s “open file” dialog.
  3. The user can shift- or control-click one or more files to upload.
  4. The flash movie receives the file list and initiates a javascript call.
  5. Javascript POSTs the first filename to the server, just like a standard HTML form would do.
  6. The server begins receiving the file.
  7. The flash movie watches the upload, sending periodic javascript calls which can be turned into a dynamic upload progress bar. Because it is a client-side progress indicator, it is accurate and updated frequently.
  8. The server reports a successful upload.
  9. The javascript runner pulls another filename from the flash queue and initiates the next upload.
  10. The process repeats until the last file is uploaded.

From the server’s point of view, it’s the same as a user uploading one file at a time—greatly simplifying server set up.

AttachmentFu

Rick Olsen programmed the best attachment plugin for Ruby on Rails—attachment_fu. It manages the server side upload process, storage, and retrieval of almost any attachment. For photographs it manages resizing and thumbnails, too. Storage options include saving to the filesystem, saving attachments into the database, or saving onto the Amazon S3 storage network.

Mike Clark of The Pragmatic Studio has written a great tutorial for attachment_fu.

Put it all together

To combine SWFUpload and attachment_fu is to use the best of both worlds—a powerful client (swfupload) and server (attachment_fu) upload process. After a lot of research, I put together a sample application that combines Ruby on Rails, AttachmentFu, and SWFUpload.

This application is based on the PHP application demo included in the SWFUpload demos.

This is a simple demonstration of how all these components can work together. Go through the code, pull it apart, read the SWFUpload documentation. Then adapt it for your own use.

Download

The public repository for rails-swfupload is on github. To clone the repository:

git clone git://github.com/davidsouth/rails-swfupload.git

Contact

If you have any suggestions, tips, bugs please email dave at appeddesign.com.

Requirements

  1. Ruby on Rails 2.1.0
  2. Freeimage
  3. Ruby gem image_science
  4. SQLite3 or MySQL

Included in this application:

  1. SWFUpload 2.1.0
  2. attachment_fu (7 Jun 2008)
  3. mimetype-fu (7 Jun 2008)

Mimetype-fu

Flash sets the mimetype for each file to application/octet-stream. Attachment_fu requires the mimetype to be set correctly before it will accept the files. Matt Aimonetti wrote mimetype-fu to help attachment_fu properly set the mimetype.

attachment_fu_hack

Using an evil twin plugin, I overrode several standard AttachmentFu methods.

  1. Uploads through SWFUpload will automatically detect mimetype.
  2. Transliterated uploaded filenames have extra underscores removed and the whole filename is downcased.
  3. When running tests a temporary directory is used rather than the public/photos directory

Functional Test

I added two functional tests for the photos controller. It tests both create and swfupload. Since each time the test is run, it adds a file to the temporary directory, the same test will destroy the photo as well.

Leopard Tips

To upgrade Mac OS X 10.5 (Leopard) to the latest version of Rails, first upgrade ruby gems (sudo gem update—system) then update Rails itself (sudo gem update). To install FreeImage and image_science, I suggest installing Macports and then using port to install FreeImage (port install freeimage). Use gems to install image_science (sudo gem install image_science).

Remember to install XCode tools (on Leopard install disk) before you can use Macports.

You can change the photo model to use mini_magick or RMagick in combination with ImageMagick. However, in my tests, I’ve found FreeImage/image_science to be much faster than ImageMagick/mini_magick.

Links

Useful links and related information found while researching this project:

Todo

  • Implement best method of passing session data through SWFUpload.

Quit typing like a spider

November 6th, 2007

by David South Jr

In 1994 I took a Sharpie and wrote out the alphabet on my computer keyboard. Then I took little pieces of clear tape and carefully covered each key to keep from rubbing off the newly written letters. Why would I do this? Because my hands were starting to hurt and I needed a better way to type. Dvorak was the key. Not the columnist but the researcher who created the world’s greatest keyboard layoutAugust Dvorak.

Read the rest of this entry

Leopard auto-saves SSH keys

October 29th, 2007

by David South Jr

One of the biggest pains with Tiger is saving SSH keys. Yes, you can create them and save them under the .ssh directory. You can also load them into the terminal using ssh-agent. But the moment you closed that terminal window, it would lose connection with ssh-agent. So I had to load a third-party ssh-agent application called SSHKeychain. It worked just fine, but about once a day it would spin off a runaway process that would slam my CPU to 100 percent. SSHKeychain is incompatible with Leopard. So what was I going to do now? Leopard had an answer—a built-in ssh-agent tied to the Leopard login keychain.

That’s right. The first time I ssh’ed into a remote account, Leopard popped open a dialog box asking for my ssh-key passphrase and then offered to save the passphrase into the login Keychain. That’s it. No more configuration. I can freely log into any remote shell that uses my key and do so securely—right out of the box.

I’ve read story after story about developers going crazy over Leopard. They claim it is the most developer friendly OS on the market. With little tweaks like this, I believe it.

Reading list for the iPhone

August 23rd, 2007

by David South Jr

There are many excellent articles and essays on the web. These articles, when found, take time to read and digest. Time I usually don’t have at that moment (I’m usually researching something else). In the past I would save the link on my desktop and promptly forget it. Eventually I’d delete it because I’ve always got other things to do on my computer. I could print the page. But then I’d have to carry the paper and remember to read it instead of remembering to read the link. Same problem, different medium.

The iPhone has such a high-resolution screen that I find it easy to read websites and emails. Plus the iPhone synchronizes bookmarks with my computer. Now when I find a useful article I want to read later, I save it as a bookmark in a “Read” folder. After I sync the iPhone, the “Read” bookmarks are updated and I can pull the article to the iPhone anytime I find myself sitting with a few minutes to spare.

by David South Jr

Security is a pain. Too much security gets in the way of productivity. Too little and the world owns your bank account. Finding the right balance is difficult. For me, securing my laptop has proven to be a challenge. Sure, I can lock it down so it requires a drop of blood every time I wake it up, but that’s too painful (and I need the blood). So I found a decent balance that you may want to try.

Read the rest of this entry

by David South Jr

The day I read Getting Things Done by David Allen, I realized I was using my Palm Pilot completely wrong. I’ve had one since 1996 and never used it effectively. After GTD, I erased the Palm and redid everything from scratch. Here is what I do now.

Read the rest of this entry

by David South Jr

Our garage door wouldn’t close. We’d hit the button, it would start closing, then stop, then roll the door back the little bit it had moved down, and the light on the opener would flash 10 times. I think it was trying to say something. After careful research over the next few weeks, a lot of thought, and a clean wet rag—we fixed it.

Read the rest of this entry

by David South Jr

Our Canon MP500 ink-jet printer was not getting the job done. Sure, it worked okay if you printed from the Mac Mini the printer was connected to. But sharing the printer, through the Mini, over the network was a failure. The problem always happened if one of the kids turned off the printer. After it was turned on, it would not accept jobs from networked computers.

I moved the Canon to an Airport Extreme which handles printing from the network directly through a USB interface on the wireless router. No good. It just didn’t work. The Canon must not notify the host computer that it’s working and ready. Once the printer is shut off, even for a moment, the link would be broken and I’d have to restart the whole setup to print even a single sheet.

We needed a better solution and found it at Sam’s Club—the HP 6150 All-In-One.

Read the rest of this entry

by David South Jr and Michael South

The new iPhone has the best mail client I’ve ever used on a smartphone. When I first got my iPhone, I immediately connected it to my Gmail account. Unfortunately, Gmail uses POP to download messages. It started sending every single message from my archive—thousands of messages.

What’s worse is the lack of synchronization between my iPhone and the Mail program on my MacBook because of POP. If I delete a message on the iPhone, the message remains on Mail. I needed a better solution and it was Mike who came up with the answer. He suggested using .Mac and Gmail as a Mashup. Here is how it works for me.

Read the rest of this entry

Conflict

June 25th, 2007

by David South Jr

Conflict. It is the heart and soul of reality television—of all television, really. Without conflict there is no story, no ratings, and no show. Take Survivor (please?). In real life, if 12 random strangers were stranded on a deserted island, would they plot against each other? I doubt it. They would need to learn to get along, to work together, or else they would die.

To make a television show, you would need to find personalities that thrive on conflict, have extremely differing opinions, and then create an artificial situation where backstabbing is required to win. Now you have a prime-time show. That’s what counts as good television in the 21st century.

Read the rest of this entry