Evil Science A whole load of stuff


.Net Balloon window

Have you ever been frustated by the ToolTip component's lack of functionality,  i.e. you't can add a close button like the NotifyIcon control, lack of handleable events? Be frustated no more, as a solution is at hand.

The Balloon Window for .Net will is a handy addon that offers all the functionality of the NotifyIcon control AND the ToolTip in a handy package.

Filed under: C#, Code No Comments

C: Returning an array from a function

Recently I decided to learn C and have been diligently working my way through tutorials and websites, and since I'm more familiar with high level languages (C# for example) getting used to the more low level C is proving to be a challenge.

After getting to grips with the dreaded pointers I immediately ran into the problem of how to return an array from a function - the familiar methods used by anyone familiar with C# or VB.Net don't work, and attempts at implementing return unusual results. Basically, populating an array in a function and passing a reference to it is doomed to fail it's a regular local variable, with automatic duration, which means that it springs into existence when the function is called and disappears when the function returns. Passing a reference out of a function to a variable that has expired points to an junk.

After some googling, I found a helpful document that describes how to deal with the problem on http://c-faq.com, which describes in the three methods of returning arrays from functions which, briefly, are:

  1. The use of a static array within the function,
  2. Passing an array into the function and operating on it, and
  3. Creating an array in the function usign malloc.

All three methods have their own positives and negatives, but for the purposes on what I'm doing I'm going for the second one.

Filed under: Code No Comments

Get the first day of the week from a datetime

select dateadd(d ,-(datepart(weekday,getdate()-1)), getdate())

This is straightforwards: the patepart function extracts the weekday from the date, we remove one from that value, turn it to a negative number and then add it back the datetime. Simple.

Filed under: Code No Comments

Remove the time part of a TSQL datetime

select cast(floor(cast(getdate() as float)) as datetime)

Basically, we cast the datetime to a float, floor it and convert it back to a datetime. The first step produces a float representation of the datetime in which the date is to the left of decimal place and the time to the right, floor reduces it the lowest whole number and the last cast makes a datetime again.

Filed under: Code No Comments

SQL Server 2005: sp_msForEachDB

The following storped procedure will execute the print statement for every database that resides upon your SQL Server.

EXEC sp_msForEachDB 'PRINT ''?'''

Neat, eh? 'Tis an undocumented feature.

Filed under: Code No Comments