Monthly Archives: January 2011

The Chase

January 30, 2011 » Life

So guess what Darcy and I did Friday night? That’s right, made a lame awesome movie. It’s called The Chase

You’re welcome.

Thursday Quote: Tim Berners-Lee

January 27, 2011 » Geek, Life

“Neither governments nor corporations should be allowed to use disconnection from the Internet as a way of arbitrarily furthering their own aims.”

Tim Berners-Lee

Swiftmailer Transport for Amazon Simple Email Service

January 25, 2011 » Geek

Updated (2011-02-03)

On the suggestions of Chris Corbyn I re-wrote my class to use direct access and the Swiftmailer byte stream interface, no cURL anymore. It’s way faster, and way cooler, if I do say so myself. You can get the latest at https://github.com/jmhobbs/Swiftmailer-Transport–AWS-SES

So, today Amazon debuted Simple Email Service. The gist of it is, send mail with them instead of your own servers. Like a feature reduced SendGrid or Postmark.

Not a lot of stuff out there for it so I thought I’d jump the gun a bit and write a transport for PHP’s Swiftmailer. If you have to send e-mail from your sever and from PHP, Swiftmailer is your best friend.

Never dug into Swiftmailer’s guts before, but it’s pretty well laid out. All you have to do for a new transport is implement the send method of the Transport interface and you are done.

I knocked mine together pretty quick, and the only code I cribbed was the HMAC code from php-aws, because AWS was rejecting the output from hash_hmac. (Which I literally just figured out while I wrote that paragraph. Works now.)

So how hard is it to use? Easy as any other transport in Swiftmailer.

So, yeah, it works.

I know there is a ton of stuff I didn’t implement that I need to before this could be “production” ready, but it was a very satisfying little project.

You can grab it here: https://github.com/jmhobbs/Swiftmailer-Transport–AWS-SES

Gson Inheritance Issues

January 24, 2011 » Geek

So, work has me writing Java for the first time in my life. I needed to handle some data in JSON format, and was using Jackson and it’s ObjectMapper for a while. Fast and a relatively nice interface.

Today I switched to Gson for the even simpler API. It’s slower, but I’m just munging little strings every once in a while, so that’s not a problem.

The one thing I came across today that didn’t go as expected was serialization with inheritance in my objects. Here’s where I started:

I expected to see the JSON representing of each. Much to my surprise, I got this instead:

What the what? Weird. So I thought I’d try adding a constructor and setting it there.

Again, no luck! I got the same output as before. I gave it one last shot.

That time I got it.

Strange. So it seems that when serializing an object, Gson looks for the value of a field in the superclass. However, when you are in the object you are accessing the local field. It seems like a weird scope thing. Interestingly, if you provide a new implementation at the subclass level it will use that one instead.

This seems to be noted in the user guide at “Finer Points with Objects“. I must have just missed it.

Fields corresponding to the outer classes in inner classes, anonymous classes, and local classes are ignored and not included in serialization or deserialization

Easy enough, though a little annoying.

Thursday Quote: Abelson & Sussman

January 20, 2011 » Geek

“Programs must be written for people to read, buy and only incidentally for machines to execute.”

– Abelson & Sussman
Structure and Interpretation of Computer Programs

Tags: