The Beauty of Command-line Utilities

The Beauty of Command-line Utilities

I like the way command-line tools can be adapted for automating complex tasks.

For instance, if you had to populate the list of names of computers in your LAN in a combo box, the net.exe command can be utilized with the Process.Start() method in C#

Process netsend = new Process();
netsend.StartInfo.FileName = "net.exe";
netsend.StartInfo.CreateNoWindow = true;
netsend.StartInfo.Arguments = "view";
netsend.StartInfo.RedirectStandardOutput = true;
netsend.StartInfo.UseShellExecute = false;
netsend.StartInfo.RedirectStandardError = true;
netsend.Start();

StreamReader sr = new StreamReader(netsend.StandardOutput.BaseStream, netsend.StandardOutput.CurrentEncoding);

string sss = "";
while ((sss = sr.ReadLine()) != null)
{
if (sss.StartsWith("\\"))
comboBox1.Items.Add(sss.Substring(2).Substring(0, sss.Substring(2).IndexOf(" ")).ToUpper();
}

sr.Close();

Setting the CreateNoWindow property to true hides the console window.

Here is a list of command-line tools that I've found helpful (work in progress) -
Dear Reader, what are your favorite command-line tools?
Read More

Book Review: Beginning SQL Server 2005 for Developers

Beginning SQL Server 2005 for Developers by Robin Dewson lives up to it's title of being a helpful resource for beginners to SQL Server 2005. The author patiently walks the reader through the basics & a wide breadth of topics with adequate examples in the 500+ paged book spanning 14 chapters. Many of the examples are demonstrated using multiple modes - SQL Server Management Studio, TSQL & Templates.

The book is filled with interesting facts, "gotchas", practical tips & tricks that make the chapters engaging. I have used the SELECT statement for years but I did not know that $IDENTITY & $ROWGUID can be used with the SELECT statement to return the value from the IDENTITY column & the ROWGUID column if such columns exist within the table being querying upon. Similarly I have used the COUNT function but didn't know there was a COUNT_BIG function as well that returns a bigint data type value unlike COUNT which returns an int type value.

I feel the information in the book could have been better presented & organized. There were some places where the examples of usage could have been closer to the topic for better assimilation.

My rating: 4/5

Also see:
SSMS Tips & Tricks
Free SQL Server 2008 Learning Resources
Read More

Book Review: Cancer Has Its Privileges

We have put a man on the moon decades ago, but it's sad that science doesn't have a solution yet to wipe out the scourge of Cancer which has been there for centuries. The Big C is a devastating illness that cripples it's victims physically, monetarily & more than that, mentally as it affects their loved ones as well.

Cancer Has Its Privileges: Stories of Hope and LaughterCancer Has Its Privileges: Stories of Hope and Laughter is a poignant compilation of thoughts, anecdotes, poems and "chicken soup for the soul" type of experiences by brave cancer survivors & their loved ones. This is the fourth book of the author Christine Clifford, a cancer survivor & founder of The Cancer Club, who believes in the therapeutic value of positive thinking & humor.

The book has tips for cancer patients, their family & friends on coping with the dreaded illness. Sometimes well-meaning well-wishers of a patient get disconnected not knowing how to help. There is a chapter on how friends & family can help. Some ways of showing care & support to the afflicted is by spending time together, accompanying them on their visits to the hospital, offering to help with daily chores, preparing meals, being a "nap nanny", gifting them their favorite books & music and complimenting them on their positive changes.

This is a good book for anyone whose life has been touched directly or indirectly by cancer.
Read More

Doloto - useful addition to a Web Developer's Toolkit

I have been using the following Web Development tools over the past few years and they have helped me to be more productive -

I discovered 2 new tools that not just tell you what is inhibiting performance of a page but also cut the fat off web pages making them speedier - Doloto & Smush.it

Doloto is a JavaScript download optimizer developed by Ben Livshits of Microsoft Research.

Smush.it is an image optimizer. It reports how many bytes would be saved by optimizing the page's images and provides a downloadable zip file with the minimized "lossless" image files.

Are there any other indispensable Web Developement tools that I'm missing?
Read More

Free eBook: The Principles Of Successful Freelancing‏

The Principles Of Successful FreelancingSitePoint occasionally gives away ebooks of some of their publications. In the recent past, they have given away titles like "The Art & Science Of CSS" and "Firefox 3 REVEALED".

For a limited time, they are offering a free eBook "The Principles Of Successful Freelancing" if you follow them on Twitter or provide your email address (they will email the link from where you can download the eBook).

The book has around 200+ pages & 8 chapters -
Chapter 1: Considering Freelancing?
Chapter 2: Prepare for the Transition
Chapter 3: Manage Your Money
Chapter 4: Set Yourself Up
Chapter 5: Win the Work
Chapter 6: Give Great Service
Chapter 7: Achieve Work–Life Balance
Chapter 8: Where to from Here?

Also see:
Startup 101 - free, online serialized book for first-time entrepreneurs
Giveaways
Building non-technical skills
Read More
Appending to file with BCP

Appending to file with BCP

I found an interesting tip about BCP (the SQL Server command line tool) on the MSDN Forums

While exporting data from SQL Server to a file using BCP, it always overwrites the contents of the file specified in command if it already exists or creates a new file but it cannot append.

If ever you need the output of a query appended to the info in a existing data file, use an intermediary file to manage the updation of the data file -

Exec master..xp_cmdshell 'bcp "select name from sysobjects" queryout "c:\tempexportfile.txt" -c -T -SYourServerName'
Exec master..xp_cmdshell 'type "c:\tempexportfile.txt" >> "c:\mainexportfile.txt"

Also see:
Exporting to Excel with bcp
Read More

Excel Tips & Tricks

My Wife & I, share a liking for Excel (& good food). Once in a while, we exchange Excel tips & tricks that we may have picked up. I recognized this common interest a couple of years ago, when she pointed out that the count of rows & columns have thankfully increased since Excel 2003 and marvelled at the improvements in Charts in Excel 2007 with the same excitement that is usually reserved for a special dish. I did not loose a chance then to tell her how to get a Ribbon-less pre-Excel 2007 UI.

Just so that I do not forget the tips & tricks we discuss, I plan to document them here.

1) Find & replace a special character - This trick is adapted from a response on the MrExcel Forum

Let's say you have received an Excel file with a pesky non printing character at several places in a sheet and now you need to replace it with something else. How to go about it?

Get the numeric code of the pesky character using the CODE function. For instance, the formula =CODE("!") will display the numeric code for ! or 33

Next, invoke the Find box using the shortcut Ctrl + F. Click in the Find box, hold Alt key and type 0 followed by numeric code of the mysterious character you have encountered(for example, for "!", you would type 033 instead of 33), on the number keypad and then the release the Alt key. As soon as you release the Alt key the character whose numeric code you typed will appear in the Find box.

Now go to the Replace tab, place the character to substitute in the "Replace with" textbox, and hit Replace All.

Excel Help suggests in the topic "Remove spaces and non printing characters from text" that you can also use a combination of the TRIM, CLEAN, and SUBSTITUTE functions to remove non printing characters

2) Matching row, values of adjacent cells - I find this question frequently being asked on technical Forums. To get a result that is based on values of adjacent cells in a row, use the combination of INDEX & MATCH as explained in the topic "Look up values in a list of data" in Excel Help.

3) (Added: 17-Sep-09) Increment numeric values in a range of cells by a standard value - Jonathan Van Houtte's tip shows you how to add a value of 10 to large number of existing cells containing (let's say) salary amounts at one shot.
  1. Type 10 in any empty cell.
  2. Copy that cell.
  3. Select the range of cells containing Salary amounts
  4. Right-Click, and choose Paste Special.
  5. On the Paste Special dialog box, click the Add radio button (in the Operation frame)
  6. Click "OK"
  7. Clear the cell with the 10.

To be continued...

Also see:
HOW TO create an Excel 2007 Macro
HOW TO conditionally format entire row/s based on a cell's text value in Excel 2007
Read More