Movember Day 24: Mustache in the Huddle House

I haven’t posted in a bit, but I haven’t thrown in the towel yet. I’ve been so busy I haven’t been able to say: seriously, I’m being goofy for a good cause, if you can, please donate. It’s only 6 days until the stache goes away. The mustache is temporary, a cure for testicular or prostate cancer can be forever!

20121124-084350.jpg

FFI for Ruby and an mp4v2 example

Previously on my blog: In my TiVo2Podcast stuff I automated the process of putting chapters around commercials, but had to call out to a small C++ app I wrote to put the chapters in using libmp4v2.

A few weeks ago I was looking at some ruby gems for a project I was working on and stumbled across ffi, a foreign function interface gem for ruby, or as its docs put it: “a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code.”  As long as you know the function signatures that you need, its pretty trivial to make the calls from Ruby. You do need to be aware of memory management stuff sometimes, but overall its pretty easy, especially for basic use. If you’re only going to be working in Ruby and need access to a C library, this is much easier than mucking with swig, that’s for sure.

The mind-blowing part for me is that the authors of the gem have made it smart enough to know what flavor of ruby vm and platform the code is running in and it does the right thing, no matter if its JRuby or on Windows or whatever. While I haven’t had a chance to use it yet, I suspect this property will be useful with JRuby at work in the future.
Continue reading ‘FFI for Ruby and an mp4v2 example’ »

Using Ruby with Viewpoint unhork an Exchange mailbox

(It’s been awhile since I’ve done a technical post, so I may do that on the next few.)

Through some craziness we haven’t figured out, a user at work managed to get over *pinky to mouth* one million items in their Deleted Items folder in Outlook which is hooked up to our Exchange server. This turned into an interesting problem.

Needless to say, that is a stupid amount of items that Outlook had issues with processing. Telling Outlook to empty the trash would send it out into la-la land as a hung process. I’m thinking it was trying to pull all million items into memory to do a delete on them. I’m sure if we let it sit long enough it may have done something, but it just really didn’t like that volume of stuff.  Similarly, using another Exchange or IMAP client like Mail.app, Thunderbird, and mutt had similar issues as they needed to retrieve the million headers before they would do anything. Deleting it batches at a time by hand worked, but was slow and required someone to do it by hand which…we can see the issue there.

As is often the case, the solution to the problem could be had by creating a small script to do the pain in the butt stuff for you. Actually, the big reason a script works here is that it could be smart and just snag small batches and work on those. Luckily, a few months back I had played with Viewpoint, a “ruby client access library for Microsoft Exchange Web Services. Previously, I had used Viewpoint to read mail in a certain folder and generate stats for it, so using it to identify and delete messages would be a snap.

The first go around I was grabbing the messages in a batch and deleting them one by one.  That works, but was a bit slow.  I figured out how to do something that hasn’t been written into Viewpoint yet: a batch delete.  That sped up the operation by 4.5 times or so.  This still took over a day to run.  It also couldn’t delete everything.  For some reason it seemed to not be able to delete calendar invites.  After the script was running entirely, we were left with about 30,000 items left behind, but Outlook could handle wiping the rest of them out if we left it alone for 20 minutes or so.
Continue reading ‘Using Ruby with Viewpoint unhork an Exchange mailbox’ »