Chinh Do

Chinh’s not quite random thoughts on software development, .NET, gadgets, and other things.

First time here? Check out my greatest hits or look around in the archives, and consider subscribing to the latest posts via RSS or email. I am also on Twitter and Google Plus. Thanks for visiting.
21st August 2012

Replacement straws for Thermos Bottles

Sorry this has nothing to do with coding.

But if you have kids and have the Thermos aluminum straw Bottles such as the Thermos Funtainer or Foogo Straw bottles, you can get replacement straws directly from Thermos for $1 a piece. My kids like to bite the straws and they get destroyed pretty quickly. If you need just the top part of the straw, that would be $0.50.

Thermos Funtainer Bottle, Disney's Carsimage

Apparently, people are reselling these straws on Ebay and other sites for $7-$10 a piece! So Thermos is limiting each order to 5 straws. I am putting this out there to hopefully direct people to the source.

Call Thermos directly at 1-800-831-9242 to order your replacement straws. If outside the US, try 1-847-439-7821.

posted in Kids | 36 Comments

9th March 2012

Removing Excess Whitespace from a String

I was looking for the most efficient way to remove excess white space from a string and wrote the following benchmark. Guess which algorithm is faster?

const int iterations = 200000;
const string expr = " Hello    world! Why    are so    many spaces?  Testing One   two three    four    five.";

// Remove excess space using Regex
var doRegex = new Action(() =>
{
    for (int i = 0; i < iterations; i++)
    {
        var newStr = Regex.Replace(expr, @"\s{2,}", " ");
    }
});


// Remove excess space using Split/Join
var doSplit = new Action(() =>
{
    for (int i = 0; i < iterations; i++)
    {
        var newStr = String.Join(" ", expr.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
    }
});
var benchMark = new Func<string, Action, long>((name, a) =>
{
    var sw = Stopwatch.StartNew();
    a();
    sw.Stop();
    Console.WriteLine(name + ": " + sw.ElapsedMilliseconds);
    return sw.ElapsedMilliseconds;
});

// Warming up
Console.WriteLine("Warming up.");
doRegex();
doSplit();

// Run benchmark
long regexElapsed = benchMark("Regex", doRegex);
long splitElapsed = benchMark("Split", doSplit);

On my PC, the Split method is about 7.5 times faster than Regex.

image

posted in Dotnet/.NET - C#, Programming | 14 Comments

6th August 2011

Transactional File Manager Version 1.2 .1 Released

Version 1.2 of Transactional File Manager is now available on CodePlex.

Here’s the release notes:

Release Notes

This is a minor bug-fix/minor refactor release.
Fixes:

  • Copy now uses the overwrite parameter correctly.
  • Fixes crashing problem on some machines due to use of GetsequentialGuid.
  • CreateDirectory now supports rolling back nested directories.
  • RollbackFile Rollback() may throw exception when original directory has been deleted.
  • Security issue when writing to event logs.

Enhancements:

  • Upgrade solution/project files to Visual Studio 2010
  • Use NUnit instead of VSTS framework
  • Changes to support Visual Studio Express

Thanks to karbuke and dorong for their contributions.

posted in Dotnet/.NET - C#, Programming | 1 Comment

15th April 2011

Managing, Tagging, Organizing Videos with Picasa

I enjoy making taking and making short videos. My kids are usually featured in the videos in one way or another. Last year we went on a month-long vacation to Vietnam and I recorded a huge number of raw videos. With so many raw takes to work with, using Windows Explorer and browsing around without some system of tagging, keyword searching, etc. becomes extremely tedious and unmanageable.

So I started to look for a way to manage/categorize all of these raw videos and I think I’ve found a pretty good and free solution: Picasa (from Google).

The current version of Picasa for Windows (version 3.8) allows you to specify titles for images and videos, as well as assigning various tags to them. The user interface is very user-friendly. And the actual searches are typical Google-lighting-fast.

Using Picasa as a video manager

What I do is I go through each raw video take, give it a title and assign some tags. Then later I am able to very quickly search for videos. For example, if I need a take involving a dolly pan to the right, I just type “dolly pan” into Picasa and instantly the takes with those keywords come up.

posted in Photography and Video | 8 Comments

13th January 2011

WBR HTML Tag

The little known WBR tag is great for formatting HTML tables. Add it to specific places in your table cell values to give the browser the option to add a line break there. This is very useful when displaying tables with long strings that would otherwise cause horizontal scrolling.

Here’s a sample table, displaying some info. Since the values in the tables do not have spaces or tabs, the browser is forced to display the values on one line:

Key Value
ChinhDo.TestApp.TestClass.ExampleKey1 this.is.an.example.of.a.very.long.string

Here’s the same table, with <wbr/> tags inserted where periods are:

Key Value
ChinhDo.TestApp.TestClass.ExampleKey1 this.is.an.example.of.a.very.long.string

posted in Programming, Tips | 0 Comments

7th September 2010

Getting the Starting Day of the Week for Any Date

From my code snippets, here’s a function that will return the starting day of the week for any date:

/// <summary>
/// Gets the start of the week that contains the specified date.
/// </summary>
/// <param name="date">The date.</param>
/// <param name="weekStartsOn">The day that each week starts on.</param>
/// <returns>The start date of the week.</returns>
public static DateTime GetStartOfWeek(DateTime date, DayOfWeek weekStartsOn)
{
    int days = date.DayOfWeek - weekStartsOn;
    DateTime startOfWeek = days>=0 ? date.AddDays(-days) : date.AddDays(-7 - days);
    return startOfWeek;
}

posted in Dotnet/.NET - C#, Programming | 1 Comment

11th June 2010

World Cup 2010 In Glorious 3D

3DTV is here! This message shows up on my DirecTV receiver/DVR yesterday:

Your receiver is now 3D ready! With a 3D television and 3D glasses, you can view up to 25 matches of the 2010 FIFA World Coup tournament in spectacular 3D on ESPN 3D Channel 106.

Wow! 25 World cup soccer games in 3D! Wait a minute, I think I see some dead pixels on my current HDTV.

posted in Gadgets, HDTV, Technology | 0 Comments

8th June 2010

Transactional File Manager Is Now On CodePlex

It’s my first open source project! I’ve gone open source with my Transactional File Manager. Check out the CodePlex link here.

Use any file system as a transactional file system! Transactional File Manager is a .NET API that supports including file system operations such as file copy, move, delete in a transaction. It’s an implementation of System.Transaction.IEnlistmentNotification (works with System.Transactions.TransactionScope).

image

More on Transactional File Manager in my original blog post on it. If you are interested in contributing to the project, let me know.

posted in Dotnet/.NET - C#, Programming | 3 Comments

10th May 2010

MSMQ Installation on Windows Server 2008 Fail with 0x80070643

If you get one of these errors starting MSMQ Server or installing MSMQ on Windows (Server 2008), this article describes a potential solution:

  • You cannot start MSMQ Service with the following entry in the Application Event Log: The Message Queuing service cannot start. The internal private queue ‘admin_queue$’ cannot be initialized. If the problem persists, reinstall Message Queuing. Error 0xc00e0001.
  • You cannot install MSMQ with the following error: Attempt to install Message Queuing Server failed with error code 0x80070643. Fatal error during installation. The following features were not installed: Message Queuing Services/Message Queuing Server.

    MSMQ Installation Result

 

For me, the solution was to delete the Registry key KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ, then try the installation again.

See also:

posted in Dotnet/.NET - C#, MSMQ, Programming | 11 Comments

27th March 2010

Don’t hire ghost hunters who are afraid of ghosts

Your house is haunted. You can’t stand living with the ghosts anymore and decide to call in the professional, a ghost hunter. The ghost hunter comes, nicely equipped with all kinds of shiny ghost hunting equipment, and proceeds to immediately pass out and fall to to the floor with a loud thud at first sight of the ghosts.

Well, in a nutshell, that is the story of the new Event Viewer in Windows Vista and Windows Server 2008. The new Event Viewer looks very nice and all. Trouble is, it now won’t work when there is a syntax error in machine.config or other .NET Framework problems. Apparently, in Windows Vista and Windows 2008, someone at Microsoft decided to rewrite the Event Viewer utility (a perfectly usable and solid utility in previous versions of Windows) in .NET.

MMC could not create the snap-in. The snap-in might not have been installed correctly. Name: Event Viewer.

So, the lesson I learned from this is: don’t hire ghost hunters who are afraid of ghosts. Or, don’t write a utility designed to view monitoring and troubleshooting messages that can fail due to unnecessary dependencies. A critical system troubleshooting utility such as Event Viewer should be the last thing that fails.

What to do when you cannot run Event Viewer in Windows Vista/Windows Server 2008/or Windows 7?

If you get the following error:

MMC could not create the snap-in. The snap-in might now have been installed correctly. Name: Event Viewer. CLSID: FX:{b05566ad-fe9c-4363-be05-7a4cbb7cb510}

Try the following:

  • Fix any syntax errors in machine.config. Restore to a previously known working copy.
  • Rename EventVwr.exe.config in %WINDIR%\System32.

posted in Dotnet/.NET - C#, Programming | 1 Comment

  • Calendar

  • February 2017
    M T W T F S S
    « Dec    
     12345
    6789101112
    13141516171819
    20212223242526
    2728