Random Gradient Wallpaper Generator

by dimitrovski 29. October 2009 17:50

Today I stumbled across a post called “Random Gradient Wallpaper Generator” by Kirill Osenkov. This reminded me of the past when I used to make such simple yet cool wallpapers quite often. The nostalgia trip sparked my interest to dig into the project and find out more as it is publicly available on CodePlex.

When I saw the the wallpaper generating algorithm I smiled. The code is written very well so it wasn’t a laughter but just a smile. More of a smirk actually and I hope it will become apparent later why. So anyways, the original code looks something like this

   1: public static void GradientRect(Graphics g, Rectangle r, int steps, GradientOptions o)
   2: {
   3:     using (SolidBrush b = new SolidBrush(Color.WhiteSmoke))
   4:     {
   5:         for (int i = 0; i < steps; i++)
   6:         {
   7:             //deprecated for simplicity
   8:             for (int j = 0; j < steps; j++)
   9:             {
  10:                 //deprecated for simplicity 
  11:             }
  12:         }
  13:     }
  14: }

I cut out parts of it for the sake of simplicity so what I wanted to point out is that there is a nested loop to created the wallpaper giving the whole algorithm an 0(N*N) performance. In this case the number of steps is just 256 and actually for the processors of today performing 2562 loops is actually a piece of cake. But in any case the perfectionist child in me wanted to simplify things have some fun. More...

Currently rated 5.0 by 8 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Measure the time a certain SQL statement takes to execute

by dimitrovski 24. September 2009 19:07

Some time ago I was working on a rather complex stored procedure that aggregates data from different databases and presents the summary in a single result set. For a while the stored procedure was working fine but recently the query was getting time-outs. I was sure that something was changed on one of the databases but I wasn’t sure on which one and I didn’t want to go through all of them one by one*. Instead I was measuring the time it took each of the sections in the larger stored procedure to execute. To do that I used a small code snippet that I found on SqlServerCentral.com. The original article can be found here but you need to register for the site to view it. Since I use that web site on occasional basis and I always forget my account name/password I decided to store that code snippet here in my longer term memory.

   1: DECLARE @start_time datetime, @stop_time datetime
   2: SET @start_time = GETDATE() 
   3:  
   4: --some sql code here
   5:  
   6: SET @stop_time = GETDATE()
   7:  
   8: PRINT 'Execution time: ' + 
   9:        CONVERT( varchar(10), DATEDIFF(ms, @start_time, @stop_time) ) + 
  10:        ' ms'

The code is self explanatory I believe. On line 2 the time the query starts is recorded using the GETDATE function, some SQL code is executed and right after that you get another time snapshot. Finally using the DATEDIFF function you calculate the duration between the two dates in milliseconds (ms) and you print the time in the console. So simple yet so powerful :)

This code is tested and works fine in SQL Server 2000 and 2005. Although not tested in other version, I see no reason that it wouldn’t work in earlier or later versions of SQL Server

*As a strong believer in Murphy’s Law, I know that no matter how random the order of choosing a database to test, the slow database would be the last one :)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Resharper Live Templates in VB.NET

by dimitrovski 22. April 2009 12:36

A while ago I saw a screencast on using Live Templates with Resharper. According to the screencast and to the Resharper web site, in order to insert a Live Template in the code you need to start typing the name of the template and then the template will be shown in Intelisense. Alternatively you could type the full name of the template, then press tab twice and the code appears. However neither of the two approaches work in VB.NET. First it does not show up in Intelisense and second even if you type the name of the template followed by pressing TAB+TAB again nothing happens. I looked over at their support forum and it seems that you have to do it differently in VB.

In VB.NET you need to type the template name and then CTRL + E + L. This is not as elegant as in C# but nevertheless it works.

Live Templates

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Problem Installing Windows Live Writer on Vista x86

by dimitrovski 31. March 2009 23:36

As I mentioned in my previous post, I really wanted to install Microsoft Live Writer on my computer so that I can quickly create some blog posts. However I cannot I am not quite sure what the reason for this is. The installer gives me this as a result of the installation

Most importantly, the installer tells me that it's Done! Then it tells me that actually it had a fatal error during installation and it suggests to close all other programs and to try again (which doesn't help). In addition is says, that it looks like another program is preventing the installer from working. hr:0x80070643. This is the best part; I mean it is just great that I know the code of the error. It seemed to me that it will be easy to find what the problem is after I search the Internetz with this error code but so far I could not find resolution.

Hopefully by the time I write my next blog post (which based on historical data should be in December, 2011) I'll be able to resolve this issue.

P.S. After closing the dialog above, the best part is that I'm greeted with a message "Welcome to Windows Live", "Your new programs are in the Windows Live folder on the Start menu". Hmmm, no they are not :)

Update 1: I noticed that during installation, the Windows Live Messenger would start itself up. I thought maybe the messenger application is the one preventing the installer, so I uninstalled it (I don't use it anyways). After finding how to uninstall it (you have to click uninstall on Windows Live Essentials, there is no separate entry for Live Messenger), I tried installing Live Writer but I encountered the same problem.

Update 2: I was suspecting that maybe my Symantec Endpoint Protection somehow prevents the installer, so I disabled it for few minutes to try to install Live Writer. Again I had no luck and got the same error message.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

The Snipping tool in Windows Vista has disappeared

by dimitrovski 31. March 2009 22:10

For some time now I was puzzled as to why the Snipping Tool in Vista wouldn't show up when I'd look for it in my start menu. Not paying too much attention to it, I had a workaround - take a screenshot of the screen (using the Print Screen key) and then quickly crop the selection that I need in Paint.

I had forgotten about this 'problem' but recently I was working on something that involves taking screenshots often, so I decided to have a look into it. Quick Google search revealed that I removed that program myself when I decided that I do not want to have the 'Tablet PC optional components' on my desktop computer. I'm not going to portray the feelings I had when I found out that according to Microsoft, capturing images from your screen is a "Tablet feature", instead I'll just say that I was glad that I had my Snipping Tool back.

But the excitement was short lived. I found out that I could not do simple edits on the captured image such as drawing a line or a rectangle. Yes, you can scribble on the image, but if you want to create a straight line you need to have hands of a surgeon. Having lost my faith in the usefulness of the Snipping tool I decided to finally install a proper tool. At work I use SnagIt, a program that is very dear to me so I decided I will go for it even though it has a price tag associated with it. Once I was at the TechSmith's web site (the creators of SnagIt), I found out that they now offer a new freeware product called Jing that does exactly what I need. With a download size of 7.6MB I was a bit skeptical at first, thinking that it is some bloat-ware program, but once I installed it that wasn't an issue any more because it runs fast. It does use a lot of memory (96MB Working set) but for me it is not an issue as I do not use it in combination with other resource hungry applications. In addition to the simple interface to take screenshots, this program even has a dead simple interface to upload the screenshot online so that I can share it with friends.

That issue is solved, next on the agenda "Why can I not install Windows Live Writer on my Windows Vista machine".

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen