Introductions are always awkward so I’ll just get right to the point. I’m Matt Warren and I work at Safari Books Online’s newly acquired publishing division, PubFactory. Specifically, I was their Lone SysAdmin. I’ve been with PubFactory for slightly over 18 months. But that’s enough about me.
What the Heck is Waldo?
About a year ago one of my coworkers pointed out that we send an awful lot of email about where we are that day. Some people go out on sales trips, some people work from home to take care of home things, some are sick, some leave early… you get the picture.
At the time, these emails went to the whole company and everyone either read, promptly deleted, or skipped over it altogether. For some, it seemed like an inefficient use of time. There were two major proposed fixes. One, send all this email to a different list. Two, send it to some database that would record it for any interested parties.
Solution one was, naturally, incredibly easy. I set up a list named ‘whereami’ and after some discussion over the existential theme of the list, people quickly adopted its use.
Solution two seemed like a fun project so I captured the idea in a Systems ticket and promptly filed it away to be dealt with another day. Then over the September Labor Day weekend, I sat down in my family’s cabin in Maine, decided to learn Ruby on Rails and created Waldo.
I implemented a fair amount of the functionality in that weekend. Ruby on Rails has a fantastic little command
scaffold that allows you to create a schema and the necessary pages/functions to create, display, edit, and delete data. Some people will tell you not to use scaffolding to create your app. I was following a guide and it made my life super easy.
Looking back, I’ve made some major changes since creating that scaffolding but it allowed me to demo the project after my return from the weekend. I also used scaffold in the Engineering Programming Challenge and got a serious leg up on the non-cheating competition.
Anyway, after a weekend of work, I had the basics of a site, something I could call an alpha release. Part of that was a script that would allow users to email the app and feed it into the database. Parsing through raw email headers to get the From, Subject, and Body was a good challenge. Similar to the site layout, I had the basic functionality done and successful tests with some cleansed inputs.
Remaining tasks were to clean up email parsing, get/process the “date out”, disallow duplicate email addresses, style the app, and create a script to clean the database. I didn’t want this to be the de facto solution for time-off. I suppose it could be but the immediate use case was to find out where people were today. Just to be clear, I didn’t style it well. I took that task as a challenge to learn CSS and leave the real styling to someone who knows how red and blue can really coexist on a page.
Development Phase 2
During the recent snowmageddon, I had plenty of time to polish up the project. A large amount of focus went into the email parsing script. I had real inputs now and there were extra headers or unexpected characters that had to be stripped out.
An example of one of the more difficult formats (don’t worry, I asked for permission):
12345678910111213 ------=_Part_25652_32303157.1360171018160Content-Type: text/plain; charset=utf-8Content-Transfer-Encoding: quoted-printableStaff meeting first and then getting my hand checked out. I wont be back to=day but you can reach me by cell if you need me. HUGE thanks to Lao, Melani=e and Marc for the help.=20Have a great day guys.=20--=20Name Name=20Some Title=20More Signature Stuff=20Even more signature=20and so on=20
The result isn’t quite ideal but definitely readable.
1 Staff meeting first and then getting my hand checked out. I wont be back to=day but you can reach me by cell if you need me. HUGE thanks to Lao, Melani=e and Marc for the help.Have a great day guys.
That was all pretty standard Ruby text processing. The fun part came when processing the subjects for what date the user planned to be out. At first, I thought I was going to write how to handle today, tomorrow, this Thursday, Next Monday, etc. With the power of Google, I found a nice little gem (Ruby joke, ha) by the name of Chronic. Once I had that, it was just a simple regex and function call to get the date I needed. I was even able to catch multiple dates in an email (i.e. Out Tues and Wed). Of course I realize now I have a potential bug.
subjects = subject.scan(/(today|tomorrow|next w+|this w+|monw*|tuew*|wedw*|thurw*|friw*)/i) if subjects.size &gt; 0 subjects.each do |dates| dates.each do |date| active_date = Chronic.parse(date).strftime("%Y-%m-%d").to_date Users.create(:name => name, :email => emailaddr, :status => subject, :notes => notes, :active_date => active_date) end end else active_date = Date.today Users.create(:name => name, :email => emailaddr, :status => subject, :notes => notes, :active_date => active_date) end
I won’t go through the rest of the code right now. If you’re that interested, I encourage you to browse through or fork it! I am happy, however to announce that the Beta 2 release came out on 11 Feb! I have some bugs to work out and I’d like to get a real Front-end Developer to look at the styles before I call it stable. That being said, I have to publicly thank Dave MacGugan, Ryan Pollock and Robert Hall for helping on ideas for how to get styles started. They will eventually make it into a file in the project.
My real motivation for writing this is to encourage people to run my app! I would greatly appreciate feedback on what I’ve done. As a disclaimer, I freely admit that I am a SysAdmin and not a programmer. That explains my confusion about the strange feeling I had in regards to the multiple
Users.create calls in the snippet above. Was it just a draft in my apartment or a voice telling me to write a helper function?