Saturday, September 17, 2016

VS2015 Tips - Useful Commands in Solution Explorer Toolbar

After a brief hiatus, I started coding again and developing with Visual Studio 2015 Professional.  Came across the following new commands (at least new to me) that I wanted to share:

Pending Changes Filter (Ctrl+[, P)

I wanted to create a summary of my changes and was hoping it allows me to filter only those files that are changed/added.  Sure enough, there is such an option.  Right next to the Home icon in the Solution Explorer panel you see a Clock icon with the tooltip "Pending Changes Filter" as shown below. It did exactly what I needed. 

Open Files Filter (Ctrl+[, O)

If you do not see this Clock icon, then you should see the Open Files Filter as shown below.  Once you click on it, it should only show the files that you have currently opened.


Sync with Active Document (Ctrl+[, S)

I remember having to hunt down this setting in the Options menu to sync the current file open with the item in Solution Explorer, but having it always sync gets in the way too.  So instead of having it always sync, but when you need it is really useful. 


Preview Selected Items

The following option is really nice as you want to quickly browse through the contents of various files, you can do so without actually having to open them.  Just have all the documents closed and this icon selected and then click on the items in Solution Explorer to have it simply show the contents of each file you selected.  You do not want to double-click on any item as that will open it. It won't do anything for images, references or any other binary files.  It seems to work only for files that of type "text."

I do not remember seeing these options in earlier versions of Visual Studio, so very happy to find these in VS2015.

Have Fun Coding!


Sonny

C# Object Initialization Examples (Cheat Sheet)

I really like the elegant object initialization facility in C# (I believe you can do the same in VB.NET also). Here are some examples of how you might initialize objects: Hope you find this cheat-sheet useful. Sonny

IE and setting HTML Global Attribute draggable to true results in weird behavior

I recently had to make a popup dialog box draggable or movable so that the user can read the text underneath it. I found the HTML Global Attribute draggable and set it to true. As the MDN page suggests, it does not quite work at least in the browsers I tested. I ended up adding an Angular Directive for draggable behavior as detailed on Angular Docs page. A working version of this directive can be seen on Plunker. Couple of things to be aware of if you are using somewhat similar approach: 1) I happened to have an input form in this dialog box and I could not enter text into any of the input fields. This is because of the event.preventDefault() line in the element.on event. Comment this line if you are making a draggable/movable input form. 2) Even though I was able to get the drag/move behavior for my dialog, I left the draggable="true" in there thinking it could not possibly hurt. Turns out that it is causing a weird behavior in IE. When I click on an input text box to enter text, I was not getting the input cursor and I had to double-click on it. Also when I double-click, it puts the focus at the beginning of text instead of where I double-clicked. Once I remove the draggable attribute, everything is working as expected. I spent quite a bit of time trying to figure what caused this weird behavior and hopefully this tip would help others find a solution quicker. Happy Coding! Sonny

Tuesday, May 15, 2012

What happened to zone information in IE 9 status bar?

In earlier versions of IE, I used to be able to see the zone information such as “Local intranet | Protected Mode: Off” in the middle of status bar and it was very useful while troubleshooting Server Errors.  This information is no longer available in the status bar starting with IE 9.  It is now under Files > Properties.

It also includes other information such as Protocol, Type, Connection, Address, Size of the page and the timestamps as shown below:

image

Hope this helps.

Sonny

Wednesday, March 28, 2012

Export Excel Spreadsheets to SQL Server


There are many posts out there about moving data from Excel to SQL Server and there are many twists/solutions to this need.  Here is another one that I have successfully been able to use in my projects.
In the past, I have used the OPENROWSET feature in SQL Server to upload data in an Excel Spreadsheet to a temporary/staging table in SQL Server.  That way I can use that table in queries however I want to or need to, but that comes with a cost. You would need to enable ad-hoc query feature in SQL Server. That might work in development environment, but, often times, the DBAs won’t enable that in the production environment for various security reasons.
So if you are an ASP.NET/C# developer and can quickly create an ASP.NET page or a simple C# console app, you can use this technique to quickly load data from an Excel Spreadsheet to SQL Server. This also frees you from having to upload the Excel file to the server as you would have to do in the case of OPENROWSET.
Here is the class in C# to export the data from Excel to SQL Server:
ExcelDataImport.cs
Here is one way how you could use the above class:
ExcelDataImport xlsDataImport = 
   new ExcelDataImport("data.xls", "Sheet1", "aTable");
xlsDataImport.UploadDataToSqlServerDb(connStr);
You could either pass a single sheet/table name pair or an array of sheet names and corresponding table names.
Most of the code should be self-explanatory, however, some things to keep in mind while using/running this code:
  1. Names in the first row of Excel Sheet would be used as column names in the SQL Server table if the table need to be created. So, make sure first row contains valid column names. Though SQL Server allows non-standard identifiers as long as they are delimited, I prefer standard identifiers. More about this topic is at Database Identifiers.
  2. As shown in the code, you could use “*” to indicate you want to import all columns in a given Sheet or specify specific list of column names just like you would do in SQL Server.
  3. For table names, you could use fully qualified names as you would in TSQL, if no schema is specified, SQL Server would simply look in the default schema.
  4. Target table must exist in the database and it will simply append rows to the target table in the database.
  5. You could also programmatically create Tables in SQL Server from your DataTable definition as done in the sample code. Idea for this was obtained from the blog: http://clicpharmacodebits.wordpress.com/2011/01/28/create-sqlserver-table-using-smo-sql-server-management-objects-in-net/
  6. Note that we are using Microsoft.ACE.OLEDB.12.0 driver, which supports both .xls and .xlsx formats unlike the old Microsoft.Jet.OLEDB.4.0. driver, which supports only the .xls format.
Other links related to this:
How to import data from Excel to SQL Server
OPENROWSET and not Text files but Excel files

Thanks for reading.
Sonny

Saturday, February 18, 2012

Installation of UniversalIndentGUI failed

If you ever want to pretty-print or beautify your source code files in Notepad++, you might have heard about UniversalIndentGUI (UIGUI) plugin for Notepad++ (Npp).  However, when you tried to install this plugin for Npp via the Plugin Manager, you might have gotten the following error:

Installation of UniversalIndentGUI failed

There is an active ticket at UniversalIndentGUI issues list, which has been opened for 16 moths with a single comment made about 7 weeks ago. I could not find any help related to how you could resolve this error.  I also could not find much reference to this plugin either from the UniversalIndentGUI page nor from Notepad++ Plugins List.  So I have downloaded the latest release of UIGUI to see if I could manually install it as a plugin for Npp, but disappointed to find out that it is not a plugin anymore but a stand-alone Windows application.

image 

It works pretty good as a Windows application and has support for lot of languages as you can see from the above screenshot taken from the UIGUI’s home page.  However, I could not search nor could I edit the file as easily as I could in Npp, so it would really be nice if I could get it to work as a plugin.

The last known version of UIGUI plugin for 1.0.2. which is what Npp uses to install when you try to install this plugin via Plugin Manager.  This info is in the file PluginManagerPlugins.xml, which is typically located in your profile directory on Windows 7.  That is in the following directory:

%USERPROFILE%\AppData\Roaming\Notepad++\plugins\config

If you can’t find it there, then bring up the Plugin Manager dialog and click on the Settings button at the bottom.  In the Plugin Manager Settings dialog, you should be able to see the Config path setting being used by your install of Npp.

Open the PluginManagerPlugins.xml and locate the UIGUI section and you should see something similar to the following:

image

Note: I had to use the XML Tools for Notepad++ to format this file. XML Tools for Notepad++ is another Npp plugin that gives you lot of XML tools including pretty-printing XML files.  I was able to install this using the Plugin Manager.

If you try to download the plugin zip file referenced in this config file, you get redirected to http://sourceforge.net/projects/universalindent/files/, which is the home location of UIGUI files.  From here, you would want to go to uigui folder and then to UniversalIndentGUI_1.0.2 folder, and from there, you want to download the UniversalIndentGUI_1.0.2_NotepadPPplugin.zip file.  Or you might want to just use the following URL to download the plugin zip file:

http://sourceforge.net/projects/universalindent/files/uigui/UniversalIndentGUI_1.0.2/UniversalIndentGUI_1.0.2_NotepadPPplugin.zip/download

After downloading the zip and extracting it to a some temp directory on your system, as per the XML snippet, move/copy the files as shown above. $NPPDIR$ is typically “C:\Program Files (x86)\Notepad++” and $PLUGINDIR$" is “C:\Program Files (x86)\Notepad++\plugins”.  Restart Npp and you should see UIGUI listed under the Plugins menu.  You should now be able to indent/format/pretty-print a wide-variety of source code files right inside Npp.

Happy Coding!

Sonny

Windows Command Console inside Notepad++

What happened to my nifty Windows Command icon inside Notepad++ (Npp), is the question I have asked myself a few times before and I do not really remember how I got it back the last time I looked for it.

If you are wondering about what the heck is Windows Command icon in Npp, then you must not have used it already.  It is the icon you get when you installed Npp plugin called NppExec.

NppExec is a very powerful/useful plugin for Npp. It gives you Console Window (cmd.exe) functionality right inside from Notepad++.  Note that it is not an emulator of Console Window (CW) nor a command interpreter according to NppExec manual.

That means all the DOS commands such as dir, xcopy, move that you would run in the CW can directly be run right from Npp.  For example, you might have used dir or tree command and redirected their output to a text file to include it in your documentation.  Well, you no longer need to do that, you could run such commands right from Npp and you could copy the output right from the Console inside Npp and paste it into any text file that you have opened in Npp.

If I remember correctly, it used to be included in the Npp default install, but I no longer see it in my latest version (v5.9.8) of Npp. After looking around, I finally learned that it is a plugin and hence need to be installed if it did not already get installed with the default Npp install.

To install it, you could use the Plugin Manager which is another plugin that gets included with the default install of Npp.  Under Plugins menu, go to Plugin Manager and click on “Show Plugin Manager” command to bring up the Plugin Manager dialog.

image

As shown above, navigate to the NppExec line and select and click on the Install button. Follow the prompts and it will automatically download and install the plugin for you.  You might be asked to restart the Npp to complete the installation.

Once the install is complete you would see NppExec listed under the Plugins menu as shown below:

image

Either select the “Show Console Dialog” from the above menu or click on the little console window icon image in the menu bar to get started. Go ahead and explore it.

It also has advanced scripting functionality, which I have not explored yet, but looks promising.

Hope you find this useful.

Sonny

Tuesday, October 18, 2011

Age of a given date in months v2.0

I got to think about code in my previous blog post about calculating the age of a given date in months and thought about a little more elegant way to do it, here is my modified version:

//Calculate the approximate age in months for a given date
function getAgeInMonths(fromDateStr)
{
 var frDate = new Date(fromDateStr);
 var toDate = new Date();
 if (frDate > toDate) {
  throw "Given date is in future, invalid!";
 }

 var frAge = (frDate.getFullYear() - 1) * 12 
          + frDate.getMonth() + 1;
 var toAge = (toDate.getFullYear() - 1) * 12 
          + toDate.getMonth() + 1;

 return toAge - frAge;
}
// test function to check some random dates
function test_getAgeInMonths()
{
   var arrDates = ['2011/05/01', '2010/09/05', 
      '2002/02/25', '1980/03/23'];

   for (var i=0; i < arrDates.length; ++i)
   {
      var ln = 'getAgeInMonths("'+arrDates[i]+'") = ' +    
         getAgeInMonths(arrDates[i]) + '<br/>';
      document.writeln(ln);
   }
}
I am basically calculating the age in months for each date since 0/0/0 AD and taking the difference between those ages. Here are the results from this version and they do match with the previous version:
Hope you find this useful.

Happy coding,
Sonny

Monday, October 17, 2011

Age of a given date in months

Have you ever tried to calculate the age of a given date in months using Javascript? Well, a co-worker looking for a way to do that. It does not have to use the date (day of the month), but just a rough calculation of age in months.

Here is what I have come up with:
//Calculate the approximate age in months for a given date
function getAgeInMonths(fromDateStr)
{
   var frDate = new Date(fromDateStr);
   var toDate = new Date();

   if (toDate.getFullYear() == frDate.getFullYear())
      return toDate.getMonth() - frDate.getMonth();
   else 
      return (12 - frDate.getMonth() - 1) + 
      ((toDate.getFullYear()-frDate.getFullYear()-1) * 12) 
      + (toDate.getMonth() + 1);
}

// test function to check some random dates
function test_getAgeInMonths()
{
   var arrDates = ['2011/05/01', '2010/09/05', '2002/02/25', '1980/03/23'];
   for (var i=0; i < arrDates.length; ++i)
   {
      document.writeln('getAgeInMonths("' + arrDates[i] + 
         '") = ' +       
         getAgeInMonths(arrDates[i]) + '
'); } }

Optionally you might want to use the isDate function to check the date string being passed-in is in valid date format or not.
The code is self explanatory and when you run the test function, you get the following results:

Hope you find this useful.

Happy coding,

Sonny

Monday, September 19, 2011

Find duplicates in a table - SSMS Tools to the rescue

The other day one of my co-workers was asking if there is a quick way to insert a SQL query to find duplicates in a given column in Microsoft SQL Server Management Studio (SSMS) similar to how you can insert SQL scripts, i.e. “Select Top 1000 Rows”, “Edit top 200 Rows” etc., when you right-click on a table name.

You could sort of do this using Template Explorer feature in SSMS, but it is not very user-friendly. A while back I have installed an add-in for SSMS called SSMS Tools Pack to help me organize length SQL Scripts into regions and sub-regions. This tool is very useful and I have yet to capitalize on all of the features that it offers.

This tool has a feature called Custom Scripts and it is very powerful.
Using the Custom Scripts feature, I have created a template that looks like this to quickly find duplicate values under a given column:

SELECT |ObjectName|, COUNT(*)
FROM |SchemaName|.|ParentTableOrViewName|
GROUP BY |ObjectName|
HAVING COUNT(*) > 1

The tokens between the pipes are automatically inserted by this tool when you instantiate the template from a context-menu off of the selected object. For example, I would right-click on column Title in a table called Courses and select the template "Find duplicates" from the SSMS Tools context menu. It will open a new Query window with the following script embedded:

SELECT Title, COUNT(*)
FROM dbo.Courses
GROUP BY Title
HAVING COUNT(*) > 1

You simply run the script to find the duplicates. As you can see this is a very useful feature and the next step is to come up with custom scripts that we find ourselves repeating them often and turn them into templates using SSMS Tools Pack.

Hope you find this tool useful and come up with some creative custom scripts that you could share them with your blog readers online.

Happy Coding,
Sonny

Thursday, September 15, 2011

Fully Qualified URL to refer to JIRA instance

We have our JIRA instance running on a server, for example, JIRA_SERVER01. Users can get to that server by using URL http://JIRA_SERVER01/.  We also created a CNAME to that server called JIRA so users can use a friendly name such as http://JIRA/ or fully qualified name, for example, http://JIRA.OurCompany.com/.

All of these URLs work fine, however, we want all of those URLs to automatically converged to the fully qualified name so regardless how users get to the JIRA application, the browser will always use the same URL and hence can take advantage of local cache and user’s cookies to restore the User’s last state.

Luckily, JIRA already uses a utility called UrlRewriteFilter (it is a Java Web Filter to be used on any J2EE compliant web application servers such as Tomcat, Resin or Orion) provided by http://www.tuckey.org/urlrewrite/.

Added the following rule elements to be the first node under the root node (urlrewrite) in the file urlrewrite.xml on the JIRA server:

<?xml version="1.0" encoding="utf-8" ?>
<!-- Make sure users are always redirected to fully qualified name when a short name is entered for JIRA application -->
<rule>
<name>Canonical Hostname for jira.OurCompany.com</name>
<note>The goal of this rule is to force the use of jira.OurCompany.com as the hostname to reach JIRA prod instance.</note>
<condition operator="notequal" name="host">^jira\.OurCompany\.com</condition>
<condition operator="notequal" name="host">^$</condition>
<from>^/(.*)</from>
<to last="true" type="permanent-redirect">http://jira.OurCompany.com/$1</to>
</rule>

The file urlrewrite.xml should be in folder [JIRA_INSTALLATION_DIRECTORY]\atlassian-jira\WEB-INF

Note of Caution:  This change is made in JIRA v4.2.1 running in a stand-along service mode.  This is NOT officially supported by JIRA and use your discretion while making these kind of changes to JIRA installation files. As with any such unsupported changes, make them at your own risk and make sure you backup the files prior to your changes so you can revert to the original configuration if needed.

There may be other ways to achieve this same behavior, but this is what I did and it works fine for us.

Cheers,

Sonny

Saturday, September 10, 2011

Combining Multiple C# Using Statements

I sometimes find myself having to write the following code where I need to use multiple Using statements and end up nesting them.

using (StreamReader reader = new StreamReader("FileToProcess.txt";))
{
    using (StreamWriter results = new StreamWriter("Results.txt"))
    {
        using (StreamWriter errors = new StreamWriter("Errors.txt"))
        {
            // Read/Write from/to the files as needed
        }
    }
}

There is nothing wrong with this, but I do not like having too much indentation in my code.  When I searched on the web to see if there are other ways to avoid nesting multiple Using statements, I found the post on StackOverflow:
http://stackoverflow.com/questions/966086/using-various-types-in-a-using-statement-c

Basically, the statement inside the using is like a variable declaration, so if you happen to be declaring multiple variables of same type that all implement IDisposable, then you could combine them inside a single using declaration.  For example, I could combine results and errors variables in the above code as follows:

using (StreamReader reader = new StreamReader("FileToProcess.txt"))
{
    using (StreamWriter results = new StreamWriter("Results.txt"), 
            errors = new StreamWriter("Errors.txt"))
    {
        // Read/Write from/to the files as needed
    }
}

It is a little better, but it would be nice if I can get rid of the second using statement or nesting another level, so I have modified the original code to as follows:

StreamReader reader;
StreamWriter results, errors;
using (IDisposable _reader = new StreamReader("FileToProcess.txt"),
    _results = new StreamWriter("Results.txt"),
    _errors = new StreamWriter("Errors.txt"))
{
    reader = (StreamReader)_reader;
    results = (StreamWriter)_results;
    errors = (StreamWriter)_errors;

    // Read/Write from/to the files as needed
}

Granted I have more lines of code that does the same thing as the original code plus extra casting for the sake of a single using statement and eliminating multiple levels of nesting, I however prefer this later version of code.
While getting ready to write this report, I was searching StackOverflow(SO) for the above link as I found that post a while back. While searching SO, I found this other post where it shows how you could write separate usings one below another without having to nest them.
http://stackoverflow.com/questions/1329739/nested-using-statements-in-c

Taking a cue from this post, I have changed the code as follows:

using (StreamReader reader = new StreamReader("FileToProcess.txt"))
using (StreamWriter results = new StreamWriter("Results.txt"))
using (StreamWriter errors = new StreamWriter("Errors.txt"))
{
    // Read/Write from/to the files as needed
}

This is the ideal solution in my opinion. You could list all of usings one by one explicitly and do not have to nest them. I understand, I originally said, I wanted to put all of them in a single using statement, but my main objective is to avoid nesting and this syntax that I was not aware of until now suits me the best.

Thanks for reading.

Sonny

Friday, September 9, 2011

Collapse/Expand All Comments in JIRA Issue Details Screen

In JIRA, when you are looking at an issue, it often shows all the comments expanded. This would be OK if there are only a couple of comments and they are compact, but often comments are added to JIRA via emails and each email contains the whole thread and thus it makes very hard to read/browse through the comments as they all seem to run together with same text repeated in successive comments. For example, you would often see comments displayed like this (http://jira.atlassian.com/browse/JRA-12569):You could collapse all the comments and JIRA will automatically show the first line of the comment which makes it very easy to look at all the comments as whole and improves the readability of the issue. For example, the above page is displayed like below when all the comments are collapsed:Problem:

You would have to collapse each comment one by one as there is no single button that can collapse all the comments in one click. This could be quite tedious if there are many comments in an issue. I believe if the JIRA instance is integrated with Confluence, it provides this feature but our instance of JIRA is stand-alone and that is why I came up with this technique.

Solution:

Use the following steps to install two macros that allow you to collapse/expand all the comments in JIRA window with a single click:

  1. Launch Internet Explorer (IE)
  2. While in the IE window, type “about:blank” in the address bar.
  3. Press Ctrl+D key combination to bring up the Add a Favorite dialog box.
  4. In this dialog box, select the “Favorites Bar” from the “Create in” drop-down and type “Collapse JIRA Comments” in the “Name” box and click on the “Add” button.

  5. Turn on the “Favorites Bar” if it is not already on. Right-click on the toolbar area and select “Favorites Bar”.
  6. In the “Favorites Bar”, you should now see a new icon by name “Collapse JIRA Comments” as shown below:

  7. Right-click on this icon and click on Properties command to bring up the link properties dialog box as shown below:

  8. In this dialog box, while in the “Web Document” tab, enter the following javascript code in the box titled “URL”:

javascript:if(!window._ctwixi){function _ctwixi(){jQuery(“.verbose”).each(function(){if (jQuery(this).css(“display”) == “block”) jQuery(this).find(“.twixi”).click();});return;}}_ctwixi();

  1. Click on the “Change Icon” button to bring up the “Change Icon” dialog box as shown below:

  2. In this dialog box, click on the “Browse” button and select the shell32.dll and click “Open” as shown below:

  3. Select the collapsed folder icon in the icons shown in the “Change Icon” dialog box and click OK as shown below:

  4. Click on “OK” in the “Collapse JIRA Comments Properties” dialog box.
  5. Click on “Yes” in the following warning dialog box:

  6. Navigate to any JIRA issue page and click on this button in the favorites bar to collapse all the comments.
  7. Repeat the above steps to add a button to “Expand JIRA Comments” using the following javascript code:

javascript:if(!window._etwixi){function _etwixi(){jQuery(“.concise”).each(function(){if (jQuery(this).css(“display”) == “block”) jQuery(this).find(“.twixi”).click();});return;}}_etwixi();

Conclusion:

You should now have two buttons in your IE Favorites Bar that you could use to collapse/expand JIRA comments while looking at a JIRA issue.

As you can see, I am using the jQuery in my javascript snippets, this works because JIRA already uses jQuery and hence we do not have to worry about making sure jQuery is already loaded.

Thanks for reading and look forward to your comments.

Thursday, September 8, 2011

Check MD5 or SHA1 hashes in Windows

If you ever download stuff off of web, you should use some sort of checksum tool.  I believe in most Unix/Linux flavors of Operating Systems, come with a checksum tool, but no such luck in Windows.

Have you every wished every edition of Windows came with checksum tool?  Well, almost.  As far as know, most of the Windows versions do not come with this tool, however, Microsoft does provide one.  In the past, I have used to use various other third party tools whichever I could find online at that instance, but I would rather use one that is provided by Microsoft itself.

So, just go to this page and install it:
http://www.microsoft.com/download/en/details.aspx?id=11533

As the page states, this small command line tool works on Windows 2000 or higher.

Hope you find this useful.

Thanks.

Sonny

Monday, March 21, 2011

Can’t Use Inline Function Calls While Calling a Stored Procedure

I can’t believe it has been more than 18months since I have written a blog.
Today, I was trying to call a stored procedure in SQL Server 2008 and keep getting Incorrect syntax error.
For example, let’s say, I have a following stored procedure on the asp.net membership provider that returns active users since a given date:
CREATE PROCEDURE _GetActiveUserSinceDate
@SinceDate DATETIME
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM [dbo].[aspnet_Users]
WHERE [LastActivityDate] >= @SinceDate
END
And when, I try to call this stored procedure as follows to get me the list of users logged in the last 7 days:
EXEC [dbo].[_GetActiveUserSinceDate] DATEADD(d, -7, GETDATE())
I would get the following error message:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'd'.
I was able to get around this error message by explicitly assigning the return value of DATEADD function to a variable and passing that variable to my stored procedure as shown below:
DECLARE @SinceDate DATETIME
SET @SinceDate = DATEADD(d, -7, GETDATE())
EXEC [dbo].[_GetActiveUserSinceDate] @SinceDate
I keep thinking of why do I need to have this extra variable and why can’t use the function inline and so searched on MSDN and found the following page:
Look under the “Specifying Parameters” section and you see the following statement:
The supplied value must be a constant or a variable; you cannot specify a function name as a parameter value. Variables can be user-defined or system variables such as @@spid.
So there you have it and it is my bad to use the same mindset while writing TSQL as I do while writing C# code. If you already know about this, you are a lot a better TSQL programmer than me.
Thanks for reading.
Sonny

Tuesday, August 11, 2009

24 Hours of Nonstop SQL Server Training

Get ready for brain overload, 24 hours of nonstop SQL Server training by experts all around the world! And best of all it is FREE and you don't have to go anywhere to get this training. Here is the link to this training http://24hours.sqlpass.org.

Anyway the reason for my post is not to propagate about this event, though it is not a bad idea, but to share a little javascript. When I went to register for sessions, all the start times are listed in GMT and I wanted to be able to see the times in local timezone format. Here is a sample screenshot of how the start times are listed:



If you are using IE8, it is really easy to run custom javascript code on any page, you simply press F12 and go to the Script tab in the Developer Tools window and then run the following javascript code:


var sp = document.getElementById("schMeetings");
var timeSpans = sp.getElementsByTagName("span");
for (var i = 0; i < timeSpans.length; ++i)
{
if (timeSpans[i].id.indexOf("lblScheduletime") > 0)
{
var dtStr = timeSpans[i].innerText;
var dt = new Date(dtStr.substr(0, dtStr.length-"+00:00".length));
timeSpans[i].innerHTML += " [" + dt.toLocaleString() + "]";
}
}


Once I ran this javascript snippet, I can see the start times in my local timezone format as shown below:



I really like the new IE8 Developer Tools and this is just a sample of what you can do with custom javascript on any web page you visit.

Happy Coding,

Sonny

Thursday, April 16, 2009

Visio Flow Diagram "Loop Limit" example/sample

I was looking for an example of how the "Loop Limit" shape can be used in a Flow Diagram and could not find any diagrams either in Microsoft documentation or on their website that show the sample usage of this shape. Most of the pages on the web are also not helpful either. Most web pages are either people asking about how to use this shape or a couple of blogs that basically rehash Visio online documentation that lists all the shapes that are available for Flow Diagrams.

After searching for a while, I finally found a PDF document by Roxaneh Chamlou on FAA site that has it. I wish Microsoft has concise sample diagrams that show how some of these non-standard shapes are intended to be used.

Here is a sample diagram that I have created taking a cue from the above PDF document:

This diagram should be self explanatory and I would love to hear what you think about it? Is there a better way to show the loop either with or with out "Loop Limit" shape?

Hope this helps someone out there.

Happy Drawing!

Sonny

Friday, January 16, 2009

Checks if a given value is Number or not in Javascript



The other day I needed to check via javascript if the text entered in a textbox is a valid or not. I know I can use the built-in isNaN function, but wanted to make sure that would in work all the scenarios. So, I searched online, but I found a couple of examples on the web, but they were using regular expression to check. I am not sure why they are using regular expressions, when you have isNaN function.

I created a test function to make sure isNaN works in all the scenarios and found that it works for almost everything I tried except for three values, they are null, empty string and a string with just spaces. For these three inputs, it returns false but you really want it to return true since obviously they are not valid numbers. I wrote an helper function to get around that and the following page shows the helper method as well as the test function I wrote to validate this helper function:

// Checks if a given value is a valid number or not
// The argument could be any of the following:
// a) A number itself
// b) Number in quotes, i.e. number stored as string
// c) Number could be in scientific format
// d) An object

function isNumber(val)
{
  // we need to explicitly handle null values
  // because isNaN returns false when it should return true 
  if (null == val) return false;
 

  // if it is an empty string or a string with just spaces
  // isNaN returns false, but we really need it to return true
  // this expression will remove spaces if the given value is a string type
  if (typeof(val) == "string")
   val = val.replace(/\s*/g, "");
  
  if (val == "") return false;

  return !isNaN(val);
} 


// test function to test the isNumber function
function isNumber_Test(val, expResult)
{

  var dblQuote = '';
  if (typeof(val) == "string")
   dblQuote = '"';

  var actResult = isNumber(val);

  var clr = 'green';
  if (actResult != expResult)
   clr = 'red';

  document.write('
');
  document.write('isNumber(' + dblQuote + val + dblQuote + ')');
  document.write('' + actResult + '');
  document.write('' + expResult + '');
  document.write('
');
}
By the way, I am using a Javascript utility called SyntaxHighlighter, to render this code. If you have not already used this utility, I would highly recommend you check it out.

Here are some test results of isNumber() function:

Test isNumber() Function


Expression Result Expected Result

Happy coding,
Sonny

Friday, November 21, 2008

Parser Error Message: Access to the path ... (ASP.NET)

I have been working on an ASP.NET page and all of a sudden, I was getting Parse Error on this page as shown below:

All I did was modify the code in the page and plus I could build the page in Visual Studio 2008 with out any errors. I could also build the entire web site with out any errors, but I was still getting the error.

I compared the file with the previous version and I do not see any special characters or anything like that. I even tried removing the using statements and putting them back again thinking there may be some hidden character on the first line, but still did not help.

I finally, made a copy of that file and got the previous version from the Source Control and then the error is gone. I then deleted the previous version and renamed the file (that was giving the problem) to its original name and the error is still gone.

Bottom line, I do not know what caused it and neither do I know how doing what I just did fixed the problem, but thought putting it here would might come handy for anyone that run into this issue.

After I did this, I also found this blog post and the author of this post had to reset the permissions of the file that was causing this error.

Have fun coding.
Sonny

Saturday, November 1, 2008

Using AJAX 3.5 toolkit with latest version of SharpForge 0.5.14b

I just installed the SharpForge version 0.5.14b on my system that has .NET Framework 3.5 and Visual Studio 2008 + Visual Studio SP1. That is, I have AJAX toolkit version 3.5 running and when I browse to the SharpForge web page, I am getting the following error from web.config:

I tried changing the version # for System.Web.Extensions to 3.5.0.0 everywhere it is referenced in the web.config but I am still getting this version error for other user controls in the app. I searched on the SharpForge site and all it indicated is that you would have to install AJAX 1.1 toolkit and I do not want to install the older version of AJAX along with the latest version.
I finally found few pages on the web that talk about how you can run old web sites that are built using AJAX 1.1 toolkit with the latest version with out having to install the older AJAX toolkit. You basically tell the app to use 3.5 version of System.Web.Extensions every time it needs the older version of System.Web.Extension using runtime section.
Here is a blog post that talks about it:
HOWTO: Running ASP.NET 2.0 Ajax Toolkit 1.0.x in .NET 3.5 / SP1 IIS

I spent quite a bit of time chasing this issue and I hope other people find this solution sooner.

Thanks.

Sonny