Thursday, 28 January 2016

Greek Pronoun Verbs - AngularJS - KnockoutJS

I have read and briefly investigated the 2 libraries AngularJS and KnockoutJS in the past looking at others code and looking more at KnockoutJS rather than AngularJS

So I decided to explore and write a demo demonstrating my AngularJS and KnockoutJS skills just so can understand the differences and pitfalls.

Once I completed the solution I found AngularJS to be much more of a feature set than KnockoutJS. Also the implementation is cleaner. Hope to do some more work on AngularJS.

What I did was embark on writing a Greek Pronoun Verbs dictionary online using both Javascript libraries to demonstrate how to use these libraries for user interface without postback etc...
Hence the Greek Pronoun Verbs Solution.

Let me explain the problem and what the solution very simple does.
In english you would say

I graph, You graph, He she it graphs, We graph, You (Plural) graph , They (He,She,Neuter) Graph
Not much of a problem graph is always said as graph

This is not the case in Greek and the end of the word is altered accordingly.

Graph - Γραφω
See - Βλεπω

The following is the result.

Εγω - (I)
Εσυ - (You)
Αυτος - Αυτη - Αυτο - (He) - (She) - (It)
Εμεις - (We)
Εσεις - (You (Plural))
Αυτoi - Αυτες - Αυτα - (They He) - (They She) - (They)

The demonstrations are available online at the following addresses with source code. Please go ahead and look at the code and try it out.

Greek Pronoun Verbs - AngularJS

Greek Pronoun Verbs - KnockoutJS


Wednesday, 13 January 2016

C# .NET - Interview A4 Cheat Sheet

I sarcastically title this as a  C# .NET - Interview A4 Cheat Sheet simply because of the scope of questions in the .NET framework and C# arena. Looking at the summary it shows how extensive the .NET framework has become and how developers are now more than ever retaining large amounts of technical information. I remember doing most of my exams in open book or an A4 sheet of paper. Maybe I should create one for .NET and bring it in the interview.

I should call Interview A4 Cheat Sheet. Might be a good idea :-) Comments\.

I am writing this because I recently did an 2 hour phone interview whereby the questions touched on all different aspects of development.

For a phone interview I was amazed at the number of questions asked and the time it took to convey all the answers. I normally feel they can get you off guard. Interviews in IT are sometimes a hit or miss. So I decided to write my experiences on this one. Especially as to what happened at the beginning.

In summary for those who like to experience an indepth preliminary interview here are some of the questions which were asked included.

Reflection allows a .Net developer to inspect public/private objects, methods and properties.
Dynamic only allows access to public objects, methods and properties.

There is a type called dynamic similar to var but its value is not defined in declaration.

Interesting to see how there named the same but there is a difference. Hmmmm.

WeakBinding  - Object properties and methods etc not know until runtime. Typical var or dynamic variable
StrongBinding - Object properties and methods known at runtime.

Array is slower than collection for inserting/deleting records. Array is faster for index and iteration.
IEnumerable Forward only List with iterator. Has Functions like Where SelectFirstOrDefault Count Union Join Min Max Last First to name a few
IQueryable has LINQ to SQL.

Mapping Table is need to correlate a many to many relationship.

SQL Clustered Index Primary Key Flat structure. Slow to create fast to lookup
SQL Non Clustered Index B - Tree structure faster to create than clustered but slower lookup.

CTE - Common Table Expression - Self Referencing Recursive Query.

WITH Sales_CTE (SalesPersonID, SalesOrderID, SalesYear)
-- Define the CTE query.
    SELECT SalesPersonID, SalesOrderID, YEAR(OrderDate) AS SalesYear
    FROM Sales.SalesOrderHeader

Threads in a process and a seperate process all together.
In a single process a single thread can crash all the app while a process allows independently other threads. (Never saw it that way).

SOAP --> I thought that was XML.

HTML5 New Features Introduce Include

Unmanaged Code
Including unsafe accessed via pointer variables.

Why unmanaged
Avoid Serialisation
API calls

Any type safe data structure. Collections are using generics
Others include Queue, Array, SortList, SortedArray.

Always dont like the left/outer join sql questions get left and right muddled up verbally.
Basically the join correlate link 2 or more tables together.
Left Join returns all rows on the left.
But only return rows matching on the right. Where the rows dont match on the right the returns are null.

The ABC of WCF.
Never saw it as
Address        URL
Binding        Encoding
Contract    Contract

The contract can be further split to

Message - Data without serialisation to class
Stream - Data without serialisation to class
ChannelFactory - Allows retrieval of parts of a data contract without the data contract.

SVCUTIL able to get datacontract C# for wsdl or class or xml etc.


Provides metadata (not!!! properties) on class or method.

Entity Framework.

Abstracts SQL and C#
edmx - scripting/xml based file describing the
conceptual model C#
storage model SQL
mapping between them

Lazy, Eager, and Explicit Loading (JOINED READS)

Lazy does not load all related records until you access data.
Eager loads all related records the first go.
Explicit you will need to call load every iteration to read related records.

MVC Filters
Service Filter
Type Filter
Model - Data Representation  @Model Employees
View - Cshtml (Razor) @Html. @Model.Value
Controller - HTTP Directs To Method and Data Model and View.
return View(employeeModel);
return RedirectToAction("Index");

[HttpPut ("{id}")]

[Route("api/[controller]")] public class TodoController : Controller 

[HttpGet] public IEnumerable<TodoItem> GetAll()  
    return TodoItems.GetAll();  

[HttpGet("{id}", Name = "GetTodo")] 
public IActionResult GetById(string id)  
    var item = TodoItems.Find(id);  
    if (item == null) { return HttpNotFound(); }  
    return new ObjectResult(item); 

JSON / XML application/json


from cust in customers
select cust;


from cust in customers
where cust.Name = 'ABC'
select cust;


from cust in customers
join dist in distributors on cust.distributorID = dist.distributorID
where cust.Name = 'ABC'
select cust =, dist =;

I hope I have provided a good summary of C# architecturally. From there you can explore the details of each area.

Monday, 11 January 2016

C# Illustrating Object Orientated Programming

On many occassions I have been asked to describe and illustrate Object Orientated Programming.

I struggle to how to describe this in average person terms.
Recently I was asked to write classes for Animal, Dog and Cat

Initially the classes

public class Animal
public class Dog : Animal
public class Cat : Animal

Then provide the following attributes.
Name Property for all Animals
MakeSound method for all whereby Dog returns "Woof" and Cat returns "Miaow" but extensible by using abstract.

The modifications were made below.

public abstract class Animal
    public string Name { get; set; }
    public abstract string MakeSound();
public class Dog : Animal
    public override string MakeSound()
        return "Woof"
public class Cat : Animal
    public override string MakeSound()
        return "Miaow"

Finally suppose you want a generic sound for all animals allowing for instance a Rabbit where the response is unknown so generically speaking its an animal and it makes a noise.

The modifications were made below.

public abstract class Animal
    public string Name { get; set; }
    public string MakeSound()
        return "Noise";
public class Dog : Animal
    public override string MakeSound()
        return "Woof"
public class Cat : Animal
    public override string MakeSound()
        return "Miaow"
public class Rabbit : Animal


This should help someone explain OO principles with a real life example.

Tuesday, 5 January 2016

Using C# The Cheque (Check) Writer

Using C# The Cheque (Check) Writer

Recently I was given a test to test my coding skills not just functionally but also aesthetically as well. My wife is an art teacher and I always believe coding is an art form as well as an engineering discipline. 

So I decided to blog and plan to seek from the IT community any feedback on the infinite possible ways to tackle the solution.

The test was to write a cheque printing application that needs to be able to display numeric values on the screen using the equivalent text. So I went ahead and design and implement an application that does take a numerical value for a cheque and displays it in words on the screen.

For example if I entered


The program would return

one thousand two hundred and thirty four dollars AND fifty six cents 

As a team leader in my previous roles I have done many interviews. I have in the past used this test without much success and it usually only done by candidates who have gone through and succeeded simpler tasks.

I have to be fair I feel my solution could be better hence why I have blogged and interested in feedback regarding this problem.

The approach I have taken is to split and group the number based on their significant values i.e. their numerical significance. For example:


Will be grouped in the following way

1 thousands represented as one thousand.
2 hundreds represented as two hundred.
3 tens represented as thirty.
4 units represented as four.

Then the cents are grouped in the same manner.

Hence the output will be one thousand two hundred and thirty four dollars AND fifty six cents

The text are kept in string arrays indexed by the quotient for efficiency in lookup and translation from number to text.

i.e. 200 / 100 will be 2.

The array will arrUnits[2] which returns a string two etc.. as per initialisation.

This allows for easy adjustment to another language which will require a small code change and initialisation differently.

I include the code below with comments. I welcome comments and likely will get the community to provide possible solutions.

Anyone thoughts would be appreciated.

The link is

Whilst the actual code is included below.

using System;
using System.Collections.Generic;
using System.Text;

namespace ChequeWriter

    /// <summary>
    ///  This class performs the number to written text functionality.
    ///  It exposes one public member function OutputNumberToString
    ///  Implementation:
    ///  All Cheque Writing Texts are stored indexable arrays.
    ///  I choose this over collections/lists simply because of memory efficiency.
    ///  The arrays are initialised in the constructor.
    /// </summary>

    public class ChequeWriter

        // Array Containing Currency Dollar / Cents easily adaptable to Pounds
        string[] strarrCurrency;//[4];

        // Array Containing Singular Unit Texts
        string[] strarrUnits;//[10];

        // Array Containing DecaUnits and Teens
        string[] strarrTens;//[20];

        // Array Containing HundredUnits
        // Reproduction of strarrUnits and deemed not necessary but kept as I coded the solution. Shows how code can adapt to language if necessary.
        string[] strarrHundreds;//[10];

        // Array Containing Thousandths.
        string[] strarrThousands;//[3];

        /// <summary>
        ///  The arrays are initialised and language dependent texts are populated in the array.
        /// </summary>
        public ChequeWriter()
            strarrCurrency = new string[4];

            strarrUnits = new string[10];//[10];
            strarrTens = new string[20];//[20];
            strarrHundreds = new string[10];//[10];
            strarrThousands = new string[3];//[3];

            strarrCurrency[0] = "dollars";
            strarrCurrency[1] = "dollar";
            strarrCurrency[2] = "cents";
            strarrCurrency[3] = "cent";

            strarrUnits[0] = "";
            strarrUnits[1] = "one";
            strarrUnits[2] = "two";
            strarrUnits[3] = "three";
            strarrUnits[4] = "four";
            strarrUnits[5] = "five";
            strarrUnits[6] = "six";
            strarrUnits[7] = "seven";
            strarrUnits[8] = "eight";
            strarrUnits[9] = "nine";

            strarrTens[0] = "";
            strarrTens[1] = "ten";
            strarrTens[2] = "twenty";
            strarrTens[3] = "thirty";
            strarrTens[4] = "fourty";
            strarrTens[5] = "fifty";
            strarrTens[6] = "sixty";
            strarrTens[7] = "seventy";
            strarrTens[8] = "eighty";
            strarrTens[9] = "ninety";

            strarrTens[10] = "ten";
            strarrTens[11] = "eleven";
            strarrTens[12] = "twelve";
            strarrTens[13] = "thirteen";
            strarrTens[14] = "fourteen";
            strarrTens[15] = "fifteen";
            strarrTens[16] = "sixteen";
            strarrTens[17] = "seventeen";
            strarrTens[18] = "eighteen";
            strarrTens[19] = "nineteen";

            strarrHundreds[0] = "";
            strarrHundreds[1] = "one";
            strarrHundreds[2] = "two";
            strarrHundreds[3] = "three";
            strarrHundreds[4] = "four";
            strarrHundreds[5] = "five";
            strarrHundreds[6] = "six";
            strarrHundreds[7] = "seven";
            strarrHundreds[8] = "eight";
            strarrHundreds[9] = "nine";

            strarrThousands[0] = "thousand ";
            strarrThousands[1] = "million ";
            strarrThousands[2] = "billion ";


        /// <summary>
        ///  The console application entry point. The user is prompted for entering a number.
        ///  This number will be then converted into text.
        ///  The ChequeWriter class is used to provide this functionality.
        /// </summary>

        static void Main(string[] args)
            string strName;
            string strInput;
            long lngWholeInput;
            int intCentsInput;

            ChequeWriter ntsOutput = new ChequeWriter();
                // User input is read in.
                Console.Write("Please Enter Your Name ");
                strName = Console.ReadLine();

                Console.Write("Please Enter a number ");
                strInput = Console.ReadLine();

                // Output Verbatim The User Name

                // User can enter cents and is optional hence the checking of the decimal point.
                if (strInput.IndexOf('.') > 0)
                    // Validation and Parsing of Input as Numeric before proceeding.
                    // First Parse Whole Amount of User Input.
                    // Not in requirements but could have need for a custom response.
                    if (long.TryParse(strInput.Substring(0, strInput.IndexOf('.')), out lngWholeInput))
                        // Parse Decimal Portion of User Input.
                        // Proceed and call function and Output Number to String
                        if (int.TryParse(strInput.Substring(strInput.IndexOf('.') + 1), out intCentsInput))
                            Console.WriteLine(ntsOutput.OutputNumberToString(lngWholeInput, intCentsInput));
                    // Parse Input as Whole Amount
                    // Proceed and call function and Output Number to String
                    if (long.TryParse(strInput, out lngWholeInput))
                        Console.WriteLine(ntsOutput.OutputNumberToString(lngWholeInput, 0));

            // Repeat While User Input
            while ((strInput.Length > 0) && (strName.Length > 0));


        /// <summary>
        /// Output Number To String - Public
        /// Converts a number provided into text.
        /// </summary>
        /// <param name="lngWholeValue"></param>
        /// <param name="intCentsValue"></param>
        /// <returns>String in words of input value as a cheque writer</returns>
        public string OutputNumberToString(long lngWholeValue, int intCentsValue)
            string strOutput = "";
            long lngRemainder;

            // Calculate the indexes for retrieving text from the array.

            long iBillion = Math.DivRem((long)lngWholeValue, (long)1000000000, out lngRemainder);
            long iMillion = Math.DivRem((long)lngRemainder, (long)1000000, out lngRemainder);
            long iThousand = Math.DivRem((long)lngRemainder, (long)1000, out lngRemainder);
            long iUnits = lngRemainder;

            if (iBillion > 0)
                strOutput += OutputHundredUnitsToString(System.Convert.ToInt32(iBillion)) + strarrThousands[2];

            if (iMillion > 0)
                strOutput += OutputHundredUnitsToString(System.Convert.ToInt32(iMillion)) + strarrThousands[1];

            if (iThousand > 0)
                strOutput += OutputHundredUnitsToString(System.Convert.ToInt32(iThousand)) + strarrThousands[0];

            if (iUnits > 0)
                strOutput += OutputHundredUnitsToString(System.Convert.ToInt32(iUnits)) + strarrCurrency[0];
                strOutput += strarrCurrency[0];

            if (intCentsValue > 0)
                strOutput += " AND " + OutputHundredUnitsToString(System.Convert.ToInt32(intCentsValue)) + strarrCurrency[2];
                strOutput += " AND ZERO CENTS";

            return strOutput;

        /// <summary>
        /// </summary>
        /// <param name="iValue"></param>
        /// <returns>Cheque Writing within the range of 1 to 999 </returns>
        private string OutputHundredUnitsToString(int iValue)
            string strOutput = "";

            int iTens;          // The number calculated by output of a remainder for hundreds.
            int iUnits;         // The number calculated by output of a remainder for tens.

            // Math Div Rem Allow Quotient and Remainder in 1 function call.
            // It is an optimization. Some processors are able to compute both values at the same time.

            // Number of hundred with remainder.
            // Hundreds are converted to text.
            if (Math.DivRem(iValue, 100, out iTens) > 0)
                strOutput += strarrHundreds[(iValue / 100)] + " hundred ";

            // Number of tens with remainder.
            // Tens are converted to text.
            if (Math.DivRem(iTens, 10, out iUnits) > 0)
                if (strOutput.Length > 0)
                    strOutput += "and ";
                if ((iTens / 10) > 1)
                    strOutput += strarrTens[(iTens / 10)] + " ";
                    strOutput += strarrTens[iTens] + " ";

            // Remainder Units are converted to text
            if ((iUnits / 1) > 0)
                if (((iValue / 100) > 0) && ((iTens / 10) == 0))
                    strOutput += "and ";
                if ((iTens >= 20) || (iTens <= 9))
                    strOutput += strarrUnits[(iUnits / 1)] + " ";
            return strOutput;