Richard Smith's Blog

The thoughts of an easily distracted software developer...

sudo

I’ve written a very simple helper tool to elevate processes on Windows. You can find the project at sudo and you can download at sudo - 1.0.1.

SMTPTester

One of the challenges I’ve had is testing SMTP server configuration’s supplied by our clients. Often there are problems with certificate validity or various other security settings. I wrote a simple tool to allow for testing/debugging from the command line. You can find the project at SMTPTester and the first version can be downloaded at SMTPTester - 0.1.0.

It allows you to send test messages, dump the certificate’s of the SMTP server to disk and optionally ignore certificate errors. There is detailed error logging available in verbose mode.

../../../_images/SMTPTester.png

Clearing a FTP directory with TeamCity & LFTP

I recently needed to setup a TeamCity build which deployed to an FTP site. Configuring the deployment itself was simple: just use the Deployer plugin to copy the build artifacts across.

Unfortunately the plugin doesn’t support cleaning out the destination directory before copying the artifacts. The solution was to use LFTP to run:

rm -rf /my/target/dir/*

There is a windows build of LFTP available here. You can then just configure a command line build step in TeamCity to run something like this:

lftp -u user,password ftp://my.ftp.site.com -e "rm -r /my/target/dir/*; bye"

Exif data analysis spreadsheet

Lately I’ve been debating my next lens purchase and trying add a bit of objectivity (not particularly easy) to the process. I started out wanting to do get some simple info on common focal length usage and came across ExposurePlot, however it doesn’t work with Canon raw files. I subsequently discovered the excellent ExifTool which works with just about every image format known to man.

I’ve put together a simple Excel spreadsheet to pull in data from ExifTool in CSV format and display a few charts based on the sliced and diced data. It is fairly easy to use:

  • Run the batch file to dump the data to CSV.
  • Refresh the data connections in Excel.

You get some nice charts to play around with:

../../../_images/exif_data_analysis_spreadsheet_1.png

You can grab the spreadsheet and batch file here. N.B. This is released as is without warranty of any kind. Use at your own risk. You’ll need a copy of ExifTool in the same folder. Run the batch file passing in the folder where the images you would like to analyse are; then open the spreadsheet and refresh all.

Profiling a unit test in VS2012

Just a quick useful tip, you can run the Visual Studio profiler on a unit test. It’s fairly well hidden but you can access it by right-clicking on a test in the “Test Explorer” and selecting “Profile Test”:

../../../_images/profiling_a_unit_test_in_vs2012_1.png

Very useful and well hidden feature.

Runtime architecture detection & DllImport

I have been playing around with the excellent Math.NET Numerics lately and wanted to see if I could use native MKL libraries with our product. A requirement of this would be that we could ship an Any CPU version of the application and detect which native library to load. Normally this is fairly easy with .NET assemblies as you can just hook into the AppDomain.AssemblyResolve event. You then do something like this:

private Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    Assembly asm = null;
    string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    string asmName = string.Format("{0}.dll", args.Name);
    string asmPath = string.Empty;

    if (Environment.Is64BitProcess)
        asmPath = Path.Combine(appPath, "x64", asmName);
    else
        asmPath = Path.Combine(appPath, "x86", asmName);

    if (File.Exists(asmPath))
        asm = Assembly.LoadFile(asmPath);

    return asm;
}

This unfortunately doesn’t work with unmanaged assemblies referenced with a DllImport attribute. These assemblies are loaded using the standard windows loader which lives outside .NET. What you can do however is use the SetDllDirectory system call to insert an additional search path for the windows loader before loading takes place. You can then call SetupNativeSearchPaths on start up (or some other time before the unmanaged assembly is loaded):

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetDllDirectory(string pathName);

public static bool SetupNativeSearchPaths()
{
    string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    string asmPath = string.Empty;
    if (Environment.Is64BitProcess)
        asmPath = Path.Combine(appPath, "x64");
    else
        asmPath = Path.Combine(appPath, "x86");

    return SetDllDirectory(asmPath);
}

New theme & Tinkerer update

Tinkerer has released V1.2, I’ve just updated to the latest version and the new “flat” theme.

Installing pip on windows

Quite often Python projects recommend the use of pip for installation. For example tinkerer recommends that you install using:

pip install tinkerer

The problem is that pip and it’s dependency distribute aren’t supplied with the default Python install on windows. Additionally a simple there isn’t a convenient windows equivalent of:

sudo apt-get install python-pip

It took some figuring out how to get hold of pip and its dependencies on a windows machine. I’ve listed the steps required below.

Read more...

First steps...

I’ve decided to try and capture the various interesting (or not so interesting) things I discover on a day to day basis. Additionally this should give me a chance to learn a bit more about python and web development on the side (I’m primarily a C# developer who works on a desktop/server based platform). So far it looks like I’ll be running this blog using Tinkerer and hosting it on App Engine. I should have some details of the setup process up shortly.