Archive for June, 2007

A follow up to snakes and pomegranates

In my previous post, I was having some issues with a regex substitution in Python:


matchdate = re.compile(r'?P200[0-9]{5}’)
matchdate.sub(’CCYYMMDD’, ‘date’, count = 1)

However, I managed to get this working earlier in this week with a little refactoring (I also recoded the entire function it was enclosed in):


pattdate = re.compile(r'(?P200[0-9]{7})')
fi = file.read()
newdate = pattdate.sub(thedate, fi)

My problem was that while I was compiling the regex properly, I wasn’t matching it correctly. When run the program would produce something similar with my print function:


The old date was CCYYMMDDRR, the new date is date

And that was repeated 10 times for the first 10 bytes of the file. This was simply due to the fact that my `for` statement was incorrect so I was iterating over the first line of the file and processing stopped at the first \n. So I recoded the entire chdate() function to dump the `for` statement and just do an inline replacement a la sed. I also managed to get the output working for the the most part. I had declared `output = file(‘test.com.db’, ‘w’)` for my output file however, I wasn’t using output.write() correctly. I merely changed this to the following:


fi = file.read()
fo = open(sys.argv[1]+'.2', 'w')
print >>fo

Which, by reading, makes a lot more sense than pulling a global variable from somewhere and it functions the same albeit slightly faster from what I’ve seen. I can now do my inline date changes on zone files by merely typing `python chdate.py test.com.db 2007062301` and the script does the rest. Now I’ve got to figure out the most efficient way to walk a directory and gather certain criteria into a list or dictionary for further processing.

Snakes and pomegranates

This week, I’m nearly 300 pages deep in Mark Lutz’s Learning Python, Second Edition and it’s still an easy to read book surprisingly. I know that technical books that I’ve read can be easy to read, or even entertaining, for the first few chapters but once you get into the real “meat” of the subject matter, it tends to dry up. I’ve started chapter 15 today and it’s now getting into the more advanced and concrete everyday use cases you’ll see: modules, module packages. I’m currently using it to rewrite a script I use at work for mass SPF record insertion in DNS zone files. I’ve skipped ahead some in the book to get an understanding of the re (regular expression) module of Python but unfortunately, Lutz doesn’t really spend a whole lot of time on it in this book or Programming Python (his other acclaimed O’Reilly book on Python). It’s really a shame because the module’s syntax is rather complex and can really take some getting used to if all you’re used to using are PCRE-types (Perl Compatible Regular Expressions) and sed. But it’s extremely nice being able to create groups like the following for code re-use:


matchdate = re.compile(r'?P200[0-9]{5}')
matchdate.sub('CCYYMMDD', 'date', count = 1)

Now I can use `date` to match anything from 20010101 to 20091231 which can obviously be very helpful if I’m busy doing inline edits on multiple files that can have multiple dates in them in that syntax. However, my only problem now is the fact that I can read zone files into a list (an array in other languages) and change the date inline but I can’t seem to take those values and write them back into a file. In bash, it’s easy:


sed 's/200[0-9][0-9][0-9][0-9][0-9]/CCYYMMDD/' < file1 > file2

But when I try this with production code, I either end up with an empty file2 or I get an exception raised. Do I need to pickle the files?

Also, I’ve really grown to love pomegranate juice. I buy a bottle of POM(c) about once every two weeks since I use it as a supplement in my orange juice in the morning. I also have this great pomegranate tea that also has hibiscus and pepper in it. Yum!

Reading and work

So, this week begins my third week working from home and I’ve now gotten accustomed to the boringness and blandness of only leaving the house after 7PM EDT. I have my little routine of working and taking a lot more breaks in order to stretch and go outside to see if it’s daylight or not or to do chores around the house. At least now our apartment stays rather clean since I end up having a bit of free time during my work day.

This week also marks me getting a raise at work which is definitely going to help in the long run. While I may not like everything about my job — especially just about everything I have to deal with concerning spam — this bump in pay will help me forget about the horror of filling out the same Yahoo email deferment form 10 times a day. A coworker of mine is also finally helping me, and the rest of my department, embrace automation by getting tools and scripts in place that I’ve been asking to have for months. In the past, the abuse department of my company only had two or three real employees however, now we’ve got almost 10 to replace those same two or three people. While it amazes me that we need 2 to 3 times more people to do the same amount of work, things are getting done more quickly and slightly more efficiently since we do have people working around the clock versus 9AM till around 2AM. With more people working graveyard, it definitely helps us communicate effectively with providers many timezones ahead of us. My coworker and myself are the only two people in the department that want to do things quickly and efficiently versus everyone else who just wants to drag their feet and do everything by hand. We’re writing scripts and form letters so people can easily automate the dull task of emailing people because they’re sending 20,000 emails to Hotmail when they shouldn’t be.

Which brings me to my next point: reading. I’ve been doing a lot of it lately. More online than off and I’m getting tired of staring at my monitor all day, I just want to dive into my books. I’ve put off reading Satan by Jeffrey Burton Russell in favor of Learning Python

Does anyone know of any good plugins/widgets for WordPress for listing what books you’re reading? There’s only two listed at wordpress.org that I’m able to find. One has not been updated since mid 2006 (and according to the author’s site, was never released) and the other is even older than that.

So many new toys…

So my first week of working at home has produced a lot of free time and for me, that means toys! To start off, I bought Custom Robo Arena and Super Princess Peach for the Nintendo DS, Super Paper Mario (totally awesome) and Mario Party 8 for the Nintendo Wii, Forza Motorsport 2 for the Xbox 360, and finally a shiny new Nikon D40x digital SLR! Ok so technically Peach and the camera are for my girlfriend Jessica but I’ll definitely be putting the camera to use for concert photography since we can finally do lowlight reliably.

Custom Robo Arena is extremely awesome. It’s basically a very crappy RPG with “roll your own Gundam” mixed in since you can mostly build your own battle robot and kick some ass. I’m roughly 75% done with the game and if you like robot battle games, you should pick it up for sure. Super Paper Mario is awesome in its own cartoony/kiddy right. I love the fact that they’ve taken the dull 2D aspect of old platform games and added a comical (as in comic art, not the cheesy jokes) 3D platform fun machine. Paper Mario: The Thousand Year Door was pretty fun from what I hear and this builds on that great franchise. Mario Party 8 is just what you expect: lots of fun and entertaining mini-games built on the successful Mario Party platform. Some of the motion controls for the Wii feel a bit tacked on — and very kludgy — at times but they add a new element to the game as well. For you racing fans, Forza 2 is simply amazing. I plowed through the first game on my Xbox and could not wait to get this one, especially since Jessica bought me the Microsoft Wireless Racing Wheel for Christmas! I’ve waited six long months to test out this bad boy properly and let me tell you, it’s pretty freakin’ awesome! I’m only about 15% through the game but this time the learning curve is not as high as the first game.

I also purchased a new Dell 2007FPW widescreen 20.1″ flat screen monitor to compliment my other one just like it. These monitors are amazing and now I have to figure out how to fit 2 17″ LCDs and 2 20.1″ widescreen LCDs on my tiny desk for work. I also got a new XFX Nvidia 7600GT dual-link capable AGP video card and 2GB of Corsair XMS DDR400 for my old computer so I can finally play City of Villains again and rip CDs properly. I can’t wait to hook it all up and use my old PC again, I miss it terribly. But now it’s going to serve as a dedicated gaming/CD ripping station since I can do everything else on my work PC.

All in all, the week was pretty awesome except for the utter boredom of working at home. I’ve ripped a lot of CDs into iTunes and listened to well over half of them already, and I ripped about 70 CDs in two days. I’ll try and post more this week because I spent almost all of last week trying to get acclimated to working at home and getting used to being at home all day.

First week of working at home

Well, today will conclude my first week of working at home and frankly, it’s not a lot different than my office. Now I get to listen to music as loud as I please and I just hooked up my Wii to my widescreen monitor last night for another outlet to keep me entertained. I’ve spent a few hours ripping a whole bunch of CDs into iTunes and I played Super Paper Mario for about 30 minutes on my “lunch break” yesterday.

After all, it’s my first week and I’m still working out things around the house I should do to keep busy and that might just keep the place cleaner as well. I’ve managed to do far more laundry this week and keep the kitchen rather spotless, a feat in this household. But sometimes, I get just as mind-numbingly bored here as I did at the office and unfortunately, I have no one to talk to here. My cats don’t really help in that department!

Overall, it’s been nice to wake up and roll out of bed into the office where I can sit all day and toil away with my luxurious triple monitor set up.