Archive for May, 2009

Best explanation of monads I’ve seen yet

Thursday, May 14th, 2009

I stumbled on this today. I don’t know why, but I’ve always had a block over what the word “monad” actually means, and how the bind and return operations map to that meaning.

In the linked StackOverflow post, there is a single sentence that fixes the problem:

An alternative term is computation builder which is a bit more descriptive of what they are actually useful for.

Ah-ha! The rest of the post is made up of some great examples. Go read if you’re as confused as I was.

Client uploads to Amazon S3

Tuesday, May 5th, 2009

As part of the spangly new and exciting project I’m working on, I’ve got a dumb JRuby client app that runs on the user’s desktop, which I need to have upload data to my S3 buckets. I pondered and read for a bit. S3 is new to me, so I was wandering off down the path of “touch the key with a public-writeable ACL, wait for a completion notification callback, then close the ACL.” This, obviously, is madness.

Luckily, the fine folks at Amazon have already thought of this, and provided a POST mechanism designed for browsers. It’s got a slightly strange gotcha, though: the uploaded file must be the last element in the POST body. This and Ruby’s default Net::HTTP API sent me looking for alternatives to building the post by hand.

The solution is quite neat. I’ve got a teeny Sinatra app sitting on the server whose only purpose is to serve prevalidated upload forms to authenticated clients. Auth is provided by Rack. The client just uses 6 lines of Mechanize code to fill in the form details and submit it to S3. It’s rather a library-heavy solution, but as a concept it doesn’t get much simpler.

And simpler is better.

Current Rails template

Tuesday, May 5th, 2009

For reference, here’s my standard Rails kit at the moment:

  • Authlogic for session handling.
  • Paperclip for uploads.
  • RestClient for remote service handling.
  • Mocha for mocking.
  • Webrat for integration testing.
  • Scaffolding_extensions for laziness.
  • Passenger/Apache for serving.
  • Vlad for deployment.

I want to add cucumber and thin to this, but cucumber has given me problems in the past and I just haven’t got round to trying thin out yet.

Entries (RSS)