" /> Primordial Ooze: November 2003 Archives

Main | December 2003 »

November 27, 2003

Image Loading Goodness

Happy Thanksgiving!

I took a crack at two things this morning. First, I took some old C# code I wrote that traverses a directory structure and gets information on each file. Second, I use the System.Drawing library to get image information. Finally, I output all of the results.

The directory traversal turns out to be trivial. I implemented this as a simple recursive function as follows:

==


static int traverseFiles(FileAction action, DirectoryInfo dir)
{
int numFiles = 0;

FileInfo[] files = dir.GetFiles();
foreach (FileInfo f in files)
{
if (action.doAction(f))
{
numFiles++;
}
}

DirectoryInfo[] subdirs = dir.GetDirectories();
foreach (DirectoryInfo d in subdirs)
{
numFiles += traverseFiles(action, d);
}

return numFiles;
}


==

The FileAction argument is my simplistic shot at making the loop generic. My default implementation tries to load the file into a Bitmap() object. If this fails with a throw of System.ArgumentException, doAction() returns false. Here is the implementation of doAction().

==

public bool doAction(FileInfo file)
{
ImageInfo image = new ImageInfo();
try
{
image.Load(file.FullName);
Console.WriteLine(file.FullName + " " + image.Width + "x" + image.Height);
image.Unload();
return true;
}
catch (System.ArgumentException)
{
return false;
}
}

==

The ImageInfo class was lifted from AspHeute (AspToday, a German site I think). Thanks Christoph Wille. There is one error in their example, where the Width() wrapper returns the internal Bitmap() Height property.

The code for the sample I, uncreatively, named FindFiles.cs is available for your compiling pleasure.

Compiling can be done at the command prompt as follows:

==


csc FindFiles.cs
==


November 25, 2003

EditCSS, what a timesaver

My last entry saw about 50 revisions as I desperately figured out how to beautify my source code snippets. I enumerate the packages I used in my earlier post.

My problem was basically a malformed comment in my CSS file. Bummer. I found this out by using a great plugin for Mozilla Firebird called EditCSS.

EditCSS allowed me to override and modify the CSS for any page, in realtime. Every character I typed into the EditCSS side-bar caused the page to re-render. Once I removed the comment, the page immediately rendered properly. Wow, cool stuff.

Using EditCSS proved a more efficient edit-save-try workflow when compared with the normal way I would edit a stylesheet via Moveable Type's template editing interface.

November 24, 2003

Code formatting blues

I just installed MTCodeBeautifier by Sean Voisen, which leverages the Beautifier code written by Mike Jewell and which required the MTMacro plugin by Brad Choate. I also installed Brad Choate's MT-Textile plugin, which helped me with eliminated literals from appearing in my code segments. Finally, because I'm a complete geek, I installed John Gruber's SmartyPants plugin which converts regular quotes to smart quotes (among other things).

To get C# code formatter properly, I had to hack the beautifier.pl and download a HFile_csharp.pm from the Twiki project Web site.

Here is a sample formatted for C#. It didn't originally look right in Mozilla Firebird (my default browser), but that's because of a dumb mistake I made with a malformed comment. Argh!

/* * EnumVideoModes */ public class EnumVideoModes { public EnumVideoModes() { s = "Hello"; } } == An anonymous-language block: ==

    int i = 10;
    String message = "hello, World";

November 21, 2003

and sometimes you're wrong... (or, Train Story #1)

Since I'm new to blogging, I kind of played a little tug of war in my mind on whether I should post a description of my train ride home. As you can plainly see, the blogger-half won.

I work in Manhattan (that's New York City) and I commute on the Long Island Rail Road. Long Islanders (that's what we call ourselves) like to use the term L.I.R.R because we like to sound like we have a speech impediment.

I typically take the 5:19 train home. The first thing I noticed when I walked into my car was that it was nearly empty. What's up? When I took a breath, I realized that the car smelled like crap. Literally. It was a bathroom car.

I decided to suck it up since I thought these kinds of smells would go away once the train got going. As I sat there listening to Sarah McLachlan and Matchbox Twenty, I noticed that people continuously walked in, looked confused, then sickened, and would either suck it up like I did or bolt for the next car.

The train got going and I was like, thank God, the smell should go away soon or perhaps I'll just get used to it.

Instead, the smell wafted over me and the rest of my macho trainmates like wave of nausea. The smell must have been angered by everyone's defiance. It just so happens that no one got up since they're all too proud to admit that everyone who bolted for the next car saw something that they didn't.

First Blog

Well, this is my first blog. I suppose I should use this time to enter in a fantastic manifesto about what I plan on doing with this thing but, alas, I'm not that poetic.

I'll be attempting some C# programming, probably using Managed DirectX. I'm new, so perhaps my pains will be documented for other newbies to enjoy.

For some reason, the blog is giving me the opportunity to enter text in an "Extended Entry" section, which is what this is. I have no idea what this means, but since I'm putting text in here, I'm sure I'll found out soon.

http://www.primordia.com