Posts

Showing posts from July, 2015

Took a Codility Test : Decimal Reverse, Magnitude Pole and Most Number of Occurrence.

Image
I took a test few days ago in Codility, I say this really is a good way to validate the skill set of programmers, it shows clearly how they think and approach problem vs normal multiple choice type of question or by simply having a technical interview. Here's my answer to the Codility questions. Decimal Reverse: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 public static int DecimalReverse ( int n) { char [] arr = n.ToString().ToCharArray(); string reversed = string .Empty; List< string > list = new List< string >(); foreach ( var item in arr.Reverse()) { list.Add(item.ToString()); } reversed = string .Join( "" , list); return Convert.ToInt32(reversed); } Magnitude Pole: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 public static int MagnitudePole ( int [...

Creating an Automated Testing Framework using Selenium.

Instant T-SQL Formatter

Imagine you are maintaining an existing system, there are countless of SP's already in use, and there are few other devs touching the sp's every now and then, and normally they look it up via sp_helptext without pressing CTRL+T, they copy and paste the result, modify it and execute it. The result is SP having white spaces and not properly formatted, wouldn't it be nice if we can format it with a click of a button? Yes, there's a tool for that. I'm attaching a link to it giving credit to the the owner of the site and the one who created it. http://architectshack.com/PoorMansTSqlFormatter.ashx#Download_5

Identity vs Scope Identity vs Ident_Current

While doing some update on an existing Store Procedure I came across a code that retrieves an Identity value. 1 2 3 4 5 6 if @@ rowcount > 0 begin select @ id = scope_identity() end else select @ id = 0 Now let's discuss when to use Identity, Scope Identity and Ident_Current, I checked the internet and found an article from the SQL Authority . Here's a brief of what it says: Select  @@IDENTITY It returns the identity value generated on a connection regardless of table and the scope which produce the value, it means that in case a trigger was also called from the same connection and produced an identity, this identity will be returned. Select SCOPE_IDENTITY It returns the identity value generated on a connection and by a statement on the same scope regardless of the table the produced the value. it will return the value that was explicitly created by the statement and will not be affected by any trigger even if it creates an identity on the same ...

Adding an Obsolete Attribute to Class Methods in C#

As a developer we normally maintain our own framework, our own abstraction of things, be it database wrappers, our own implementations of persistence managers, in some cases we figure out a better way or new way of doing things so we decide to include it in the framework, how do we now tell other developers to use this instead of the old one? The answer is the Obsolete Attribute. 1 2 3 4 5 6 7 8 9 [Obsolete("ExpandoObject.CreateObject is deprecated, please use NameValueCollection.CreateObject instead.", true)] public static void CreateObject ( this ExpandoObject that, NameValueCollection querystring) { querystring.AllKeys.ToList().ForEach(x => { if (!that.ToDictionary(y => y.Key).ContainsKey(x)) ((IDictionary< string , object >)that)[x] = querystring[x]; }); } We simply add this attribute on top of the method or class and specify our message. BTW, the Boolean parameter if set to True, will throw and exceptio...

My First Android App Published in Google Play

Image
I decided to retool myself in Java Android Development few months back, here's the first product for a local company here in Manila. I will discuss in details the technical stuff involved in the project, a soon as I free myself up from some urgent task.

Serializing JSON string to ExpandoObject

In some case you want to create and Object from JSON, a great way of doing this to deserialize this JSON to an ExpandoObject. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /// <summary> /// Convert Json String to an Expando Object /// </summary> /// <param name="that">Json string to convert</param> /// <returns>Expando Object</returns> public static ExpandoObject ToExpando ( this string that) { ExpandoObject result; try { result = JsonConvert.DeserializeObject<ExpandoObject>(that, new ExpandoObjectConverter()); } catch (Exception e) { throw e; } return result; } Here we use JsonConvert.DeserializeObject, you need to add reference to NewtonSoft.Json see below. 1 2 3 using Newtonsoft.Json ; using Newtonsoft.Json.Converters ; using Newtonsoft.Json.Linq ;