Friday, September 9, 2016

HTML Scrubbing !

Just very recently I extended a little help to one of my UI developers (an Angular one :-)) and thought I'd share with the community a little piece of C# code..

Context : As with many legacy application data, we ran into one that has persisted a lot of garbage HTML data, copy-pasted from a Rich Text Editor, without application validating much of it..That accumulated a lot of HTML code persisted, when read and displayed using Angular.js framework, did not display the right content. The right content was intended to strip off all the HTML tags including   as well.

The below little utility as C# static function does exactly what I intend to put forth the above context..

        public static string ScrubHtml(string value)
            var step1OfScrubbedHtml = Regex.Replace(value, @"<[^>]+>|&nbsp;", "").Trim();
            var step2OfScrubbedHtml = Regex.Replace(step1OfScrubbedHtml, @"\s{2,}", " ");
            return step2OfScrubbedHtml;

Have fun!


Wednesday, April 13, 2016

QuadKey - what it is?

To start with, let me share an excerpt from MSDN as below:

Bing Maps Tile System (Reference: )
Bing Maps provides a world map that users can directly manipulate to pan and zoom. To make this interaction as fast and responsive as possible, we chose to pre-render the map at many different levels of detail, and to cut each map into tiles for quick retrieval and display. This document describes the projection, coordinate systems, and addressing scheme of the map tiles, which collectively are called the Bing Maps Tile System.
So if you follow the above references Bing Maps Tile System, you would get an idea that  - how the world map is kind of apportioned into a tile system and depending on what level of detail or zoom you are interested in, you would get a <N> character long quad-key. 
For what I am involved with currently, we care to go for the maximum allowable detail to uniquely identify each geo-location, and hence Zoom Level = 23 !
Show me the code!
Well - there is not much you need to do if you are a .Net shop or a developer - other than grabbing the code from the above referenced URL on MSDN. For some, (like myself) our need is to actually run the generation of the QuadKey on the actual data store and that is EXASOL. 
EXASOL by itself is a fantastic in-memory database for Analytics (URL : ) but it primarily supports running either Oracle PL/SQL scripts or Lua ( ... and then, there was a language that I liked to explore and must say, it is quite intuitive and easy to learn (well - I admit, I needed a crash course on Pluralsight)
How to generate QuadKey in Lua?

The story does not end there, though! As mentioned earlier, my required level of detail is specified as 23 - which means I get 23 character long, string - all numeric values (from 0 through 3) but can't fit that into long numeric value!! Also, it is critical to have a computed, numeric value as part of the data schema for efficient search and retrieval of data, in addition to be able to encode and decode the actual Quad Key String.

So, then that led me to write up a function that would compute numeric value for that. Similar to how binary (base 2) are converted into decimal,. as Quad Keys are numeric values from 0, through 4 - as you might have figured can be treated as base 4 - and taking a cue from the binary conversion to numeric, the below is my encoding or numeric computation working function in Lua.

Now go ahead and give it a shot .. for a sample LATITUDE/LONGITUDE combination the below is a sample output..

--Test Data
latitudeSample  =  43.750546
longitudeSample = -79.716408

quadKey = GetQuadKey(latitudeSample, longitudeSample, levelOfDetail)

---> 03022313030302020021221
quadKeyEncoded = GetEncodedQuadKey(quadKey)
---> 13940604568169

Monday, March 30, 2015

Yep! Canadians are the nicest people on the planet.

A recent travel story posted on BBC travel site prompted me to write this up on my humble blog and more than that, makes me feel proud Canadian, sharing with you all ...

Pretty much everything is relative, at least from my perspective - and this blog is about it, isn't it?

Our behavior is observed and compared vis-a-vis someone else's and having myself spent significant amount of time in 3 different continents - I agree 200% with the writer of this post on BBC.

KISS Principle - Your website should be so SIMPLE, a drunk person could use it.

What in the world we are talking about? A drunk person playing with a web site to ensure it is 'tested' in a realistically simplistic nature !!

Yes, these days you can hire a person for $150 - who would get drunk and jump on browsing on your website - with an objective of ensuring it is usable by pretty much anyone :-)

Refer this link on the for a ping-back POST.

Monday, January 6, 2014

XSL1.0 String.Replace() is missing! How can that be achieved?

A couple of months ago, one of my team members, Ali Chaudhary dealt with an issue for which XSL 1.0 is in place and couldn't really figure out the String replacement feature in it .. until he hit the following URL .. seems there is always a way to achieve what you want to ...

Using T-SQL Convert LOCAL datetime to UTC datetime value using UTC offset (defined)

While working on some things recently, I figured there is an easy way to convert (using T-SQL) local time to UTC departure time … and that is leveraging built-in DATEADD function  


The key is using the right offset value for calculating UTC .. in the scenario that we dealt with, the database has Offset defined in minutes and is based on the offset/difference in minutes FROM UTC time so to convert the captured local date time to UTC.. the following works just fine ..

DATEADD(mi, - <UTCOffsetValue>, <LOCALDateCaptured>)    // mi - minutes

As an example for offset, Canada EST (with Daylight) has the value for the Offset defined as -300 [5 hours behind of UTC] whereas for France it is defined as + 60 [1 hour ahead of UTC]

SQL Server database is Case In-Sensitive - is a MYTH!

The case sensitivity or insensitivity depends on the collation applied to the column or at the DB level ..

Normally, the default collation is ‘CI’ but please remember it is not always ‘Case Insensitive’ 

If you run the below query on any particular db server ..


what you could retrieve the data value, normally would be, 

Latin1_General_CI_AS  (CI – Case Insensitive, AS – Accent Sensitive)

But it could also be something like this … 
            Latin1_General_CS_AS  (CS – in this case, it is Case Sensitive)        

So though it may take an additional 1/100th of a nano-second, I'd generally prefer to UPPERize the string comparison such as below …


instead of exact match such as

SUBSTRING(COMMENT_, 1, 8) = 'Schedule'

Wednesday, July 24, 2013

Entity Framework: IQueryable vs. IEnumerable

Found a great post on this, with example ..

Entity Framework: IQueryable vs. IEnumerable

Many of us sometimes get confused of different aspects of using IEnumerable<T> and 
IQueryable<T> in Entity Framework. One of considered opinions is that Entity Framework and 
DbContext and deffered execution just do all the magic and there is no difference. ...

But even though LINQ query result remains basically the same, it may significantly impact 
the query performance.

Hope it is helpful for the team.


Wednesday, May 8, 2013

Baseless merge!

Baseless merge in TFS ? or a Baseless Question? :-)

A colleague came over wondering for what someone asked him to do - and that is to merge two branches. I believe, the tool allows you to do that however, I wouldn't recommend it simply because it is a sort of sibling-sibling merge rather than (what it is intended for) parent-child merge.

Reference to support my perspective ...

How do I merge two branches?

To perform a merge, you can use the merge functionality in Source Control Explorer, or you can use the merge command-line tool. You can merge based on changeset, label, date, or version.
You might find that your branching structure becomes deeper than one level. If this happens, keep in mind that it is only possible to merge one level at a time. For example, consider the following source tree structure:
  • Development – Container for isolation development branches.
    • Feature A
      • Source
    • Feature B
      • Source
  • Main – Main integration build branch
    • Source
    • Other asset folders
  • Releases– Container for Release branches
    • Release 1
      • Source
    • Release 2 – Current release being locked down
      • Source
When the source code contained in the Release 2 branch changes, you might want to eventually merge that change into a Feature branch; for example, to incorporate a bug fix into the latest feature code. It is not easy to merge directly from Release 2 into Feature B; instead, you merge from Release 2 into its logical parent, Main, and then from Main into its logical child Feature B. If you need to merge between branches that do not have a direct parent-child relationship, you need to perform a baseless merge.

O.K., so what is a baseless merge?

The branch command will create a relationship between two folders. You can leverage this connection to perform merges of code between the branches. Branches that are not a direct child or a direct parent of the merge target do not have this relationship. As defined in MSDN, a baseless merge “performs a merge without a basis version. That is, allows the user to merge files and folders that do not have a branch/merge relationship. After a baseless merge, a merge relationship exists and future merges do not have to be baseless”.
A baseless merge will result in many more conflicts than a normal merge. However, after the first baseless merge, future merges between these branches will no longer be baseless, thus minimizing conflicts.
Baseless merges can only be created from the command line. Even after the first baseless merge, when a relationship has been created between the branches, future merges still need to be created from the command line.

Friday, April 5, 2013

How do you sort worksheets in Excel 2010?

Interestingly enough, Microsoft Excel does not have an inherent functionality of sorting data sheets. I was working on something that required to segregate data across multiple worksheets and in no time had come up with several data sheets on the same workbook. I had to find a better way of organizing them and the first thing I needed was an ability to sort my worksheets ...

However, there is always a way to find a workaround to it .. and to be honest, I do not find that difficult to apply - this post is about the same.

and there I have it my worksheets, sorted ...

Basically, you will have to run the macro in VB Editor and run that under a module.

Do remember that unless you <save as..> as your workbook as type .xlsm, the macro will not be part of the spreadsheet and in which case you will have to revisit the steps to run the macro again.