Posts

Ah, the joys of poor messages, brief documentation and faded memories!

Image
Today, I was at Hack Dev days in Vancouver, B.C. and enjoyed the group and the presentations. Two recent Uni-grads and I teamed up and proceeded to define a project and work away for most of the day.  We were using the TinEye.com API, specifically a collection of 10 million images from Flickr that they have in one of their libraries. We decided to create a Chrome Extension on the API (one of the other dev’s had done one of these recently).   It’s been 16 months since I have done any serious JavaScript/Ajax stuff, and that was (in hind-sight) unfortunately against the website where the pages were hosted…   The code that consumed most of the day… The code below should have been up and working in 15 minutes… < script type ="text/javascript"> var ApiUrl = 'http://piximilar-rw.hackdays.tineye.com/rest/' function myData() { var fd = new FormData(); fd.append( "method" , "color_search" );...

Windows Azure Service Dashboard OPML Feed File

In case you don’t want to add all the RSS feeds on the Windows Azure Service Dashboard , I’ve created an OPML file you can import into your ( Google ) reader. The file is up on Windows Live Skydrive but in case you can’t get to that, the file contents are below. If you found I’m missing a link or the link has changed, please let me know.   <? xml-stylesheet type ="text/xsl" href ="http://www.microsoft.com/feeds/msdn_opmlpretty.xsl" version ="1.0" ? > < opml version ="1.1" > < head > < title > Azure Service Dashboard Feeds </ title > </ head > < body > < outline text ="AppFabric Access Control [East Asia]" title ="AppFabric Access Control [East Asia]" type ="rss" xmlUrl ="http://www.microsoft.com/windowsazure/support/status/RSSFeed.aspx?RSSFeedCode=NSACSEA" htmlUrl ="http://www.microsoft.com/windowsazure/support/status/se...

Tech Qu: The checking your degree questions…

University transcripts are no longer trusted because of grade inflation and even bogus degrees. The result is that often people are asked questions that anyone that has taken a 3rd year computer science course (recently) should be able to answer. Personally, I feel these questions are biased for recent graduates and against those that have been in the industry many years. They are theory centric and not practical center.   On Glassdoor, one contributor says it perfectly: There are many question which will from you university course of Informatics, so worth to renew that knowledge. Many puzzles, and mostly of them you can find in internet. Nothing difficult, just good exam on things which you will never use in real life .   A few examples are: Differences between Array, Linked List, Heap etc You could dive into mechanisms of implementation, or cite a table (i.e. rote learning) such as   Linked list ...

Tech Qu: Some SQL Server Questions

Image
The Idiot ones I have gathered a few from some interview sites, and the ones below are so trivial that it’s shocking that they were asked!   WriteTSSL to find all the duplicate email address in a table which contains only one column "email" Code Snippet select [email] from [sometable] where [email] is not null OR len ( [email] )= 0 group by [email] having count ( [email] ) > 1   Many answers failed to exclude no email (could be recorded as null or an empty string), or return the count with it (which was not asked for).   Given a table: CustomerOrders: (Customer ID | Order ID | Order Date) 1. Write a SQL to find all customers who has placed an order today. 2. Write a SQL to find all customers who has placed an order today AND yesterday. Again, a trivial one Code Snippet Select CustomerId from CustomerOrders Where OrderDate >= Cast ( GetDate as Date ) Select CustomerId from CustomerOrde...

Tech Qu: Removing duplicates from an integer array

Image
Write two algorithms to remove duplicates from an integer array.   There are many solutions including sorting the array and then finding duplicates. My preference would be the following ones Code Snippet public static int [] NoDuplicate1( int [] arr) {    var map = new HashSet < int >();    foreach ( var i in arr)     map.Add(i);    return map.ToArray(); } public static int [] NoDuplicate2( int [] arr) {    var map = new Queue < int >();    foreach ( var i in arr)      if (!map.Contains(i))       map.Enqueue(i);    return map.ToArray(); }   And testing: Code Snippet int [] a = { 6,5,4,3,1,2,1, 2, 3, 4, 5, 6, 5, 6 };       var test = Questions .NoDuplicate1(a); foreach ( var i in test) {    Console .WriteLine(i); } test = Questions .NoDuplicate2(a); foreach ( var i in test) {    Console .WriteLine(i); }   Both approaches had the sequence maintained of the first integer found in th...

Tech Qu: Intersect two arrays

Write the code to find the intersection of two arrays, a,b.   The code can be very simple (or horribly complex) from the right perspective: Code Snippet public static int [] IntersectionArray( int [] arr, int [] arr2) {    var result = new HashSet < int >();    var map = new HashSet < int >();    foreach ( var i in arr)    //  if (!map.Contains(i))       map.Add(i);    foreach ( var i in arr2)      if (map.Contains(i) ) // && !result.Contains(i))       result.Add(i);    return result.ToArray(); }   I have included some unneeded condition tests as comments above (HashSet does not retain duplicates and it is assumed that an explicit test would be more expensive then letting the hashset do it itself).   Unit testing is trivial Code Snippet int [] a = { 1, 2, 3, 4, 5, 6, 5, 6 }; int [] b = { 3, 4, 3, 4, 3, 4, 3, 4, }; var test = Questions .IntersectionArray(a, b); foreach ( var i in test) {   ...

Random number generator from binary input

Image
This question is likely if you are dealing with quantum randomizers, etc. It’s irrelevant if there is an appropriate function in the language. You are given a function that generates 0 and 1 with equal probability. Write a function that uses the above function to generate any n(1<=n<=1000) so that probability of producing any number between 1 to 1000 is equal and is 1/1000. The solution is simple and fast using bit shifting (which gives performance, *2 could be used but that will raise flags with many interviewers) Code Snippet static Random _Ran = new Random (); public static int ZeroOne() {    return _Ran.Next(2); } /// <summary> /// We bitshift for optimal performance /// </summary> /// <returns></returns> public static int Random1to1000() {    var num = 0;    var outofrange = true ;    while (outofrange)   {     num = ZeroOne() << 1;      for ( int i = 0; i < 8; i++)     {       num = (num |...