1. 10:55 5th Dec 2012

    Vote on HN

    Using Oracle Text Search

    The author goes from creating the tables, a multicolumn index and queries it.
    I believe there is a better query, but that is still a good and simple start.

     
  2. 14:24 13th Sep 2012

    Vote on HN

    Testing the IDataReader mapping

    I don’t want to enter the discussion if you should or not use a datareader, this is another topic. I will just show how I test the mapping between the reader and my objects easily.

    First of all, I try to isolate the mapping from the rest of the code

    I usually create one class by mapping and pass it the datareader. I use this base class :

    public abstract class DataReaderMapperBase<T> where T:class
    {
          public abstract T Map(IDataReader reader);
    }
    

    A simple example of using this base class :

    public class PersonDataReaderMapper : DataReaderMapperBase<Person>
    {
         public override Person Map(IDataReader reader)
         {
               return new Person 
               {
                      FirstName = reader.GetString("Name"),
                      LastName = reader.GetString("LastName"),
                      ...
               }
         }
    }
    

    But how to test this? there is a simple way of stubbing a datareader using a DataTable and a DataTableReader. But that is still a cumbersome syntax, so I wrapped it in a helper that could take objects and transform them into a DataReader row. I will probably package a little better, but here is the raw draft, with an example of how you use it :

     
  3. 14:09 17th Jul 2012

    Vote on HN

    Notes: 1

    Tags: psakeCITeamCity

    Using psake to run your TeamCity continuous integration build

    Recently I had to setup a CI build in TeamCity.
    I already did this once using msbuild script, and met very quickly walls when I wanted to get into more advanced deployment scripts. So I looked for a different solution and found psake. From the github project :

    psake is a build automation tool written in PowerShell. It avoids the angle-bracket tax associated with executable XML by leveraging the PowerShell syntax in your build scripts. psake has a syntax inspired by rake (aka make in Ruby) and bake (aka make in Boo), but is easier to script because it leverages your existent command-line knowledge.

    DISCLAIMER : Works on my machine!

    The psake build script

    At the top of my default.ps1 I have

    properties {
        $home = $psake.build_script_dir + "/../.."
        $sln_file_server = "$home/Server/Server.sln"
        $sln_file_client = "$home/Client/Client.sln"
        $sln_file_common = "$home/Common/Common.sln"
        $configuration = "Debug"
        $framework = "4.0"
    }
    

    My build script is not at the root of the repository, so I adjust a $home variable myself.

    And here are my tasks :

    task CompileCommon {
      exec { msbuild "$sln_file_common" /p:Configuration=$configuration }
    }
    
    task CompileClient {
      exec { msbuild "$sln_file_client" /p:Configuration=$configuration }
    }
    
    task CompileServer {
      exec { msbuild "$sln_file_server" /p:Configuration=$configuration }
    }
    
    task All -depends Clean, CompileCommon, CompileClient, CompileServer {
    }
    

    Awesome, but the integration with teamcity has some surprises (fortunately relatively simple to overcome). In short, Powershell does not use the exit codes of the programs you launch from it. If msbuild exits with the code 1 (for failure), the powershell process will still exit with the code 0 (success). Unfortunately, this is what teamcity is looking at to tell if the build step passed or failed.

    I ran into this problem and had a hard time making the build fail when the compilation was failing. Here is how I solved it, which is similar to what the wiki says:

    Make TeamCity fail when the compilation fails

    I fixed this in the teamcity build step setup. I have tried multiple things (running the psake.cmd didn’t do it for me), and I ended up with the following configuration (click to see a higher resolution) :

    Some tips

    To reference the paths in my build script, psake has this nice little helper : $psake.build_script_dir
    This variable will have the path to the script that you execute. Whether you execute it from another folder or right from the script folder, it will hold the correct value. That’s what I base the path to the .sln files in the properties section

    $home = $psake.build_script_dir + "/../.."
    

    That’s also how I let psake know where my powershell modules are in the psake.config.ps1 :

    $root = $psake.build_script_dir
    $config.modules=("$root\modules\*.psm1")
    

    Another useful tip is that psake has a built-in function to configure the build environment (access to msbuild.exe of a specific framework for example)

    if you digg into psake.psm1 source code, you will find this function :

    function Configure-BuildEnvironment {
    $framework = $psake.context.peek().config.framework
    if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
        throw ($msgs.error_invalid_framework -f $framework)
    }
    $versionPart = $framework.Substring(0, 3)
    $bitnessPart = $framework.Substring(3)
    $versions = $null
    switch ($versionPart) {
        '1.0' {
            $versions = @('v1.0.3705')
        }
        '1.1' {
            $versions = @('v1.1.4322')
        }
        '2.0' {
            $versions = @('v2.0.50727')
        }
        '3.0' {
            $versions = @('v2.0.50727')
        }
        '3.5' {
            $versions = @('v3.5', 'v2.0.50727')
        }
        '4.0' {
            $versions = @('v4.0.30319')
        }
        default {
            throw ($msgs.error_unknown_framework -f $versionPart, $framework)
        }
    }
    
    $bitness = 'Framework'
    if ($versionPart -ne '1.0' -and $versionPart -ne '1.1') {
        switch ($bitnessPart) {
            'x86' {
                $bitness = 'Framework'
            }
            'x64' {
                $bitness = 'Framework64'
            }
            { [string]::IsNullOrEmpty($_) } {
                $ptrSize = [System.IntPtr]::Size
                switch ($ptrSize) {
                    4 {
                        $bitness = 'Framework'
                    }
                    8 {
                        $bitness = 'Framework64'
                    }
                    default {
                        throw ($msgs.error_unknown_pointersize -f $ptrSize)
                    }
                }
            }
            default {
                throw ($msgs.error_unknown_bitnesspart -f $bitnessPart, $framework)
            }
        }
    }
    $frameworkDirs = $versions | foreach { "$env:windir\Microsoft.NET\$bitness\$_\" }
    
    $frameworkDirs | foreach { Assert (test-path $_ -pathType Container) ($msgs.error_no_framework_install_dir_found -f $_)}
    
    $env:path = ($frameworkDirs -join ";") + ";$env:path"
    # if any error occurs in a PS function then "stop" processing immediately
    # this does not effect any external programs that return a non-zero exit code
    $global:ErrorActionPreference = "Stop"
    }
    

    That function is called automatically by psake before the tasks are run. It looks at psake’s configuration hash to find the $framework property that you can set at the top of the default.ps1 file. You maybe noticed that I do the following :
    properties { … $framework = “4.0” }

    I can then do exec { msbuild … } in my tasks without caring where it is located on my build server. The best is that I can override the properties from the teamcity command line by passing another $framework value as a parameter.

    ./psake.ps1 -properties @{"framework"="3.5"}
    

    Simple and efficient :)

     
  4. 12:59 16th Jul 2012

    Vote on HN

    Notes: 199

    Reblogged from alainmeier

    Some really important shortcuts in SublimeText to improve your productivity.

    The one that is new for me is the last one, very useful indeed!

    • Select all instances: You can select all instances using cmd + ctrl + G (Thanks gryghostvisuals)

    alainmeier:

    I’m a big fan of Sublime Text. As with many Mac programmers, I started on TextMate and then migrated over once Sublime Text 2 was released. When I started, however, there were a lot of things that I didn’t know about ST, so I’ve compiled a list of basic things that are excellent time savers.

     
  5. 13:23 15th Jun 2012

    Vote on HN

    Tags: solrgithub

    Running Solr as a windows service

    Solr is a very powerful search engine built on top of Lucene. If you read this article you are probably familiar with it already, so I will skip the introductions.

    One recurrent issue is that it is not the best fit to run it on a windows server. Or at least, it is not straight forward for everyone apparently.

    I stumbled upon a small project (thanks rupertbates) on github that is making this a piece of cake. I updated it and thought that might help others :

    https://github.com/serbrech/SolrWindowsService

    All you need to do is update the few settings in config file to match your environment :

    <solrService>
    <add key="JavaExecutable" value="C:\Program Files (x86)\Java\jre6\bin\java.exe" />
    <add key="WorkingDirectory" value="C:\Solr\apache-solr-4.0\example" />
    <add key="Solr.Home" value="solr" />
    <add key="CommandLineArgs" value="-Djava.util.logging.config.file=logging.properties" />
    <add key="ShowConsole" value="false" />
    <add key="Port" value="8983" />
    <add key="InstanceName" value="MyProjectName" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
    </solrService>
    

    After compilation, run Install.bat from the bin folder.

    That’s it. Solr is installed as a service on your windows machine.

    if you just want the executable, here you go.

     
  6. 00:16 14th Jun 2012

    Vote on HN

    Tags: graphneo4jlambdasyntax

    Lambdas input parameter name

    I just saw an example of lanbda using “it” as the lambda input parameter name, and I found it quite nice. I never thought about this, nothing exceptional, just a nice touch in readability :

    collection.Where( it => it.Name == "MyRelationship" );
    

    It stays concise, still keeps a meaning when you read it, and it stays short.

    By the way, this lambda was from an example in the Neo4J Rest interface .net wrapper that popped up in the github “C# Most Watched This Week” rss feed.

    Maybe something I will look into. Graph databases are still a mystery to me.

     
  7. 19:33 8th Jun 2012

    Vote on HN

    Tags: designgithub

    Designing software for multiple platforms is not about making them similar

    Github builds great software. They think it through, design it well, and they ship good software.

    Recently they shared their experience about how they designed the native windows github app.

    Codercat from github

    What I find very interesting here is the principal advantage they see in doing this. The first idea you might have when attacking this problem is to make the UI look relatively similar so that your product keeps it’s “identity” in your users eyes. But here is what they say :

    “We specifically made the decision to write each application in a language native to the platform, and this has turned out to be hugely beneficial to us. Because of this separation we’ve been free to tackle the problems that are most pressing for each platform and work in the best possible tools instead of being constrained to the lowest common denominator.”

    Instead of making the difference of the platforms a problem, they turned it into an advantage. They don’t think about how to make them similar despite the platform differences, on the contrary. Building the apps differently the different platforms gives a better experience, more adapted for every users. I believe this is the right approach.

    Trying to make an app look and work the same on 2 different platforms might seem easier, or less complex from both the development side and the user’s side. But that would be ignoring the differences of experiences that are expected on the different on mac and windows, and it can drag you down towards the lowest common denominator, particularly in terms of user experience.

    The last note that I really appreciate is the very last paragraph and sentence. I don’t think it needs much comments :

    “Design is often most important for the things that you don’t see.”

     
  8. 13:34 25th May 2012

    Vote on HN

    Notes: 15

    Reblogged from nosql

    I keep hearing people complaining that MapReduce is not as easy as SQL. But there are others saying SQL is not easy to grok. I’ll keep myself away from this possible flame war and just point you out to this ☞ SQL to MongoDB translation PDF put together by Rick Osborne and also his ☞ post

     
  9. 10:42 4th May 2012

    Vote on HN

    Tags: .netoops

    The server is stable… Oops

     
  10. 21:27 25th Apr 2012

    Vote on HN

    Tags: script rails

    How I startup all my project services in multiple terminal tabs in one command

    [DISCLAIMER]

    I am running snow leopard, and TotalTerminal (because the slide down is awesome)
    [/DISCLAIMER]

    It’s been some time now that I am playing and learning ruby, rails, and the tools around it to develop. On a project I work on, we start having a bunch of services to start to be ready to work. If you want to really see what is going on, you want each of them in a separate tab.
    And so the dance starts:

    Cmd + T  
    cd <project>
    [insert command to start service]  
    

    And the services to start are:
    -mongod
    -redis-server
    -foreman
    -passenger
    -fork
    -autotest

    I looked for a way to script this repetitve work, and found how to open a new tab in your terminal using shellscript.

    I edited it appropriately to pass it a command and Voilà :

    And it is now in my .bash_profile with a better alias.
    If you have better way, or equivalent ones, please tell me, I am always happy to learn!