Scott Hanselman

Coding4Fun is LIVE! - A new syndicated MSDN Column

April 18, '05 Comments [13] Posted in Coding4Fun | XML | Gaming
Sponsored By

I can finally tell my little secret. I'm a part of the new Coding4Fun site that was launched as a part of Beta2 today.

Coding4Fun is a new .NET 2.0-focused hobbyist site with a number of great syndicated columns including ones on creating games, web development, XML and my new column on interfacing with hardware called Some Assembly Required. (It's a triple play on words if you think for a sec)

My first article is on interfacing a CrystalFontz USB LCD Display to Windows Media Player or iTunes using .NET 2.0.

There's a lot of great code up there now, and lots more coming. I'm pretty impressed with the 'Express' SKUs for Visual Studio, and I hope they will inspire more hobbyist developers to jump in and enjoy.

Updated: Here's an RSS Feed.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Converting from a String Representation of a Unicode Character back into a char

April 18, '05 Comments [4] Posted in Internationalization
Sponsored By

Hopefully Michael Kaplan will step in here and explain some edge case or just a general comment like "that's totally wrong, Scott" - but until he does:

A fellow emailed me this question:

I want to convert a string representation of a Unicode character back into a 'char' in .NET C#.  Can you help?
 
i.e."U+0041" which is Hexidecimal for 65 which is ASCII for "A"
 
There's got to be a built in function(s) for this, and I just can't seem to find them?
 
To give you an idea, the pseudocode would be something like:
 
string s = "U+0041";
char c = new ?Unicode.Decoder.Decode?(s);
textBox1.Text = c.ToString();

Now, I have no idea why this gentleman would want to do this, but it's interesting enough. Here's what I came up with. I'm sure there's a better way.

//Just a reminder that you can use \u to escape Unicode in C#
char c = '\u0063';
Console.WriteLine(c.ToString());

//Here's how you'd go from a string to stuff like
// U+0053 U+0063 U+006f
string scott = "Scott and the letter c";
foreach(char s in scott)
{
	Console.Write("U+{0:x4} ",(int)s);
}
		
//Here's how converted a string (assuming it starts with U+)
// containing the representation of a char
// back to a char
// Is there a built in, or cleaner way? Would this work in Chinese?
string maybeC = "U+0063";
int p = int.Parse(maybeC.Substring(2), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine((char)p);

Now playing: Craig Armstrong - Ray's Theme

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Date.ParseExact and the subtle goo that is DateTime Format Strings

April 15, '05 Comments [5] Posted in Internationalization
Sponsored By

We recently needed to parse this evil. 

string poop = "2005-12-14T14:35:32.1700000-07:00";
DateTime poo = DateTime.ParseExact(poop,"yyyy-MM-ddTHH:mm:ss.fffffffzzz", System.Globalization.CultureInfo.InvariantCulture);

Important Notes:

  • HH means 24 hour time, hh means 12 hour time.
    • Don't do all your testing in the morning of a one digit month on a one digit day. 11:59pm on New Years Eve is an important test case.
    • If I'd have tested with 01:01:01 then using lower case h's would have worked, but would have broken this afternoon.
  • zzz means TimeZone offset like -07:00
  • When doing a ParseExact and then round-tripping with a ToString using the same format string will NOT result in the same string.
    • That means that:
      DateTime foo = DateTime.ParseExact(poo,"yyyy-MM-ddTHH:mm:ss.fffffffzzz", System.Globalization.CultureInfo.InvariantCulture);
      foo.ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz") == "2005-12-14T13:35:32.1700000-08:00"
      However, the semantics of the DateTime is the same.
  • fffffff means 7 digits of fractional seconds
  • T (in this context) has no specific meaning (it’s not reserved) so it is treated as a literal.
  • System.Globalization.CultureInfo.InvariantCulture is almost always necessary when you’re working in a non-UI context.
    • Don't get screwed when your application doesn't work when installed on an international version of Windows. 

 

 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

TechEd Video #4 - It's all about Community. And Ice Cream. And Baby Carrots.

April 13, '05 Comments [10] Posted in ASP.NET | TechEd | Web Services | Javascript | Speaking
Sponsored By

In the fourth and final installment of our "Those are some really weird TechEd Videos Collection (coming soon in DVD, not)" Rory and I learn the meaning of community as we sleep through the TechEd Keynote Address.

Please spread it around and Trackback/Pingback it. If you can't view it below, you can download it here.

Remember, if you're blogging TechEd this year, make sure to register your blog at TechEd Bloggers.NET and get your content aggregated!


play video stop video indicatorhandleamount downloaded toggle sound launch in external player
Launch the streaming media file

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

TopDesk: Expose Clone for Windows (and capturing video from DirectX)

April 12, '05 Comments [32] Posted in Bugs
Sponsored By

An animated GIF of TopDesk in action.Finally, my search for a decent Windows Task Switcher is over. Sure, there's TaskSwitchXP, which kicks the Windows Power Toy Task Switcher's booty.

But, no, I'm not talking about an Alt-Tab replacement. I'm talking about the pure sex that is Mac OS X Expose, but on Windows, and written in DirectX. It's TopDesk, and it's the bomb. And it's US$9.95? Sold. He sure ain't doing it for the money.

It has been around a bit, but it used OpenGL and it was pretty buggy. The author recently rewrote the whole thing in DirectX, adding a bunch of new features, including floating buttons for TabletPC support and corner hotspots.

Oh, and it supports multi-monitor, too? Awesome.

I set it up with the very corners of my monitors as "hotspots" to start the taskswitcher. Since I'm a developer, I also changed the default hotkey from the Mac default of F9 to a more reasonable Alt-F9.

Here's a Windows Media 9 encoded video of it in action on my machine. I used Fraps (another awesome util) to do the DirectX capture to AVI, FYI. Then I used RiverPast Video Cleaner to make an Animated GIF from that AVI. Then I used GifWorks.com's Online Animated GIF Editor to make it loop.

I sure love utils.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.