Friday, 11 July 2014

Useful tools: Remote Desktop Connection Manager

Remote Desktop Connection Manager -- free tool from Microsoft, quite useful if you need to connect to more than one computers remotely. Organizes sessions in compact window, allows storing credentials (though not always a good thing but often a time saver).

Wednesday, 2 July 2014

Visual FoxPro Memo file format uses big-endian convention

Contrary to the little-endian convention used across DBF file format, and generally across the Windows, VFP Memo file format uses the big-endian one.

A screen shot below displays the header record of a memo file. The first four bytes define the location of next free block. Bytes 6 to 7 (0x00, 0x40) defines the size of a block -- 64 bytes, VFP default value (SET BLOCKSIZE). Clearly the big-endian convention is used.



In no way this is an obstacle had you decided to parse or modify Memo files, but of course needs to be taken into account.

As I found after completing this post, Visual FoxPro MSDN page states exactly the same: [for offset, length, and size fields in Memo File Structure (.FPT)Integers stored with the most significant byte first.

Thursday, 26 June 2014

Using PrivateObject class for unit testing of private methods in .NET

Whether private members should be unit tested or not, I should say that the PrivateObject class serves its purpose nicely.

Useful tools: Kleopatra for file and email encryption

Kleopatra of Gpg4Win for file and email encryption.

Will add some comments later.

Useful tools: Beyond Compare for file and folder comparison

Beyond Compare of Scooter Software for file and folder comparison.

Will add some comments later.

Using SQL Server aliases vs messing with configuration files

For creating SQL Server aliases use either SQL Server Configuration Manager or cliconfg.exe utility. The utility apparently exists on virtually any Windows computer. Safe way would be creating same aliases for 32-bit (System32) and 64-bit environments (SysWow64).

With aliases properly set there is no need to modify connection strings in project's configuration file when switching between different environments, e.g. development and production.

Sunday, 21 July 2013

Cartesian Product code sample, LINQ, C#

Starting point
StackOverflow: Cartesian Product + N x M Dynamic Array

Credit: Eric Lippert

Sample code (C#, console app)

namespace CartesianStudy
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public static class Program
    {
        public static void Main()
        {
            var persons = new[]
                {
                    "Peter", 
                    "Mary", 
                    "Ivan", 
                    "Oscar", 
                    "Lucy"
                };

            var flyingDays = new List<string>
                {
                    "Tue", 
                    "Wed", 
                    "Fri", 
                };

            var flights = new List<Flight>
                {
                    new Flight("Air Canada", "AC1152"), 
                    new Flight("CanJet", "C6785"), 
                    new Flight("WestJet", "WS4040"),
                    new Flight("SunWing", "WG423"),
                    new Flight("Air Canada", "AC093"),
                    new Flight("American Airlines", "AA8118"),
                };

            var allCombinations = new IEnumerable<object>[]
                    {
                        persons, flyingDays, flights
                    }.CartesianProduct().ToList();

            foreach (var combination in allCombinations
                .Select(c => c.ToList()))
            {
                Console.WriteLine(
                    "{0} on {1} by {2}", 
                    combination[0], 
                    combination[1], 
                    combination[2]);
            }

            Console.WriteLine(
                "\nCount: {0}\nAny key...", 
                allCombinations.Count);
            
            Console.ReadKey();
        }

        private static IEnumerable<IEnumerable<T>> 
            CartesianProduct<T>(
            this IEnumerable<IEnumerable<T>> sequences)
        {
            IEnumerable<IEnumerable<T>> emptyProduct = new[]
                {
                    Enumerable.Empty<T>()
                };

            return sequences.Aggregate(
                emptyProduct,
                (accumulator, sequence) =>
                from accseq in accumulator
                from item in sequence
                select accseq.Concat(new[] { item }));
        }
    }

    public class Flight
    {
        public string Company { get; set; }

        public string Number { get; set; }

        public Flight(string company, string number)
        {
            this.Company = company;
            this.Number = number;
        }

        public override string ToString()
        {
            return string.Format(
                "{0} - {1}", 
                this.Company, 
                this.Number);
        }
    }
}