DICOM Image Plane Editor

Recently I had to have a few MRIs done. Many times in an MRI more than one view of the body is taken. Most DICOM software will allow you to compare two series and will show lines indicate where each view is on the different image. If you have moved, even 1mm, in the MRI machine these numbers will not match up, making visualization a little difficult with the lines off.

To solve this, I wrote a ruby script. Point it to a folder full of DICOM files and it will allow you to apply an offset to the image plane in a series. You can then visually match features and apply an offset to have a more accurate view of where you are looking at in the body.



I came across a post the other day for Devd. It’s goal is to be a simple webserver for developers, if you just want to host some pages to look at. I think this is a great idea but because I typically am doing full applications instead of just javascript there is already a development server for my environment ready to go. Definitely something to keep an eye on but it wont change my day to day.

devd: a web daemon for developers

Extracting images from text mail archives

When you back up or save emails, one format of doing so is in plain text. The attachment to emails are then stored as base64 encoded data in the file. I wrote this script to find known signatures of emails in base64 attachments and write the images out to the disk.

Simply pass it in the file name you want to read from, or it will read from stdin. This just goes to show Ruby still has very high performance, on my system it was processing a test file at 50+ MB/sec. Full code after the break.


How to recover data from .7z files

Suppose you have a .7z file, and the archive is “corrupt”. If it is not corrupt, but missing the end of the archive you will get an error. Here is how you can recover at least some of the data from that.

First step is to take the bad file and see how long the archive is supposed to be. The header has a pointer to the end header in it. At offset 0x0C in the start header is the offset of the end header, stored in 8 bytes.  The next 8 bytes is the length of the end header, which means the end of the file.

Now that you know how big the file was supposed to be, you can recover all of the data that you have but all of the files will be concatenated together. You don’t know the length of any of them, or even how many separate files there are. The important thing though is that you can extract the data.

Windows 10 IoT

I myself am not much of a Windows developer. I have messed around with winapi code a while ago, and some VB.net course in college, but otherwise have developed in other environments. This may change shortly with this new Windows 10 IoT that has been released. Especially seeing that it has Python and Node.js support, I am excited to see if I can try it out.



I recently came across an article, Writing a Primitive Debugger. It goes through what a debugger does and the basics of how one functions. I was reminded of a debugger I created for Rhomobile’s Rhodes applications.

There are some key differences between the two. As mentioned in the linked article, a debugger needs a few basic functions to be useful. My goal was to have a useful debugger that could stop at a breakpoint, inspect variables, and execute arbitrary Ruby commands. I had read an article about using GDB to debug Ruby and started initially with that approach. At this point, I really wasn’t writing a debugger but a UI for GDB and Ruby. This worked great when running on the iPhone simulator which runs as a process on the local machine, but did not work on mobile devices or any other platform other than the iPhone simulator.

My approach to this was to work at a little higher level. One interesting feature I had come across in Ruby is set_trace_func. When set, the execution steps of the Ruby VM also trigger your trace function. While this does significantly slow the program down, it allows you to accomplish nearly everything you need to do for a debugger. I adapted this to allow debugging of the application via a TCP connection. I may go into detail later, but you can see the original code that I wrote for this here. It has since been expanded to the full debugger that is being used today, adding complexity and integration with an existing IDE.


Don’t reinvent the wheel

When working on a development project, there are often tasks or features that are common for that type of project. For example, a website may need user management, or a batch processing system needs a queuing system. One thing you should always keep in mind is to not reinvent the wheel.

There are many libraries available depending on the choice of language and environment. Ruby has a plethora of gems that tackle almost everything imaginable. Python has pip which is very similar to ruby gems. Before you decide to roll your own implementation from scratch, you should always take some time and see what is available. You may be able to find a package that fits your needs and can be reused saving valuable development time.