Archive

Archive for January, 2013

A HRON parser in Powershell

HRON is similar to JSON. Check it out here for more information. Friday fun; write a parser in powershell for HRON. Quick and dirty hack here.

Categories: Uncategorized

Yet another Sudoku solver

I revisited the dancing links algorithm for solving Sudokus. My previous implementation and post can be found here. This time I used C++. The most important difference, however, is that I realized that it is easy, and faster, to build the sparse matrix directly. Last time I created a dense matrix first.

The code repository is here; https://bitbucket.org/d95danb/cppdlx.

This time, I decided to also measure performance, using the same approach as attractivechaos in the blog post An incomplete review of Sudoku Solver Implementations. The author uses 20 really hard Sudokus that are solved repeatedly 50 times.

The bench marking machine I used for the test was equipped with a AMD Athlon 64 X2 Dual Core Processor 5000+ (2.6GHz) which Windows rated index 5.6 on the scale of CPU performance (5.1 considering the entire machine).

Given this, in release build, the resulting time was about 1.2 seconds which competes well with the other Sudoku solvers from the article.

Categories: Uncategorized

Geocoding using Powershell and Google Geocoding API

It has been a while since I blogged. I guess that, sometimes, there are other things in life that need contemplation than code (and sometimes there is just not enough time for contemplation at all).

Yesterday, I sat down and played a bit with the Google Geocoding API. Being to lazy to open visual studio I started out in Powershell. It turned out really simple and I ended up with the following code:

function Get-Location($address)
{
    $result = Invoke-WebRequest "http://maps.googleapis.com/maps/api/geocode/xml?address=$address&sensor=false"
    if ($result.StatusCode -eq 200)
    {
        $message = [xml]$result.Content
        if ($message.GeocodeResponse.status -eq "OK")
        {
            return $message.GeocodeResponse.result
        }
    }
}

Get-Location expects a string containing a location description such as “Avenyn, Göteborg, Sweden” and the result is an array containing all possible interpretations along with their geographical positions.

type formatted_address address_component geometry
route Kungsportsavenyn, 411 … {address_component, ad… geometry

This script uses Invoke-WebRequest which is a new command in Powershell V3. In can be replaced simply with:

$webclient = New-Object System.Net.WebClient
$result = $webclient.DownloadString($url)

which will work in V2 (and probably in V1 too but who cares, really?).

Categories: Uncategorized