Blog

Blogging on programming and life in general.

  • Published on
    -
    3 min read

    WOW! Windows Vista is...

    ...quite slow! This is what I thought as I was setting up my mothers laptop running on Windows Vista (compared to Windows XP Professional Edition running on a similar spec computer. I decided to run the "Windows Experiance Index" where Windows Vista determines the performance rate you are achieving. The score I achieved was a mere 3.3!!!

    Anyway, how can I can I improve the general performance? Well I carried out the following:

    1) Disable Indexing Service

    The Indexing Service is a little program that uses a hell a lot of memory that indexes and updates lists of all the files that are on your computer. It does this so that when you do a search for something on your computer, it will search faster by scanning the index lists. If you don’t search your computer often, then why have something you don't need. To disable, cary out the following:

    • If you want, you can just remove any extra areas of search, so you can keep your fast searching for some areas.

    • Go to My Computer, right click on C: drive, go to the General tab, and uncheck Index this drive for faster searching, select Include subfolders and files. Select Add/Remove Programs.

    2) Removing Sidebar

    I have to say that the Sidebar looks great and displays information in the form of widgets really nicely! However, it can take some system resources and adds a longer startup time. This is dependent on the amount on info displayed on your Desktop.

    3) Clear Up Restore Points

    From the very first day you start to use your PC, Windows stores shadow copies of your system files. Over time, the amount of shadow copies can waste precious space. Windows Vista allows you to remove all restore points up to the most date. To do this carry out the following:

    • Goto Start, Accessories, and System Tools.
    • Click on Disk Cleanup.
    • When the Disk Cleanup window appears, click on the 'More Options' tab.
    • Under 'System Restore and Shadow Copies' section click 'Clean Up...'

    Voila! You will see the amount of disk space that has been freed! Awesome!

    4) Hibernation is a No No!

    Yeah I have to admit the Hibernation feature is cool feature that allows you to startup your PC in the condition you left it. The only thing is that the amount of memory that it consumes is quite large. So its now a good idea to overuse this function.

    Watch out for the Automatic hibernation process runs constantly in the background using up resources. If you’re happy to hibernate manually, and you’re not using a laptop on battery power, switch it off by the carrying out the following:

    • Open Control Panel.
    • Select System and Maintenance and click 'Change when the computer sleeps'.
    • Set 'Put the computer to sleep' to Never and click Save changes.

    5) Tweak VI

    This software provides a wealth of tools for messing with Vista's guts, including a boot-configuration manager, a CPU optimizer, browser-settings managers and tons more. Whats even better...its free!!!!

    6) Disable User Account Control

    User Account Control puts in a layer of security that stops you from making system changes without confirming them. More experienced users willing to take the security risk can disable this to speed things up when performing low-level tasks. User Account Control can slow down and can be irritating. To disable, carry out the following:

    • Open Control Panel.
    • Choose User Accounts and Family Safety.
    • Select User Accounts and click Turn User Account Control off.

    7) General Updates

    Ensure your PC is up-to-date with the most current patches. This will also help improve performance, but very slightly.

    8) Disable Unused Startup Programs

    Try and reduce the amount of programs that need to be run on startup. You will find the utility to disable any unwanted startup programs in Windows Defender. Yes, I thought that this was a strange place as well! But I have to say it is a good idea because the Software Explorer feature lets you take a close look at every running program and remove or disable those that are starting automatically.

    Well give it a go and if you find any extra things to add here, please leave a comment!

  • Published on
    -
    1 min read

    UNION ALL

    The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type.

    One of my work colleagues at work showed me something that I never knew about UNION SQL statement. By default the UNION statement does the exact same thing as a SELECT DISTINCT on the resulting data. But what if we want to carry out a UNION without distincting the data result? Thats where the UNION ALL comes into play.

    Example

    Table 1: tblCars-UK

    Car_ID Car_Name
    1 Volvo
    2 Volkswagen
    3 Chevrolet
    4 Nissan
    5 BMW

    Table 2: tblCars-US

    | Car_ID | Car**_Name** | | 1 | Pontiac | | 2 | Chrysler | | 3 | Chevrolet | | 4 | Dodge | | 5 | BMW |

    If we used a UNION statement, the results would be as follows:

    Select car_name from tblCars-UK
    UNION
    Select car_name from tbleCars-US 
    

    | Car_Name | | Volvo | | Volkswagen | | Chevrolet | | Nissan | | BMW | | Pontiac | | Chrysler | | Dodge |

    As you can see from the results above that the duplicate car entries have been removed and only displayed once. Now this is what will happen if we use UNION ALL statement:

    Select car_name from tblCars-UK
    UNION ALL
    Select car_name from tbleCars-US
    

    | Car_Name | | Volvo | | Volkswagen | | Chevrolet | | Nissan | | BMW | | Pontiac | | Chrysler | | Chevrolet | | Dodge | | BMW |

  • Published on
    -
    1 min read

    Fixing BlogEngine HTML Editor Problem

    I have to say that after using BlogEngine for my first couple of posts, I can't think of any other Blogging tool to use. However, the thing that really annoys me about BlogEngine is the HTML editor when I want to create my postings. I have found that the TinyMCE HTML editor rejects some HTML tags. For example, <code> and <iframe> tags.

    I have been desperately looking through the BlogEngine forum posting's to see if there is anyway to fix this problem. There was no specific way of rectifying this problem.

    However, I found a way to fix this!!! Laughing

    You will need to make a simple change to the tinyMCE.ascx file located in the admin folder (/wwwroot/admin/). Find the following line:

    extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],script[charset|defer|language|src|type]",

    Now you will see in this line that there are tag elements listed as valid. All you have to do is add tags to this line in order for them to be accepted by the TinyMCE HTML editor. For example, I want my <code> and <iframe> tags to be accepted:

    extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],script[charset|defer|language|src|type],code,iframe",

    And there you have it!

    Hope this helps!

  • Published on
    -
    1 min read

    Inline If Statement

    Standard IF statements are great. But I found that when I am using very simple conditions within my IF Statement I waste a lot of space in my code.

    Example 1:

    public int IfExample(bool bolFlag)
    {
    int result = 0;
    if (bolFlag)
    {
    result = 1;
    }
    else
    {
    result = 2;
    }
    return result;
    } 
    

    There is no problem using Example 1. But there is a much quicker and less tedius way of using a simple conditional IF statement.

    Example 2:

    public int IfExample(bool bolFlag)
    {
    return (bolFlag) ? 1 : 2;
    }
    

    This example is basically saying: "return if (bolFlag) 1 else 2". So you are in theory assigning the IF condition to the variable.

    I know it takes a little while to understand the syntax. But it is really good for those less complex IF conditions.

  • Published on
    -
    1 min read

    C# NULL Coalescing Operator

    Here is a really neat trick that a mate showed me at work. It is a way to assign one variable to another, but only if the variable is not null. If it is null, you want to populate the target variable with perhaps another value.

    For example, lets assume we have an integer variable "intCounter". We could check if the integer contents was null, and if not return another value:

    int intCounter = 5;
    int intResult = intCounter ?? 0;
    // Output: intResult == 5 
    

    We got the following output because intCounter did not contain a null.

    The C# NULL coalescing operator also works with string variables as well:

    string strMessage = "Hello World";
    string strResult = strMessage ?? "No message";
    // Output: strResult == "Hello World" 
    


    So we can see from the two examples above that this NULL Coalescing operator is quite useful. Here is an example of what would have happened if a variable was null:

    string strMessage = null;
    string strResult = strMessage ?? "No message";
    // Output: strResult == "No message" 
    

    Scott Guthrie talks more about this in his own blog and how to use this feature in LINQ: http://weblogs.asp.net/scottgu/archive/2007/09/20/the-new-c-null-coalescing-operator-and-using-it-with-linq.aspx

  • The SCOPE_IDENTITY() function are used in Insert queries to return the last identity value within your table. However, I never knew how to retrieve the ID value when using this function in my code.

    Create an Insert Query in your Data Access Layer called "InsertUser". For example:

    INSERT INTO Users (FirstName, LastName, DateOfBirth, Email, City) VALUES (@FirstName, @LastName, @DateOfBirth, @Email, @City);
    SELECT SCOPE_IDENTITY() 
    

    When you return to the DataSet Designer you'll see that the "InsertUser" method has been created. If this new method doesn't have a parameter for each column in the table, chances are you forgot to terminate the INSERT statement with a semi-colon. Configure the "InsertUser" method and ensure you have a semi-colon delimiting the INSERT and SELECT statements.

    By default, insert methods issue non-query methods, meaning that they return the number of affected rows. However, we want the "InsertUser" method to return the value returned by the query, not the number of rows affected. To accomplish this, adjust the "InsertUser" method's ExecuteMode property to Scalar (this can be found in the Properties panel on the right).

    The following code will put your new Insert Query into action:

    int intUserID = Convert.ToInt32(BLL.InsertUser("John", "Doe", "16/06/1985", "joe@hotmail.com", "Oxford"));
    //Output new User ID
    Response.Write("New User ID Inserted: " + intUserID); 
    

    For more info regarding the use of Data Access in ASP.NET 2.0 go to: http://msdn2.microsoft.com/en-us/library/Aa581778.aspx