Random Findings as a Developer

May 31, 2011

Windows 7 – Multi-Monitor Shortcuts

Filed under: Microsoft Windows — Andrew @ 6:51 pm
Here are some nice little shortcuts I found when playing in Windows 7:
  • Windows + Down Arrow – Minimize Window (if not maximized) or Restore Down (if maximized)
  • Windows + Up Arrow – Maximize Window
  • Windows + Left Arrow – Dock window on left hand side of the screen (if already docked, it moves it to the next screen)
  • Windows + Right Arrow – Dock window on right hand side of the screen (if already docked, it moves it to the next screen)
  • Windows + Shift + Left Arrow – Send window as-is (i.e. Maximized) to Left Monitor (if already on the left window, it will move to the rightmost window)
  • Windows + Shift + Right Arrow – Send window as-is (i.e. Maximized) to Right Monitor (if already on the right window, it will move to the rightmost window)

I hope this makes using multiple monitors a little more convenient in Windows 7.

May 27, 2011

Day 2 – D2Plug – The Setup

Filed under: D2Plug,Global Scale Servers — Andrew @ 1:49 am

After my first night of playing with the D2Plug, I read more of the instruction manual and realized that I didn’t actually need to use the JTAG port in order to connect to the console window for the server.  It turns out there is a port conveniently labeled “Console” which when a Micro-B USB port is inserted, this becomes your serial console.  So much for the JTAG board I got with my Guruplug.

It came more or less set up with everything I needed on it built in and ready for me to use.  After an hour and a half of software updates (yay for updating Ubuntu 10.04) and another hour of installation, the system was set up and ready for me to use as a media server (the original reason why I got the Guruplug).

The snag was where to put it.  I tried to take the unit apart at the power supply unit (PSU) and use the plastic pieces to cover it, but that didn’t work too well, the pieces of plastic that came with it to cover this piece of hardware was insanely difficult to get on to the point that I thought that if I were to need to remove it, I would not be able to.  Instead, I ended up just mounting the D2Plug on the wall of the shelf where it will live.

Man was that a much needed swap.  The Guruplug was originally placed in my basement due to the fact that the server sounded like a hair dryer that was constantly going.  Now when I walk downstairs, all I hear is silence.

Both of these products have been great thus far, I look forward to their future releases :).

May 26, 2011

Day 1 – D2Plug

Filed under: D2Plug,Global Scale Servers — Andrew @ 1:09 am

So I got the D2Plug for Christmas and I immediately started playing with it.  Aside from reading the online PDF, I found it relatively hard to figure out what the default password for the “ubuntu” account (account that comes automatically enabled on the server).

Have no fear, the information is here:

Username: ubuntu

Password: marvell

Reference Manual: http://www.globalscaletechnologies.com/download/D2Plug_QSG_20111011.pdf

Now to get the JTag port working as well as my other external keyboard :)

May 23, 2011

Great SQL Resource

Filed under: SQL,SQL Server — Andrew @ 8:26 pm

I have been reading a site for quite a while, the author does a great job explaining all of the questions. The site is Explain Extended.

Hopefully it’ll be very helpful :)

May 22, 2011

Visual Studio 2008 – Enable Code Modifications When in Debugging Mode

Filed under: Visual Studio — Andrew @ 3:37 pm

Today I was playing with Visual Studio 2008 and I went to run my application in debugging mode.  After running it, I realized that there was a small issue that I wanted to resolve but I didn’t want to terminate the Web Application fully (i.e. just modify the code and then recompile).  When I started typing, I got a nice little slap in the face from Visual Studio as seen below:

Visual Studio 2008 - Edit and Continue

Debugging Error Message


After some hunting around on Google I came across a bunch of Stack Overflow posts that told me how to allow me to disable that nice little slap in the face in order to allow me to continue to code.  To do this you must do the following (while the application is not running in debug mode):

  1. Click on “Tools”
  2. Click on “Options”
  3. Select “Debugging”
  4. Click on “Edit and Continue”
  5. Uncheck the “Enable Edit and Continue”


Visual Studio 2008 - Options - Edit And Continue

Disabling Edit and Continue

After following those steps I was good to go.

May 21, 2011

Testing Applications

Filed under: Testing — Tags: — Andrew @ 12:53 pm

Testing an application is not an easy task to do. As well, sometimes it can be a very tedious task to do. However, it should always be done or else you risk shipping applications which are prone to bugs which will in turn look badly on the individual / team developing the application especially since some issues are easy to find with the proper testing.

For my first co-op job I worked as a tester for an application.  Yes, this meant that I was no where near the code of the application, but it also meant that I needed to know the actual requirements for the application which we were testing.  I made a small poster describing some of my findings while working there.

To take a look please click here.

Title Case

Filed under: PHP — Andrew @ 11:47 am


Capitalizing the first character of each word in a string (i.e. “the final countdown” → “The Final Countdown”).



C# has a built-in function for this. Its called ‘toTitleCase’, hidden deep within the System.Globalization namespace.

So how do you use it?

using System.Globalization;
// Get the instance of the TextInfo class to use to (no constructor), comes from the current thread
TextInfo info = (System.Threading.Thread.CurrentThread.CurrentCulture).TextInfo;
string sample = "hello world";
// Print to console the title case
// Outputs: Hello World

The ‘ToTitleCase’ function returns an instance of a string which will have all of the first characters in words changed to upper case, and leaves the rest of the text as is. This means that if a word is in all capital letters it will remain that way. A simple work around for this is to call the string object’s ‘ToLower’ function before we send the string into the ‘ToTitleCase’ function.

For example,

using System.Globalization;
// Get the instance of the TextInfo class to use to (no constructor), comes from the current thread
TextInfo info = (System.Threading.Thread.CurrentThread.CurrentCulture).TextInfo;
string sample = "HELLO world";
// Print to console the title case
// Outputs: HELLO World
// Pre-lowercase everything
// Outputs: Hello World


The PHP version of this function is a fair bit easier to get to.  PHP’s function is called ‘ucwords’.  However, similar to the C# version you should always have the string sent in in lower case if you want it to only make the first character of each word upper case (it only changes the first character and doesn’t touch the others).

// Outputs: The Final Countdown
echo ucwords ( 'the final countdown' );

May 17, 2011

Don’t use File when you mean Directory

Filed under: C# — Andrew @ 1:49 pm

I was working on a small archiving task for a project and one of the steps is to move a folder from one location to another. Not thinking anything of it, I tried to use File.Exists(archiveFullPath) assuming that a directory would also be considered a file. But for every folder I tried it kept returning false despite them actually existing.

So then I tried switching it over to the similar function but under the Directory object (Directory.Exists(archiveFullPath)) and it worked like a charm, returning true for the specific directories which I knew existed.

To make a long story short, if you are trying to do anything with a directory, use the Directory object instead of the File because directories aren’t treated the same as files.

void Main(string[] args)
    string path = @"C:\testing\";
    string working = path + @"Working\";
    string archive = path + @"Archive\";
    // Outputs: false
    // Outputs: false
    // Outputs: true
    // Outputs: true
    // Put the thread to sleep temporarily

Determining Long Running Queries Programmatically

Filed under: SQL Server — Andrew @ 1:25 pm

I recently needed to figure out what queries were taking the longest to run. I could complete this by using the Execution Plan, however if the slow running query is part of a data load, that is a little harder to do (it requires you to stop the data load to run the steps manually).

Luckily I found a nice set of 2 queries that help to filter out which are the slow queries. They are as follows:

This first query just provides information about some of the queries which are currently being run on the server along with their specific process ids so that we can dig deeper into them later on.

SELECT  p.spid ,
                                       DATEDIFF(ms, P.last_batch, GETDATE()),
                                       '1900-01-01'), 121), 12) AS 'batch_duration' ,
        P.program_name ,
        P.hostname ,
FROM    master.dbo.sysprocesses P
WHERE   P.spid > 50
        AND P.STATUS NOT IN ( 'background', 'sleeping' )
                           'CHECKPOINT SLEEP', 'RA MANAGER' )
ORDER BY batch_duration DESC

After running the first query, you are able to retrieve the process id and then pass that into the following query to receive the actual body of the query being executed (replacing XXX with the actual process id).

    @stmt_start INT ,
    @stmt_end INT ,
    @sql_handle BINARY(20)
-- Fill this in
SET @spid = XXX
        @sql_handle = sql_handle ,
        @stmt_start = CASE stmt_start
                        WHEN 0 THEN 0
                        ELSE stmt_start / 2
                      END ,
        @stmt_end = CASE stmt_end
                      WHEN -1 THEN -1
                      ELSE stmt_end / 2
FROM    master.dbo.sysprocesses
WHERE   spid = @spid
SELECT  SUBSTRING(text, COALESCE(NULLIF(@stmt_start, 0), 1),
                  CASE @stmt_end
                    WHEN -1 THEN DATALENGTH(text)
                    ELSE ( @stmt_end - @stmt_start )
FROM    ::

I hope that this helps you as much as it helped me!

Source: http://stackoverflow.com/questions/941763/list-the-queries-running-on-sql-server

May 11, 2011

Objects Remaining in Memory

Filed under: C#,Programming Languages — Andrew @ 5:37 pm

I was implementing an image resizer and I kept running into a problem where I kept getting error messages saying that the image file was in use even after I disposed of the object in memory (the last step was to remove the unresized image).

Calling object.Dispose() is just a suggestion to say “whenever you want, we don’t need this in memory anymore”. However, because it doesn’t get rid of it immediately, meaning that it is still being referenced which means that the file won’t be able to be deleted immediately.

In order to get around this, you need to call the garbage collector yourself to force the application to get rid of the object from memory.

The Code:

string dest = @"C:\";
FileInfo imageFile = new FileInfo(file);
Image image = ResizeImage(Image.FromFile(file),size);
// Save the file to the file system
SaveAsJpeg(image, dest + imageFile.Name, 100);
// We don't need the image in memory any more (suggest it to be deleted)
// Call the garbage collector
// Delete the old file
Older Posts »

Powered by WordPress