GZipLib (playing with GZipStream)

I recently needed to un-gzip (gUnzip?) a large amount of files programatically and eventually ended up with the class/library posted below.

With the GZipStream (.NET / dot net), I had seen a lot of examples compressing and decompressing strings in memory, but I needed the straight-forward, simple method of just compressing and inflating/decompressing a file (in the simplest manner).

I made the buffer size modifiable to allow you to customize the amount of RAM needed for the process.

In all of this, I discovered the proper way to name a .gz file is the name of the contents (1 file) plus the extension .gz.

Example: manish.txt becomes manish.txt.gz.

This helps tools like WinZip decipher the contents as that .gz name is used when inflating/decompressing.

With this class, you can compress and decompress with or without the output filenames.

I originally posted the C# (csharp) code here, but it was a bit sloppy, so I zipped the project (with WinZip (ha ha)).

Download the project here.

using System.IO.Compression;

GZipLib Class Diagram Snippet

Here is a tester for the library:

My Desktop

My Desktop

 

Three icons.

Four Desktop pictures:

  1. A Geocaching banner
  2. A Commodore 128 Boot Screen
  3. A Commodore Vic 20 Boot Screen
  4. The cover of my Turbo Pascal book

#showmeyourdesktop

@shanselman

 

 

Issued Patent (7,535,994)!

http://tinyurl.com/T3-Patent-1

orhttp://shrinkster.com/16qc

 

Patent number: 7,535,994

CSharp (C#) String Test

So, in an attempt to extract digits out of a string of variable length, which technique is better?

This was primarily a test of the Enumerable.Range() method, but then turned into a refactoring question.

This, of course assumes Dot Net 3.5 (LINQ) is available:

Code showing two methods and a test method

 

Whirlwind

Channel9 Logo

Hey, I just discovered the Whirlwind series on Channel9.

Check it out!

http://channel9.msdn.com/posts/bruceky/

 

There, you will find videos on C# (CSharp) and Visual Studio.

Task List Tokens

To-Do-ListOne of the coolest features I've found in Visual Studio (currently VS 2008 Standard) is the ability to add custom tokens for the Task List.  In this example, I've added the "WAS" token that is used when I've changed some code and want to test it before actually deleting the old code.  I usually just comment out the old code and go delete it later.  If that deletion is delayed for any reason, when I re-open the code, the tokens in the tasks help me remember what I was doing.  The WAS tag is used for old/unused code that I actually intend on deleting instead of the type of code I keep in comments for reference and documentation.

I set the WAS token at a low priority because it doesn't really matter if I ever delete the
commented-out code.

Task-List picture


So now, its use becomes like the (properly used) "WAS" token in an email subject line when a subject is changed for an email thread.

By the way, make sure you only have one copy of Visual Studio running when you do this as the last update wins.

C++ and LINQ (round 1)

LINQ.jpg

I've never used a straight-edged razor for shaving, although I've seen one in use and I've played with one and sharpened one to the point that I know I don't WANT to use one (for shaving).

I have, indeed, used that thing called a "safety" razor where you screw in a double-sided razor blade into a carriage with a handle.  The contraption exposes only enough of the razor to keep you from total exsanguination but still provides a close shave.  You can always just unscrew the thing and get directly to as much of the razor as you want and, of course, when you change the blade, it's fully exposed.

I once had a really nice electric shaver, but for some reason, I never could get that thing to shave closely enough.  Funny though: once I damaged one of the curcular guards, it would only just draw blood (instead of shaving).

Now, I've become accustomed to shaving with a disposable razor that comes out of a bag of razors.  When the current one gets dull, I toss it and grab a new one . The new ones are REALLY, REALLY sharp for the first couple of shaves.
I can get a bag-full with single-edged blades, double-edged, triple-edged and even the Quattro(R)!

Code, Hines, code!

The big problem with the new C++ is that it looks like a safety-razor-blade "kit", while C# is the new "disposable" and, of course, Assembly being the straight-edged razor.
Yeah, yeah, VB is the electric shaver.

I've been trying to find a good reason to investigate LINQ with C++.
I can make an example of "how", but I'm still working on the "why".

With that said, here is an example in both C# and C++ using a "one-step-up-from-the-bottom" LINQ query.
It takes a Dictionary<string, string> and converts the VALUES in it to a unique list of strings where the length of the string is greater than two.  Listing one is in C# (C Sharp) showing the <quote> Easy </quote> way of doing this.  Listing 2 is the C++ (cpp) method and Listing 3 shows the project settings (Dot Net 3.5 and a reference to System.Core).

 Listing 1 in C-Sharp
Listing 1.

Listing 2 in C-Plus-Plus
Listing 2.

 

Settings
Listing 3.

Killing C++ (dot net)?

C++
There seems to be a suspicious lack of documentation for C++ and the new .NET features like Lambdas and Linq.

I've tried several things that ALMOST work, but there's just one piece of syntax that seems to be missing that would bring final success.

Also, it seems like MS is trying to kill C++.  All podcasts (except for those with Kate Gregory) are talking about C# and VB.NET and ASP.NET only hosts (naturally) C# and VB.NET.
If you REALLY want, you can create some supporting functionality in a library written in C++, but it's only a first-class-once-removed citizen now.

The Ivor Horton Books give so little .NET as compared to standard VC++ (including STL and MFC).

Visual C++ 2005Visual C++ 2008

Am I trippin' here?

 

Impressed by Java

OK.  I've finally seen something in Java that impressed me.  It's the JAR! (Java Archive)

Most folks would know that I'm a Microsoft fan (C++, C#) and have stayed away from Java; mainly because it's more difficult to get things done (in Java) and too hard to leverage legacy code written in C++.  I had always been a static linking guy because it allowed me to deliver ONE THING (just the exe) to the end user or server.  Deleting the app after it has run its lifecycle is pretty easy when there is ONE THING to delete.  Well, I had backed off of that a little when i started doing .NET because everything is dynamically linked -- but the deploy feature still allows the single keystroke to push the THING(s) to the server.

I had never done anthing I considered REAL in Java; meaning I had created a bunch of "proof of concept" apps, but nothing I would trust as a dedicated production app.

This past week (while on vacation), I decided to write a production utility in Java (just for kicks) and one thing led to another (using just the JDK, by the way...):

Class became collection
Collection became  library

I had heard of the JAR and wanted to see what it would take to "not have all of those class files laying around in my science directory".  I found the JAR utility and in a few minutes had figured out how to archive the classes and include the thing in my classpath.  This was still a little "steep", however, especially if I expected someone else to use the JAR.

A little web surfing led me across the command:

java -jar blahblah

When I tried that command with my JAR, it laughed at me saying the Main-Class tag was missing from my manifest.

AHA -- THE MANIFEST!

A little while later, I had that thing humming with ALL of the classes in one JAR; and I could do this without having to further mangle the classpath.

Maybe I'll try another REAL project in Java.

Tom

Mixed Lang Stuff (again)

OK, here I go again on the mixed language stuff.

I continue to be impressed by the capabilities of DOT NET.  This time, it's in the realm of salvaging legacy code. 

This included graphic shows a project I've been working on this week where I needed to leverage a lot of legacy MFC code.  Originally, I was just going to write this in C# as I do most new projects, but needing to rewrite some of the classes I had previously written (using MFC) in another project made me come to my senses.

If I wrote the new app in C++/CLI, I would not need to rewrite the MFC-flavored classes.  I had already started a couple of classes in C#, however.  There are many things easier done in C#, I'll admit.

What to do? What to do?

Remembering a previous project where I combined MFC, CLI and Web Services, I called upon that same technique to also include the previously coded C# classes.

 

If the project type is C++ (DOT NET), the project will understand all DOT NET namespaces and assemblies as well as C/C++ header files.  It'll even hande the linking.  TOO COOL!

The technique is just to add everything as a project to the "Solution", set the dependencies, the references, the namespaces and the header includes and THAT'S IT!  (...sounds like a lot, but it's not)

The question I have for the DOT NET community is WHY IS THERE NOT MUCH TALK ABOUT C++ anymore?

What Made Me A Programmer?

Vic 20 Boot Screen

This is what did it!

I was standing in K-Mart back in early 1983 waiting for my girlfriend to get off work.  I got tired of waiting in the fire lane, so every night I would hang out in "electronics" until she finished with her store-closing chores.

I walked past this screen and hit the enter key.  It said READY.
I typed the word READY and it came back with a message that stated it was unable to READ "Y". WTF!

I asked the store clerk what it meant to READ "Y" and how you'd use one of these things.  He had no clue, but showed me the book for the Vic-20 and the C-64.  The next night, I not only learned how to READ "Y", but I also had "Welcome to K-Mart" scrolling across the bottom of the C-64 screen.  The NEXT night, I had "Welcome to K-Mart" scrolling in different colored SPRITES across the screen. WOW!  GOTTA HAVE ONE!!!

Being a poor college student, I could only siphon enough money (from what was supposed to be book money) to purchase the Vic-20.  GOT IT!

I got back to the dorm, hooked the thing up to the TV and continued the quest to make that thing now do SOMETHING.
I discovered the Scott Adams Text Adventure Games.

  Within a couple of days, my next-door-dorm-neighbor (Joe Estes) saw it and said,

Joe: "I have one of those". 

Tom: "Oh yeah?  Can you PROGRAM IT?  Can you write a game like THIS?"

Joe: "Yeah, I wrote a text adventure game called 'NUNS' where you have to go kill NUNS, but I'm not finished with it".

There was a sound that erupted in my brain that can be best described as a Hanna-Barbera mix of boings and whistles ending with the coconut noggin knock (kinda like this).

"SHOW ME THE CODE!!!!!!!!!!!!!!!!!!!!!!!!"

Well, I've since learned to enjoy that sound.  It's the sound of discovery! 

...but I usually can only hear it when I'm programming.

 

 

Heroes Happen Here

Heroes Happen Here

 

The free software was worth the effort.
OK, I forgot to mention that I went to the Heroes Happen Here seminar.  I registered for both the IT Pro and the developer track.  Of course, when I registered online, the dev track was full, so I registered for IT pro.  When I got there, some dev track entries opened up, so I was there ALL day.  Worth it? Sorta. 

The free software was worth the effort.  At the time, I was using the Enterprise editon of VC++ 6.0 and the Standard edition of VS 2005 (...paid for it myself).  In the software packet, we received a fully-functional Standard edition of VS2008.

I have upgraded all of my managed projects to 2008 and still have not touched any of the other software (full or trial):

  • Windows Server 2008 32 & 64 bit (1-year Trial)
  • Visual Studio 2008 (using this now)
  • SQL Server 2008 Developer 32 & 64 bit
  • Windows Vista Ultimate
  • Windows Live One Care (Trial)
  • Windows Mobile 6 Developer Resource Kit (Trial)

The keynote was recorded -- I don't particularly mind that, but the sessions were more of a sales job than instruction.  I do wish there had been some seriously geeky sessions with folks building more demo code (there was SOME).

Also, the cute little breakfast/lunch box (with Microsoft logo) was a great addition.  I do wish they had some Microsoft shirts for sale (no smalls or mediums needed)   .

After the seminar, I went to the Kansas City .NET Users Group meeting to round out the day.

 

Holy Mother of PERL!!!

I was listening to "Software Engineering Radio" episode 91 with Kevlin Henney talking about C++.

During that episode he made reference to PERL and the phrase "executable line noise".

I ran a web search to see if that phrase had been used before and found THIS.
http://www.99-bottles-of-beer.net/language-perl-737.html

HOLY MOTHER OF PERL!!!

Any language that ALLOWS you to do THAT, will eventually ENTICE you to do THAT.

And yes, it actually works (I keep Perl installed for just such an emergency (channeling FogHorn LegHorn)).

I don't like Perl.  I DO like Ruby -- it's like Perl with all of the uglies taken out.

 

MFC, IOStream and CLR in the same app

Hmmm... Interesting...
Warning level 4 using Visual Studio 2005.
The CSplit is a library I wrote years ago to split const char* into CStringArray.

Trifecta

My PGP Key

Here is the LINK to my KEY.

 

«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345