Category Archives: Software Development

This category contains all my posts about software development. Tutorials, solutions to problems I’ve met, interesting things I’ve stumbled over, code samples, stuff I don’t want to forget, et cetera.

Helpful Sublime Text 2 packages

Keep forgetting the names of packages I like to install when setting up Sublime Text 2. Or that I should install them to begin with. So here’s a note to self on packages I should install whenever I reinstall this fantastic editor. And a note to you if you use the editor and didn’t know such helpful packages existed.

  • Package Control, the package that adds a package manager to the editor. After that is installed, simply press Ctrl+Shift+p, bring up Install Package by typing “ip”, and hit enter. You can then search for packages and install them super easy.
  • Highlight, for copying syntax highlighted code either as HTML or as RTF. Nice for pasting code into emails, documents, etc.
  • Indent XML, for… indenting XML. Been very helpful for cleaning up messy SOAP requests from logs, etc.
  • LESS, for syntax highlighting of LESS files
  • Markdown Preview, for quick preview of markdown files in the browser
  • Text Pastry, for fun pasting madness. You can for example paste in sequences of numbers.

Use WinMerge for comparing archives with TortoiseSVN

I really like the Diff Viewer that comes with TortoiseSVN, but from what I can gather it doesn’t seem to support anything but text files, which is fair enough, but I need to compare archives as well. Zip and Jar files in particular.

WinMerge supports that, and can be integrated with TortoiseSVN very easily right through its installer. But I prefer the diff viewer that comes with TortoiseSVN and the archive diff isn’t recursive by default, so I decided to set it up manually.

  1. Install WinMerge
    (without the automagic TortoiseSVN integration)

  2. Install the WinMerge 7-zip plugin for archive support
    (I couldn’t get the shared install to work, so had to use the application specific one)

  3. Open TortoiseSVN Settings, Diff Viewer, Advanced
  4. Add rows with extension set to .zip, .jar and whatever archives you want WinMerge to handle and set external program to the following:
    C:\Program Files (x86)\WinMerge\WinMergeU.exe /r /x /e /u /dl %bname /dr %yname %base %mine

If I now for example ask TortoiseSVN for a Diff with previous version of a jar file, I get WinMerge with a recursive comparison of the archive contents. I also recommend that you deselect Show Identical Items under View.

PowerShell: Write stuff to an XML file

Needed to recursively list all the files of a certain type and save them as an XML file. Turns out this was pretty easy using PowerShell.

# Make a regular .Net XmlTextWriter
$output = "processes.xml";
$xml = New-Object System.Xml.XmlTextWriter($output, $Null);
$xml.Formatting = "Indented"
$xml.IndentChar = " ";
$xml.Indentation = "1";

# Start writing

# Do the listing and keep outputting XML
Get-ChildItem .. -Recurse -include *.esbp |
foreach {
    $name = $_.BaseName;
    $path = Resolve-Path $_ -relative;

    $xml.WriteAttributeString("id", $name);

# Close the writer, which also closes the root element and document for us

Easy peasy!

PHP: Simple directory recursion

Keep running into scenarios where I need to scan through a file system and it’s actually pretty simple if you just know what classes to use. So… note to self and others:

// This should return false if there is something you want excluded
function filter($file, $key, $iterator)
    $exclude = array('.git');
    return ! in_array($file->getFilename(), $exclude);

// Recursive directory iterator for current directory, ignoring dots
$it = new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS);
// Wrapped by a filtering iterator with our filter function
$it = new RecursiveCallbackFilterIterator($it, 'filter');
// Wrapped by an iterator which automatically traverses children for us
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);

// And then just loop :)
foreach($it as $file)
    echo str_repeat("\t", $it->getDepth())
        . $file->getRealPath()
        . PHP_EOL;

This skips the annoying dots, properly excludes directories you don’t want and pretty much works the way it should.

XSLT: Load XML or other text from external sources

Just discovered you can pull in external XML and other kinds of text directly through standard XSLT 2.0 methods. So here’s a note to self on how.


Example usage

<!-- Single string URI -->
<copy-of select="doc('')"/>

<!-- One or more URI from items, in this case a variable -->
<variable name="uri" select="''"/>
<copy-of select="document($uri)"/>

<!-- Unparsed text, in this case escaped HTML -->
<copy-of select="unparsed-text('')"/>

XSLT: Pull duplicate namespace declarations up towards root node

Sometimes XML becomes a bit weird with namespace declarations all over the place. This XSLT cleans that up. Stumbled upon in a StackOverflow answer I don’t find anymore and put here so I know where to find it in the future.

<xsl:stylesheet version="2.0" xmlns:xsl="">

    <xsl:template match="@* | text() | processing-instruction() | comment()">

    <xsl:template match="*">
        <xsl:copy copy-namespaces="no">
            <xsl:for-each-group group-by="local-name()" select="descendant-or-self::*/namespace::*">
                <xsl:copy-of select="."/>
            <xsl:apply-templates select="@* , node()"/>




<soap:Envelope xmlns:soap="" xmlns:wsa="">
      <wsa:MessageID soap:mustUnderstand="0">uuid:7fa12310-5db4-11e3-ae24-a3c913f2629d</wsa:MessageID>
      <wsa:To soap:mustUnderstand="0"></wsa:To>
      <ns1:getTicket xmlns:ns1="">
         <cus:msisdn xmlns:cus="" xmlns:soapenv="">00000000</cus:msisdn>
         <cus:ticket xmlns:cus="" xmlns:soapenv="">171</cus:ticket>


<soap:Envelope xmlns:wsa=""
        <wsa:MessageID soap:mustUnderstand="0">uuid:7fa12310-5db4-11e3-ae24-a3c913f2629d</wsa:MessageID>
        <wsa:To soap:mustUnderstand="0"></wsa:To>

If anyone know how to adjust it to also merge the duplicated prefixes ns1 and cus, do let me know :)

Tail less

I keep seeing people typing these lines in the console:

$ tail /path/to/some.log
$ tail -f /path/to/some.log

This is often a dumb thing to do. Why? Because you can’t really do anything with tail. What if you discovered you needed to look at something right above the lines you got printed out? Or what if you were -f’ing and something flew past you that you needed to investigate further? You’d have to leave tail and run it again with more lines or use a different tool instead. Not very practical.

What more people should do is to use less tail and more less :)

$ less /path/to/some.log

Things you can do with less



Up one line

Down one line

Up one page

Down one page

Beginning of file

End of file

ctrl + c

Stop follow


Search forward

Search backwards

Next search result

Previous search result

Much more flexible and handy than tail! Know your tools ;) Now back to work…