RSS

Selection Sort Algorithm

The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest element in the unsorted sublist, exchanging it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.

selection-sort-algorithm

Reference: Wikipedia

 
Leave a comment

Posted by on December 19, 2014 in General

 

Tags: ,

3 SQL Server Instances You May Not Know You Have

There are 3 SQL Server database instance in most local machines. These are SQL Server Express instances that mainly useful for developers so they don’t have to install any SQL Server instance to get a project up and running. They are:

  • <machine_name>\SQLEXPRESS or .\SQLEXPRESS
    For example: “stack247\SQLEXPRESS”, or simply “.\SQLEXPRESS”.
    This is older version of SQL Server Express, 2008 to be precise. It’s also installed when you install Visual Studio 2010.
  • (LocalDB)\v11.0 or (LocalDB)\v11.1
    Comes with SQL Server 2012 or Visual Studio 2012. This is a newer version of SQL Server Express, or as the folks at SQL Express team call it, an improved SQL Express. The official name is SQL Express LocalDB
  • (LocalDB)\Projects
    Mainly used as default database by SQL Data Tools to host sandbox databases for your Database projects. Just like SQL Express LocalDB, it also comes with SQL Server 2012 or Visual Studio 2012.
 
Leave a comment

Posted by on December 18, 2014 in General

 

Tags: ,

Peek Your Definition in Visual Studio 2013

There is a new feature in Visual Studio 2013 called Peek Definition. Peek Definition allows you to see your class definition in the same file window. It even lets you edit and save the file!

You can access Peek Definition by right click on class that you want to peek and click Peek Definition. Or simply use shortcut key ALT + F12.

peek-your-definition-in-visual-studio-2013-1

peek-your-definition-in-visual-studio-2013-2

To exit from the Peek Definition, press ESC on your keyboard. You can also switch between the class definition window and your current file window by pressing SHIFT + ESC on your keyboard.

I found this very convenient feature when writing unit testing code, I can easily and quickly switch between two files.

Shortcut summary:

ALT + F12
Show Peek Definition.

ESC
Exit from Peek window.

SHIFT + ESC
Switch between Peek and current file windows.

 
Leave a comment

Posted by on December 15, 2014 in General

 

Tags:

Insertion Sort Algorithm

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

insertion-sort-algorithm

Reference: Wikipedia

 
Leave a comment

Posted by on December 12, 2014 in General

 

Tags: ,

What is the Best and Fastest Way to Flatten Data?

Given the following data set, what’s the best and fastest way to flatten them? This can be achieved with LINQ, SQL, C#, or whatever else you prefer.

001 12/5/2013 113 143 11143 44 673
001 12/6/2013 113 143 11143 44 673
001 12/7/2013 113 143 11143 44 673
001 12/8/2013 113 143 11143 44 673
001 12/9/2013 113 143 11143 44 673
001 12/10/2013 113 143 11143 44 673
002 12/5/2013 113 143 11143 44 673
002 12/6/2013 113 143 11143 44 673
002 12/7/2013 113 143 11143 44 673
002 12/8/2013 113 143 11143 44 673
002 12/9/2013 113 143 11143 44 673
002 12/10/2013 113 143 11143 44 673

Desired result:

001 12/5/2013 113 143 11143 44 673 12/6/2013 113 143 11143 44 673 12/7/2013 113 143 11143 44 673 12/8/2013 113 143 11143 44 673 12/9/2013 113 143 11143 44 673 12/10/2013 113 143 11143 44 673
002 12/5/2013 113 143 11143 44 673 12/6/2013 113 143 11143 44 673 12/7/2013 113 143 11143 44 673 12/8/2013 113 143 11143 44 673 12/9/2013 113 143 11143 44 673 12/10/2013 113 143 11143 44 673
 
Leave a comment

Posted by on December 3, 2014 in General

 

Tags: , , ,

Data Annotations in Class Generated by Entity Framework

How to add data annotations to the following class? The code is generated by Entity Framework, which means the file will be re-generated every time there’s a change to the EDMX file. When file is re-generated, all changes are wiped out.

public partial class Contact
{
    public string Firstname { get; set; }
    public string Lastname { get; set; }
    //...
}

Solution

One way to do it is to modify T4 template file to include these annotations. I don’t think this is what you and I want. So, create another partial class in a separate file:

[MetadataType(typeof(ContactMetaData))]
public partial class Contact
{
}

public class ContactMetaData
{
    [Required]
    public string Firstname { get; set; }
    [Required]
    public string Lastname { get; set; }
}

Version attow: EF 6

 
Leave a comment

Posted by on December 2, 2014 in General

 

Tags: ,

Metaphone

a phonetic algorithm, published by Lawrence Philips in 1990, for indexing words by their English pronunciation. It uses information about variations and inconsistencies in English spelling and pronunciation to produce a more accurate encoding, which does a better job of matching words and names which sound similar.

Source: Wikipedia: Metaphone

Why does this matter?

In real life, this algorithm can be used for voice translation as well as similar sounding names search.

 
Leave a comment

Posted by on November 25, 2014 in General

 

Tags: ,

 
Follow

Get every new post delivered to your Inbox.

Join 51 other followers

%d bloggers like this: