Mark Mintoff My superpower is common sense

21Aug/1214

My Take on Daphne Caruana Galizia

Daphne

Completely Irrelevant

Daphne Caruana Galizia is an inflammatory, instigative and provocative political blogger without a single, minute modicum of professionalism. Her writing is essentially drivel; consisting of immature insults, baseless claims and crass degenerate comments. She is a self-aggrandizing lout with a grossly unjustified superiority complex.

One can see this from even a cursory glance at her poorly-put-together website and the sort of replies she leaves to the comments she chooses to approve. When one has no evidence to present nor a rational argument to make, the last resort is to turn to hollow mockery in an attempt to prostrate your opponent. Daphne Caruana Galizia does this quite regularly.

Of all the irrelevant things one could possibly strive to become in the world; a blogger focusing solely on mud-slinging in local politics, ranks highly enough. Daphne Caruana Galizia is irrelevant. She has not contributed a single shred of good towards society in any conceivable manner. The only reason she has attained such infamy (certainly not fame) is because people keep giving her far more attention than she deserves.

It would behoove all of us to cease and desist from imagining her as a green witch; after all Daphne is but a simple blogger. In all probability, the poor girl goes largely ignored by her husband as she sits at the computer in her underwear.

Ignore her. She is meaningless and without consequence. Always has been. Always will be.

VN:F [1.9.22_1171]
Rating: 5.0/5 (3 votes cast)
27May/120

The Towers of Hanoi Problem

About a year ago, in the summer of 2011 I had found myself unemployed for 2 months through no fault of my own. I had accepted an ASP.Net development position with a gaming company called GamingVC and had thus resigned from my job at WagerLogic.

Unfortunately, on the day I was to begin my new job with GamingVC, as soon as I entered the building; I was taken into a boardroom and fired without reason. Thus, I spent two months searching for gainful employment and had many a strange interview.

The worst interview I had that summer, and consequently the worst interview I had in my entire life is what I shall be talking to you about today.

By nature, I am an introverted person. I do make an effort to be sociable, however it takes me some time to warm up to a person and be comfortable. The interview, unbeknownst to me consisted of an interview with a woman in human resources and then a surprise interview consisting of the IT manager and a senior programmer. The IT manager was boisterous and rude, bouncing a stress ball against the wall, seemingly paying no regard to a word I was saying. I felt stressed, sweating inside a thick suit in the middle of June, when suddenly the CIO walks in. After a few minutes he launches into a tirade about games.

He mentions to me Towers of Hanoi as if it were the greatest game ever to have been created (he's wrong, the greatest game is chess), framing it with arrogant disdain aimed at me with the term "before your World of Warcraft nonsense we had a game called Towers of Hanoi". It is funny, come to think of it, because I never even played World of Warcraft. Anyway, he wanted me to programmatically solve Towers of Hanoi on a whiteboard whilst they all watched. Given my character and nervousness I failed miserably and here's why:

Towers of Hanoi is a game I played when I was seven years old. I played it on a cheap hand-held device along with Tetris, Snake and some other monochrome pixel games. At that age, I had not a care in the world and I had not yet started to analyze everything in terms of functional programming. Nor had I any idea what recursion was when I was that young. Suffice it to say, I knew how to solve it myself, which I saw mentally as a while loop, without having figured out that it was a recursive loop. What's more I am not accustomed to programming without a computer and with three people burning a hole in the back of my head.

So, for the sake of no longer feeling stupid (because they made me feel pretty stupid) at having mucked it up so badly during my interview, I present to you the solution:

I believe that redeems me from the absolute mess of a while loop I had tried to do on a whiteboard and I can (after a year) finally move on.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
2May/120

Adding Regular Expression Support to SQL Server

First and foremost, it is worth noting that SQL Server supports .Net assemblies, allowing us to create methods which can be used from SQL.

.Net assemblies (dll files) can be loaded into the below folder.

With that out of the way, we can get started on creating a .Net assembly. SQL Server does not support regular expressions natively, so I thought it would be useful to add this functionality as my first assembly.

To start, we can create a Class Library Solution (I called mine 'TextFunctions') and add a single class (I called mine 'StringUtility'). The following is the code I wrote for my StringUtility class:

Very simple bit of code, which allows me to check for Regex matches. No big deal. Now we must install this assembly into the database. First we must check to ensure that the database is CLR enabled, so we run:

Next we will create the assembly. Please note that the dll file must be on the same machine as the database is. You might also want to specify the database you will be adding this to. I added a simple "use master;" to my script.

Now we can install the RGX function I created.

Note that the syntax for EXTERNAL NAME is SolutionName.[Namespace.ClassName].MethodName

That is all! You now have a brand new function which executes C# code and returns a boolean value back! Let us try some simple examples:

This function can also be used in WHERE clause conditions as follows:

Enjoy!

VN:F [1.9.22_1171]
Rating: 4.3/5 (3 votes cast)
27Apr/120

Useless SSIS Error Message

Had to investigate an SSIS error code to figure out what was causing it. The error code was -1073450910. I pasted that code into Windows Calculator and converted to hex.

You have to trim the Fs from it, getting me C0047062. I then navigated to C:Program FilesMicrosoft SQL Server100SDKInclude and opened dtsmsg.h to search for the error. What followed was an error which explained absolutely nothing.

Insert sad face here

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
27Apr/122

Simple Way To Check For Rows

I would like to share a very simple technique for checking for rows in your table. Before developing this, I used to make the mistake of doing a SELECT COUNT(1) script.

On tables with a large number of rows (millions), this proved to be inefficient (even with indexing). So instead, I developed this efficient way to check for rows, which makes a difference:

It's very simple. All it does is select the top one row from your table, based on your condition in a subquery (X). Then select count on that subquery and convert the result to a bit. The result will always be 1 or 0, which translates to True and False respectively!

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
16Apr/123

Meatloaf

meatloaf

You will need:

  • 1 packet of Onion Soup Mix
  • 1 packet ground beef
  • 1 packet pork sausages
  • 1 large egg
  • 2/3 cup of milk
  • 3 tablespoons ketchup
  • 3 tablespoons brown sugar
  • 1 tablespoon yellow mustard

In a blender, mix the ground beef, sausages, soup mix, egg and milk together.

Grease up a loaf shaped pan (it is a meat loaf after all) and pour the mixture into it.

Combine the ketchup, brown sugar and yellow mustard and spoon on top of the meatloaf.

Bake uncovered for about an hour.

Let meatloaf stand for about 10 minutes before slicing.

Serve with mashed potatoes and blanched broccoli.

Enjoy abundantly!

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
27Mar/120

A string literal in the expression exceeds the maximum length of 4000 characters.

In SSIS, the error "A string literal in the expression exceeds the maximum length of 4000 characters." has proved to be a stumbling block for me in the past because the error message is misleading. In SSIS, when a string variable is set to Evaluate As Expression, then the string being put together by that expression is not actually a string, but rather the SSIS specific DT_WSTR.

DT_WSTR has a limit of 4000 characters whereas string does not, in spite of what the error message appears to suggest.

I personally ran into this error on attempting to build a large query through Expression, but there is an alternative solution to using EvaluateAsExpression.

If instead, we create a Script Task, providing it with all the necessary variables; we could construct a script which exceeds 4000 characters and output it to the string variable. Contrary to expectations, the string is accepted in it's entirety and it can be used normally.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
27Mar/124

C# Equivalent for SQL IN

One of the things that irks the most when reading code is cumbersome and long-winded IF statements to the tune of:

Naturally, this could be easily typed out as:

But I am not entirely comfortable with this. Certainly it is infinitely better than trying to cram all those possibilities for a into one line, but there must be a more readable syntax. SQL has the answer with the IN statement. For example:

I wanted to emulate this syntax in C#, so I wrote the following extension method which effectively mimics the SQL IN syntax:

or alternatively as Andreas suggested in the comments below:

What this does conceptually, is incredibly simple. You pass to it a generic List or an array and it simply loops on that array searching for a match returning true or false, depending on whether a match has been found. Conceptually, this is akin to the SQL IN syntax.

What this means, is that we can now type the above cumbersome IF statement as:

Which I feel, is a noticeable improvement in the readability of a long-winded collection of OR conditions in a single IF statement.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
Tagged as: , , 4 Comments
13Mar/120

T-SQL Batch Delete

There are times when you need to delete an arbitrarily large subset of data from a database table. For the sake of example, let us suppose we will be deleting 100,000,000 rows. A simple delete statement:

will take a very long time (hours) to process as 100,000,000 rows will be deleted within a single transaction.

For this purpose, when I need to delete a large subset of data, I prefer to work with a while loop delete and multiple transactions:

This results in a much faster deletion of data as each transaction will only need to delete 1000 rows at a time. An additional benefit is presented if you need to stop the deletion at any point; for example you have locked the table and somebody needs to select some data. There are no long rollbacks and you do not lose progress on what you have deleted.

Hence, to make things easier:

Alternatively:

Enjoy!

VN:F [1.9.22_1171]
Rating: 4.7/5 (3 votes cast)
1Mar/120

SSRS Report Parameters via Query String URL

In order to pass report parameters via querystring URL in SSRS, use the following syntax:

http://[servername]/Reportserver/Pages/ReportViewer.aspx?[folder]/[reportname]&rs:Command=Render&[parameter]=[value]

Please note, this is different from the usual syntax when viewing a report:

http://[servername]/Reports/Pages/Report.aspx?ItemPath=%2f[folder]%2f[reportname]

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)