Tuesday, May 14, 2013

Insert a Line of Text or Record to the Beginning of a Text File Using Windows Batch Script

I would like to share a Windows batch script that would add a line of text / record to the beginning of a text file.

Text File: example.txt
Text to be inserted: Hello World!

COPY example.txt temp.txt
ECHO Hello World!>example.txt
TYPE temp.txt >>example.txt
DEL temp.txt

1) Copy the example.txt content to a temporay file
COPY example.txt temp.txt

2) Overwrite the example.txt content with new text we need to add to the beginning
ECHO Hello World!>example.txt

3) Append  the content of temp.txt to example.txt
TYPE temp.txt >>example.txt

4) Delete the temp.txt file
DEL temp.txt

It worked well! Share your comments for queries, improvements and suggestions.

Saturday, March 23, 2013

"A script on this page is causing Internet Explorer to run slowly" error solution

This is because some scripts may take an excessive amount of time to run, Internet Explorer prompts the user to decide whether they would like to continue running the slow script.

There are situations when a Web page contains script that takes an unusually long time to run. If you are scripting an ActiveX control on a Web page to transfer a very large file or do a large database query, this will often cause a significantly long delay.

This error could be fixed with a Microsoft Patch Update. Check out this Microsoft page for solution..

Saturday, March 16, 2013

How to use ILMerge?

"A Zero Installation Technique for Portable Applications"

Build Portable in .NET C# App using ILMerge

I had a situation where I need to develop a portable application with simple installation. Finally I found a way make it zero installation!

If you are developing a portable Windows based application on .NET platform, you could benefit from IL Merging technique for your deployment.

IL Merge is a technique and a research product from Microsoft, to merge multiple DLLs and EXEs (.NET Assemblies) together to form a merged file (exe or dll). This way no separate DLL file is required.
Follow the below steps for merging an exe and dll associated with the project.

Download and install the ILMerge utility from Microsoft Website.

Step 1: Download ILMerge utility and install it in your machine

Step 2: Compile and Publish your Project to a folder (eg: C:\Publish\)

Step 3: Use the ilmerge command to merge the exe and dll files and output single exe file

ILMerge Command
Syntax (Simple*): ilmerge <input assembly 1> <input assembly 2> /out:<output file> /target:<dll|exe|winexe>

*For complete set of options and syntax refer ILMerge Documentation


C:\Program Files\Microsoft\ILMerge>ilmerge C:\Publish\MyProgram.exe C:\Publish\MyLibrary.dll /out:C:\Publish\MyWinApp.exe /target:winexe /ndebug

ilmerge – Command
MyProgram.exe – Output from the published folder
MyLibrary.dll – Any library used in the program
/target:winexe – We need to output a single exe file for Windows Platform
/output – Output folder and filename
/ndebug – To disable debug (.pdb file)

Note: Use the exe file first in the order of input files to get .exe as extension for output file.

Please share your experience and suggestions in the comments section below.

Wednesday, January 16, 2013

JavaScript: console.log() - Best Practice

JavaScript developers, must be well aware of the console.log() function to log messages to the console window.

Today, I share my experience to write a wrapper function for console.log().

Simple Code 1: Ignore log message if the console object is missing

<script type="text/javascript" language="javascript">
    window.console = window.console || { log: function (d) {} };
    /* write your JavaScript code below this line */
    console.log("Message: Testing Console.log");


Simple Code 2: Modified to show log message as alert if the console object is missing and the global variable for debug is set to true. You can turn it off when you publish to production.

<script type="text/javascript" language="javascript">

    var debug = true;

    window.console = window.console || { log: function (d) 
        {if(debug){alert("Sorry! Logger not available on this 
            browser. \n\n" + d);} } };

    /* write your JavaScript code below this line */
    console.log("Message: Testing Console.log");


Simple Code 3: Same as above but with JQuery.

<script type="text/javascript" language="javascript">

    var debug = true;

      window.console = window.console || { log: function (d) 
        {if(debug){alert("Sorry! Logger not available on this 
            browser. \n\n" + d);} } };

    /* write your JavaScript code below this line */
    console.log("Message: Testing Console.log");


More Info:

This is a best practice to avoid errors with browsers that don't handle console.log missing object by default. For example, Internet Explorer don't handle the missing object and ignores all scripts following the error. Unfortunately, IE will not throw any error on this condition and eat your time debugging and tracing for the invisible error.

Note 1: console object is not a standard object in ECMA Script. However, it is one of the most widely used objects by developers for debugging JavaScript programs.

Note 2: In Internet Explorer 8 and Internet Explorer 9, console object is exposed only when Developer Tools (Shortcut - F12) are opened for the active tab.

Happy Coding!

Thursday, January 10, 2013

Who could innovate better?

Today, I came across an activity "Search for Social Advocate" inside the organization.

When organizations around the world hunting for social media specialist and writers on job boards and social networks, I am amazed with this idea of searching the advocates inside the organization.

"Social Advocates" - Interesting term!

It is better to that somebody who understand, live and experience the organization, writes about it on the social platforms. It is a Great thought, Isn't it?

I believe it brings in better productivity and usefulness of the content shared.

I am not aware of the internals or plans for the "Social Advocates". But I believe there should be a  team of Social Advocates, who could the organization co-ordinate and form a team (Virtual?). Train them with products, policies and basic writing strategies with marketing touch. I believe, the organization by their values and policies, will never intervene on the creativity of the individuals.

The team could be formed with experts, interested people from every group and product team to share thought and happenings in the markets/industry, technology and strategies.

We could always depend on the professional marketing team for promotions through advertisements and campaign activities. But for content, definitely this is the right way. Millions can't be wrong. Content is the KING, always.

Honestly, I un-follow people and pages that kills my interest with repeats and spams.There would be no chance for such scenario here, I believe.

Organization?? Who else? It is EMC - The Strong and Innovative Storage Giant of All Times.