Compiler Warnings -- What is the trick about them?

Add Comment | Sep 09, 2011

Be it a C# Compiler or a PHP page we all have seen errors and warnings. What is the difference between them?

Error: A failing condition which prevents the compiler from proceeding further.

Warning: A condition which the compiler can tolerate and gracefully proceed. There might be little performance and/or objective degradation.

In the strictest sense I would recommend turning on the preference 'Treat Warnings As Errors' that way you would ensure that your code is very clean. However there might be situations where a warning can be safely ignored besides you can avoid the warning along with the fact save it for the future.

Say for example you do not want to bother about an exception variable in the catch block? The quickest shortcut is that you can have something like

catch

{

}

But what happens in future you want to examine the exception? Then you have to modify the code. The other way around would be

catch (Exception exVariable)

{

   Debug.WriteLine (exVariable.Message);

}

For Visual studio this message gets written into Debug Listener and since the variable is being accessed it does not throw a warning message as well.

Necessity to lock your workstation

Add Comment | Sep 09, 2011

Most of our computers have sophisticated desktop locking tricks. Even in the older style Windows 98 we did have 'Password protected screensavers'. Why were they for? When we step away of computers there is a dire need to protect the data and the programs that are running in our computers from unauthorized access and prying eyes.

Windows provide a quick shortcut Windows + L to lock the workstation. So you save a few milli-seconds from using CTRL+ALT+DELETE and choosing Lock Workstation/Lock Computer (as it is called differently in different versions of Windows) Nevertheless we still feel lazy to use the two keys to lock the workstation and we get victimized by the minimum ('shoulder surfing').

I hence thought I would write a small C# code which you can have it in the Quick Launch bar. When you are moving away from the computer just click it and it will lock your workstation. The simple C# code is as below:

 

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace WindowsLock
{
    class Program
    {

        [DllImport("User32.Dll", EntryPoint = "LockWorkStation")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool LockWorkStation();

        static void Main(string[] args)
        {

            try
            {
                LockWorkStation();
                Environment.Exit(0);
            }
            catch (Exception LockWorkstationException)
            {
                Debug.WriteLine(LockWorkstationException.Message);
            }
        }
    }
}


Personalized URLs through Bit.Ly

Add Comment | Oct 30, 2010

We have a lot of URL shorteners like Goo.Gl and Bit.Ly. Though each of the URL shorteners give a straight forward URL shortening right from their homepages without even in need to create an account it would be wise to have an account with them and create URLs through the same. We stand to gain a lot of advantages through the same. A few of them are:

 

  1. Tracking and review of the URLs that are created by us
  2. Click Statistics
  3. In future if we want to retire an URL it would be easier for us to locate and achieve the same.

Bit.Ly goes one step further besides giving personalized accounts. They provide application keys for free so that we can programmatically create the URLs through our account.  Also the API documentation for creating Bit.Ly URLs can be found here.

Live Writer has problems downloading the WYSIWYG theme on LD Express

Add Comment | Oct 30, 2010

I was trying to configure Live Writer to publish post on my LD Express. Whilst the initial configuration of blog was fine, the test post and theme download fails. Live Writer KB indicates that community server and similar blog platforms has a delay between post and time it takes for the blog platform to publish the same. I would try to bring the same to the attention of support team to see if this can be fixed and solve.

A Good .NET Quiz ...

Add Comment | Apr 24, 2010

A Good .NET Quiz ...

Whilst casually surfing today afternoon I came across a good .NET quiz in one of the indian software company website. It is rather a general technology quiz than just a .NET quiz because it also contains options for the following technologies.

 

  1. .NET
  2. PHP
  3. Javascript
  4. MySql
  5. Testing
  6. QTP
  7. English
  8. Aptitude
  9. General Knowledge
  10. Science
  11. HTML
  12. CSS
  13. All

It also has the following levels for the Quiz:

 

  1. Easy
  2. Medium
  3. Hard
  4. All

 

The URL of the quiz is as below: http://www.qualitypointtech.net/quiz/listing_sub_level.php

An alternative way to request read reciepts

Add Comment | Apr 07, 2010

An alternative way to request read reciepts

Sometime or other we use messaging namespaces like System.Net.Mail or System.Web.Mail to send emails from our applications. When we would need to include headers to request delivery or return reciepts (often called as Message Disposition Notifications) we lock ourselves to the limitation that not all email servers/email clients can satisfy this. We can enhance this border a little now, thanks to a new innovation I discovered from Gawab.

It embeds a small invisible image of 1x1 dimension and the image source reads as recieptimg.php?id=2323425324. When this image is requested by the web browser or email client, the serverside handler does a smart mapping based on the ID to indicate that the message was read. We call them as 'Web Bugs'. But wait it is not a fool proof solution since spammers misuse this technique to confirm activeness of an email address and most of the email clients suppress inline images for security reasons.

I just thought anyway would share this observation for the benefit of others.

Source Browsing in FireFox

Add Comment | Apr 07, 2010

Source Browsing in FireFox

Just casually observed this a few minutes back with my Mozilla Firefox 3.6.3. When you do a view source of any  page in Internet Explorer it just renders as editable inoperative HTML. However in Firefox the hyperlinks are shown clickable and active. When you click on any hyperlink the most obvious and expected output would be that the target page would appear in one of the new tab in the parent browser. However the View Source window refreshed with the HTML source of the new page.

I believe this gesture of Firefox would help us to take a journey back into Lynx Text Browsing in a way.

Online Syntax Colorizer

Add Comment | Apr 07, 2010

Online Syntax Colorizer

For those of us who share code snippets along with articles the most daunting problem would be to preserve the syntax colorizations. There are a few ways to manage through this additional requirements:

  1. Tweak and point the color picker in the article textearea.
  2. Import the code to a word processor and then copy the code. However, the word processor would unnecessarily swell the contents with too much of formatting contents.
  3. Quick Online Colorizer: http://tohtml.com/ (This supports a lot of languages including autodetection). I would also recommend if GWB could link to this website and auto-colorize the code when we paste it in our articles.

 

A Gentle .NET touch to Unix Touch

Add Comment | Apr 07, 2010

A Gentle .NET touch to Unix Touch

The Unix world has an elegant utility called 'touch' which would modify the timestamp of the file whose path is being passed an argument to  it. Unfortunately, we don't have a quick and direct such tool in Windows domain. However, just a few lines of code in C# can fill this gap to embrace and rejuvenate any file in the file system, subject to access ACL restrictions with the current timestamp.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LavanyaDeepak.Utilities
{
    class Touch
    {
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Please specify the path of the file to operate upon.");
                return;
            }

            if (!File.Exists(args[0]))
            {
                
                try
                {
                    FileAttributes objFileAttributes = File.GetAttributes(args[0]);
                    if ((objFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        Console.WriteLine("The input was not a regular file.");
                        return;
                    }
                }
                catch { }

                Console.WriteLine("The file does not seem to be exist.");
                return;
                
            }

            try
            {
                File.SetLastWriteTime(args[0], DateTime.Now);
                Console.WriteLine("The touch completed successfully");
            }
            catch (System.UnauthorizedAccessException exUnauthException)
            {
                Console.WriteLine("Unable to touch file. Access is denied. The security manager responded: " + exUnauthException.Message);
            }
            catch (IOException exFileAccessException)
            {
                Console.WriteLine("Unable to touch file. The IO interface failed to complete request and responded: " + exFileAccessException.Message);
            }
            catch (Exception exGenericException)
            {
                Console.WriteLine("Unable to touch file. An internal error occured. The details are: " + exGenericException.Message);
            }
        }
    }
}

GWB -- Little More Interesting Info

Add Comment | Apr 06, 2010

GWB -- Little More Interesting Info

Whilst writing the post on 'Warming with GWB', I just recalled another historic entity often shortly known as GWB. It is in fact 'GWBasic' which we I started programming about fifteen years back way back in 1994 to 1995.   GWBASIC was actually a version of BASIC in the lines of BASICA from Compaq. Eventually it was absorbed into QBasic and QuickBasic suite of products.

Just thought I would share this recollection too in this context.