Arcane Thoughts: Tidbits from the web

I’m headed out on a road trip, so this will most likely be the only post this week. Just wanted to hit a few interesting tidbits I’ve found on the web this week.

If you haven’t been keeping up with .Net Rocks lately, you should (see the Arcane Links page). The last few shows have been some really good interviews with lots of super geeky, in depth technical content. The Kate Gregory show was really great (“It’s the speed of light. We’re screwed.”) The MLB show was really good on WCF and card space.

Want to see something disturbing? Thanks to Carl Franklin, I may never look at another chicken mcnugget again. http://www.alnyethelawyerguy.com/al_nye_the_lawyer_guy/2007/03/so_what_really_.html

There’s an interesting list of top 10 lists on Coding Horror. http://www.codinghorror.com/blog/archives/000822.html

One of my posts got quoted on the CBS blog report. http://www.cbsnews.com/stories/2007/03/19/blogophile/main2586598.shtml

And finally, someone I know just started her blog, go check it out: http://robin-newhorizons-bhm.blogspot.com

Have a good week!

Arcane

SSIS and the Metadata Out of Sync Error

Worked late tonight on a problem we’ve been having with our SSIS (SQL Server Integration Services) package. It would run, but give us a weird error about the metadata being out of sync.

It turned out to be a self inflicted error. In the SQL that drove this particular package, the statement ended with …table1.field3, nvl(table2.field4, ‘Missing’) from table1…. Turns out SSIS didn’t like the nvl part. (nvl by the way is an Oracle statement that equates to if field4 is null, return ‘Missing’, otherwise return field4.) Oh, it understood the nvl command OK, but it didn’t like the fact we failed to alias the command in the SQL.

When I updated the SQL to read nvl(table2.field4, ‘Missing’) as field4 from…, AND I did a build on the package, SSIS was happy. Note though that it kept reporting the problem until I did another build on the package, it drove me nuts for a bit until I thought to rebuild the thing.

To sum it up, never leave just an expression in your SQL, always alias it or you too could fall victim to the mysterious Metadata out of Sync Error.

Arcane Thoughts: Has Microsoft become Big Blue?

Back in the early 80’s when Microsoft first came on the marketplace, it was IBM who dominated. They had the OS, they had the computers. While they dominated the business environment, they weren’t seen as very responsive to the home consumer. (Anyone remember the IBM PCjr?)

Enter Microsoft, who came out with slick applications designed for “the little guy”. They were quick to market, had cool offerings that worked, and were reasonably priced. Oh how times have changed.

Much like IBM in the 80’s, today Microsoft is a dominate player in the enterprise marketplace. They own the desktop market, have a enterprise ready database in SQL Server 2005, their Great Plains accounting and CRM software are major players in their fields. And don’t get me started on their awesome development tools.

But when it comes to the home market they seem to keep missing the boat, with I admit the notable exception of the XBox. For example, their One Care virus software failed miserable in head to head tests with other antivirus software (http://www.pcworld.com/article/id,129722-page,1-c,viruses/article.html). And while they claim high numbers, I hear little in the blogosphere about the new Windows Live website. And then there’s Zune.

Clearly Microsoft needs a change. Either change the model, as IBM did to focus on the business areas they are so good at, or get some new leadership to recapture the lead in the consumer arena.

But hey, that’s just my Arcane thinking, I could be wrong. Leave your opinion…

Encoding Strings to Base64 in C#

I recently had the need to convert simple strings back and forth from Base64 encoding. It turned out to be relatively simple in .Net, once you figured out which class libraries you needed to combine.

It turns out the System.Convert has two handy methods for dealing with Base64, ToBase64String and FromBase64String. On the ToBase64String, we have a bit of a challenge, since it expects a byte array and not a string to be passed in.

It does make a certain amount of sense, typically you aren’t encoding a simple string but instead a binary object such as a file, which is usually represented as an array of bytes. For us, this means we have to take our string and convert it to a byte array.

You’d think the string class would have a nice static method to handle this, but alas it does not. Instead we have to turn to System.Text. I imagine most of you are working with ASCII encoding, so here we’ll call on the ASCIIEncoding.ASCIII class, and use it’s GetBytes to convert a string to bytes.

The small method below combines the two methods I’ve described to create a Base64 encoded string from a normal string.

    static public string EncodeTo64(string toEncode)

    {

      byte[] toEncodeAsBytes

            = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);

      string returnValue

            = System.Convert.ToBase64String(toEncodeAsBytes);

      return returnValue;

    }

 

Note two things, first I am using ASCII encoding, which should cover most folks. Just in case though, System.Text has encodings for the various flavors of UTF as well as Unicode. Just choose the appropriate encoding method for your need.

Second, I made the class static because I was using a console app for my test harness. While it could be static in your class, there’s no reason it has to be. Your choice.

OK, we’ve got the string encoded, at some point we’re going to want to decode it. We essentially do the reverse of encoding, we call the FromBase64String and pass in our encoded string, which returns a byte array. We then call the AsciiEncoding GetString to convert our byte array to a string. Here’s a small method to Decode your Base64 strings.

    static public string DecodeFrom64(string encodedData)

    {

      byte[] encodedDataAsBytes

          = System.Convert.FromBase64String(encodedData);

      string returnValue =

         System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);

      return returnValue;

    }

 

Finally, here’s a simple test harness, done in a console app, to show you calls to the two methods.

 

      string myData = “Here is a string to encode.”;

 

      string myDataEncoded = EncodeTo64(myData);

      Console.WriteLine(myDataEncoded);

 

      string myDataUnencoded = DecodeFrom64(myDataEncoded);

      Console.WriteLine(myDataUnencoded);

 

      Console.ReadLine();

 

Be aware, I’ve done no error checking here. My little methods assume that the data you are decoding will properly convert to and from a string. If that’s not the case you could wind up with a serious case of gibberish, if not cause a run time exception. If you are not positive that all you are dealing with is simple strings, then make effort to include some try / catch logic in your implementation.

Arcane Education: Alabama Code Camp IV

Yes, it’s spring time, when the flowers are in bloom, and a young man’s fancy turns to… .NET!

Alabama Code Camp IV is coming up quick, April 14th is just a few short weeks away. For those in the south-east, this one will be held in Mobile AL. See all the details at:

http://www.alabamacodecamp.com/

If this is anything like the previous ones it’ll be great, tons of great speakers and lots of good swag. If you have never been to Mobile before, there’s a lot to see and do. My family is coming along and we’re going to make a weekend of it.

Top on my list (after code camp of course) is seeing the USS Alabama (http://www.ussalabama.com/), a WW II Battleship. At the same location they have the USS Drum, a submarine, a B52, an A-12 Blackbird, and tons of other exhibits.

If battleships aren’t your thing, Mobile is loaded with opportunities, check out Yahoo’s top 16 list at http://travel.yahoo.com/p-travelguide-2833565-mobile_things_to_do-i,  or the Mobile city guide on AL.com (http://www.al.com/mobile/cityguide/index.ssf?attractions.html).

And for the beach goers, Orange Beach is right next door to Mobile (literally). Check out the fun in the Gulf of Mexico at http://www.gulfshores.com/things-to-do/attractions/.

So there you go, a whole day of geeky fun for you, and plenty of ways for the family to be out spending your money, oops I mean having fun while you are getting an education. Well, at least Code Camp is free!

So quit sitting on your duff and start making plans today!

Arcane Thoughts: Ze Frank’s Web

Ze Frank has had me thinking about the role of creativity on the web. A lot. There’s a great deal of talk about Web 1.0 versus Web 2.0. Certainly there are some compelling new technologies that some might consider falling into the 2.0 field, such as AJAX.

I don’t think Web 2.0 can be defined by technology though. I think it’s more about the way people use the web. Web 1.0 became strongly driven by business. Sure, individuals had pages, but it was business who dominated Web 1.0.

With 2.0, it seems the individual has moved to the forefront. Blogs, podcasts, videocasts, twitter, all examples of the individual extending his or her creativity to the web. Not only does it give a place to host, but to communicate. An artist can get immediate feedback and interaction with their audience. A global, world wide audience.

In the interest of extending my own creative streak, I’m branching out, trying some of the new services. I’ve setup new twitter and tumblog accounts. Twitter, well I’m not sure why, to be honest I’m not 100% sold on the usefulness, but what the heck.

My tumblog will host my pictures. I’ve had a long interest in digital photography, and I’ll put some of my favorites here for you to enjoy.

http://twitter.com/arcanecode

http://arcanecode.tumblr.com/

Don’t worry, I’ll still be posting .Net magic here, but everyone has to find ways to be awesome. How about you?

So long Ze… You’ll be missed.

About six months ago I discovered The Show, with Ze Frank (http://www.zefrank.com/theshow). Each day Ze Frank puts on a video podcast that is humorous, entertaining, enraging, thought provoking, but above all, inspirational.

The running theme of the show, started one year ago today, was that Ze wanted to join something called “The League of Awesomeness”, a society out to make the world a more awesome place. His initiation into the league was to do a video podcast for one year, hence The Show.

The real point though, was not simply to do a video each day, but to engage in a conversation with the viewers, and to inspire them to debate, discuss, and create. The forums are populated with his fans, known as “sports racers”. Fans contribute greetings, graphics, songs, and more to make the show a true collaboration, with Ze at the helm.

Today, March 16, 2007 is the last episode of The Show. It comes to an end as Ze Frank fulfills his internship to the league. The real gift Ze has given over the last year is not videos, but inspiration. Through his encouragement to “be awesome” he has inspired countless sports racers to create their own content and share it with the web.

Now that Ze Frank has graduated to full league membership, I am hopeful the gift he gave, that of encouraging people to create and contribute, continues. I challenge everyone, go out and create something. Videos, songs, poetry, art, even a simple blog like this one, go create and share with the rest of the world. Unleash your potential to be awesome.

So long Ze, and welcome to the League of Awesomeness.

It couldn’t be more deserved.

Follow

Get every new post delivered to your Inbox.

Join 106 other followers