Bubba likes burritos [video]

December 27th, 2008

Totally reminds me of my dog, Ripley. She’s a Hoover, too.

PDF page count

December 19th, 2008

I needed to get the page count of a pdf file. Not just one, actually. Thousands. We have a small winforms utility that takes a bunch of pdfs from a directory and bundles them up along with a metadata file and ships them off to a client via FTP. The metadata file has to have the page count of each of the pdf files in the bundle.

I could have paid over $1500 for a .NET plugin for Adobe. Or I could use this inside my loop that processes the files.

string pdfText = File.ReadAllText(file.FullName);

Regex rx1 = new Regex(@"/Type\s*/Page[^s]");

MatchCollection matches = rx1.Matches(pdfText);

loandoc.page_count = matches.Count.ToString();

I thought it might be terribly slow because it’s reading each file, but for our needs, it worked great. Well-worth the savings in money on the plug-in just to get the page counts.

Now if I could just get page counts on Word docs without COM…any tips from the peanut gallery?  =)

XML String into DataSet

December 19th, 2008

A particular query (a stored procedure, actually) I was stuck using returned XML from one of our legacy applications. It wasn’t pretty XML and didn’t work well with XmlDataSource, and XML DOM methods can be tedious. I found myself wishing I just had a DataSet. So I read it in as one.

In order to get the string results of the procedure into an untyped DataSet, I used ReadXml and a StringReader.


DataSet dataset = new DataSet();

dataset.ReadXml(new StringReader(xmlString));

You can grab a sample XML file called books.xml from Microsoft’s website here if you want to play and see how to work with what comes from ReadXml into an untyped, plain DataSet. A word of caution, though — books.xml is a well-formed and structured file and may be easier to work with than is typical of other people’s files.

There are other options, of course, depending on what works best for your application and data. You could read it into an XmlDocument and use XML methods (XPath and such), you could define a strongly typed dataset and read it into that, or you could use XmlDataSource. Play with your data and see what works best for it and your situation. Remember the rule — keep it simple. If it seems like what you’re doing is far more complicated than it needs to be, it probably is.

WOTD: Ennui

December 12th, 2008

Today’s word is brought to you by a Dilbert comic.

Ennui:

1. boredom: the feeling of being bored by something tedious
2. listlessness, boredom; melancholia, depression
3. the French word for boredom

It’s a fancy way of saying that you’re so bored, you might just gouge out your own eyeballs for pure entertainment value.

Unusual Job Interview Questions

December 11th, 2008

This article over on About.com got my attention. It deals with unusual job interview questions. We’re hiring over at my company and I was checking out interview styles and such. I have to tell you, I find the notion of questions like these to be amsuing at best, and offensive at worst. I can’t imagine they’d tell me whether someone was going to be a good developer or team member, but hey, maybe I’m just not creative enough.

So, since I love my job and don’t plan on going anywhere soon, I figured I wouldn’t be given a chance to mess with anyone over these, so I posted my responses instead. Enjoy.

“If you could be any character in fiction, whom would you be?”

Harry Potter, of course. He gets the coolest broomstick.

“If Hollywood made a movie about your life, whom would you like to see play the lead role as you?”

Hands down, it would have to be Seth Green. You don’t get a cooler geek than Seth. We’d have to give him a wig and dress him in drag, but he wouldn’t mind, would he? He probably makes a prettier girl than me, anyway.

“If you had to be shipwrecked on a deserted island, but all your human needs — such as food and water — were taken care of, what two items would you want to have with you?”

A vibrator and a book. A long book. Oh, wait, scratch the book, I need a carton of batteries. Enough batteries and I won’t have time to read, anyway.

“If you were a type of food, what type of food would you be?”

Chocolate. After all, who doesn’t love chocolate? Only the mentally insane don’t like chocolate, folks.

“How do I rate as an interviewer?”

Do you really want me to answer that after you asked me questions like those?

Anyone care to tackle any more of these fun and interesting questions? Share with us in the comments!