If you get stucked with a RoR error, restart script/server

Yesterday I had an idea for a web app (again!). I decided to sketch it out using Ruby On Rails as a way to experiment what’s outside the .NET ecosystem. Besides, if the idea finally crystallizes, it will fit much better in a Linux box than on a Windows server mostly because I think it will be hard to find a good revenue model.

This post is just a note to myself. I have to admin than I’m totally lost with RoR for now. I’m following several screencasts and reading every beginner’s tutorial I can find.

Following one of those tutorials I got stucked. I checked my config files, checked that I had not misspelled anything but nothing came out.

Finally I saw an error on the server log:

Rendering rescues/layout (internal server error)

That error message was logged 55 minutes ago!! Just restarting the ruby server made my error go away. This is the second time this happens, so I’m writing this post as a reminder. Depending of what files you touch, you could need to restart your app.

Moving from Subversion to Mercurial

mercurial I’ve been using Subversion for the last 5 years and it has served me well. I can’t conceive writing any meaningful code without using it. Using a source control tool is the definitive backup tool for your code and you should be using one no matter what.

Because I work mostly alone, merging has never been a real issue for me. Mainly because I rarely branched my code to work on different branches in parallel.

I used to have just a main branch (trunk) where I add new code. When the code it’s ready to release, I tag it and branch it. Then I continue to add code to the trunk. The branch is used only for maintenance of the shipped code.

When I touch code in the maintenance branch I can merge with the trunk or usually just fix the code in the trunk manually.

That’s it. No branches per feature, usually no experimental branches, life was easy.

However, as some of my projects begun to get momentum (read ‘get real paying customers’), my needs started to grow.

Now I have to have more than one active maintenance branch. I also need branches to develop some custom modules for some customers, and as my time to develop a single feature grows I also need branches to develop features that need a long time to complete.

If you branch a lot you have to merge a lot.

This implies that if you have problems merging you’ll try to avoid branching, and if you can’t branch as needed your source control tool is failing you.

I’ve been avoiding branching in subversion because the merging is sometimes complicated. More than once I end up applying changes manually or overwriting files from folder to folder. Not fun.

I started paying attention to all the buzz about git and its branching/merging model. I installed it and played with it. I saw the benefits but I find some concepts difficult to grasp, so I continued to use subversion while playing with git. Then I found hgInit, a Mercurial tutorial by Joel Spolsky. Turns out that Mercurial it’s pretty much like git, but simpler.

There are some differences that I’m not going to describe here, but they are not as important as their similarities. The key here is that merging code works great!

If you are using subversion please take a look at Mercurial or git. They are a really a big step forward. They have a different model than subversion so it takes a while to grasp the difference between a centralized and distributed source control system, but it’s worth it.

Here are some links that helped me see light:

http://hginit.com/

Linus Torvals on git

Can’t modify my Visual Studio 2008 installation

I run setup to add the Web developer extensions to Visual Studio 2008 from the DVD and it complaint with the following message:

A problem has been encountered while loading the setup components. Cancelling Setup

image

What!!!

Ok, I know what’s going on. The DVD has Microsoft Visual Studio 2008 installation program, but I have Visual Studio 2008 Service Pack 1 installed.

So, I need to modify the installation using Add/Remove programs and select Uninstall/Change. Then I got this:

A selected drive is no longer valid. Please review your installation path settings before continuing with setup.

image

Oh, great!

After wasting some time through the internets, the solution was to uninstall the Service Pack 1, add or remove the features you want and reinstall Service Pack 1.

Hope this saves you some time.

Add a Firewall exception at install time using WiX

windows_firewall Although I’m not a heavy user of WiX, I’ve been using it for years to build my install packages. I’ve followed a couple of times the tutorial and then tweaked my source files from there.

I’m planning a new feature to one of my apps that basically will send UDP messages through the network in order to keep all the clients in sync. This of course will require a firewall exception.

I don’t want my users to configure the Windows Firewall by themselves if possible so I did a quick search and found that exists a WiX Firewall extension that does exactly what I need. It couldn’t be easier, adding just this line to my script and passing the appropriate dll to candle and light did the trick.

<FirewallException Id="FWX1" Name="Panel" Scope="localSubnet"
        xmlns="http://schemas.microsoft.com/wix/FirewallExtension" /> 

By the way, I’ve tested it with the Windows Firewall set to Off and the exception is added anyway, so if the user turns it on the exception is already there. Unfortunately it doesn’t work if the Firewall service is not started. Adding the attribute IgnoreFailure=”yes” to the previous code will avoid an error message.

Also if the user has a third-party firewall I’m pretty much in the starting row. However I hope this won’t be the setup of most of my clients.

How to monitor serial ports in Windows

Lately I’ve been doing a lot of serial programming in C# to communicate medical equipment with a Windows Forms applications. If you have ever tried it you’ll know that serial communications in .NET, although conceptually easy, have a lot of little quirks. Sometimes you wish to monitor exactly the traffic that is flowing in the serial port.

Unfortunately there’s no way to open a serial port which is already in use. One possible solution is to use a Y-cable and split physically the cable. Today I’ve discovered a very nice tool from SysInternals (Microsoft now) called PortMon. It is capable of monitor and display serial port activity and it can even do it remotely. Basically you get a serial port sniffer.

If you just care about the OPEN, CLOSE, READ and WRITE operations, open the filter dialog and type:

IRP*

If you are doing any kind of serial port programming this tool is highly recommended. 

Activate OpenSSL extension in PHP

Some time ago I coded a small web page to generate license files for one of my clients. This is a very simple app that basically allows you to enter some customer’s info and generate an encrypted license file. I’m not a PHP developer but the language is very similar to C and a good framework helps a lot. In my case I use CodeIgniter, which is just great.

Anyway, today I needed to install this app on my laptop (which is running Windows 7 x64 by the way). I installed a fresh copy of XAMPP Lite, created my database and run the app. Everything worked fine except the function that generates the license file.

Fatal error: Call to undefined function openssl_get_privatekey() in C:\....

My initial reaction was to think that I needed to install the OpenSSL libraries, so I wasted half an hour looking for the files and reading how to install the binaries. But it was easier than that. XAMPPLite already installs all you need, you just need to activate the extensions you need. In this case I needed to edit the php.ini file and uncomment the line:

extension=php_openssl.dll

Also, if you need to know which extensions are activated, a call to phpinfo() will give you the answer.

xampp_phpinfo