Code Example #5 – WinGrepReplace

In the day to day happenings of web development many of us get into binds and have problems getting out of them. Yesterday a good friend of mine came to me with a huge problem. Her website of more than 700 files needed to have certain entries replaced and the amount of time it would take to go through them all and replace the lines individually was not worth the effort. Thankfully she knows that i dont do anything that difficult by hand, i invent something to do the work for me and give my computer a smack on the butt and just wait for the results.

Here is the Perl code to do just that:

#!/usr/bin/perl -w
################################################################################
# WinGrepReplace
#
# Replace a given line in all files in a directory of files.
################################################################################

use File::Find;
use File::Copy;

die "Usage: $0 directory find [replace]"if (@ARGV > 3 || @ARGV < 2 ||
!-e $ARGV[0] || length $ARGV[1] == 0);

our ($dir, $find, $replace) = @ARGV;

find(&func, $dir);

sub func
{
   return if !stat || -d;

   open(FILE, "<$_");
   open(FILEO, ">$_.new");

   while (($line = ))
   {
       $line =~ s/$find/$replace/i if ($line =~ m/$find/i);
       print FILEO $line;
   }

   close FILE;
   close FILEO;

   move("$_.new", $_);
}

Although there are a couple of hacks and vulnerabilities in this block, it gets the job done nicely.

Welcoming the New Year.

I am about to take my vacation from gneu in order to spend some time with those who care for me deepest. My friends and family have practically promised to assault me if I bring my laptop with me on this vacation so do not expect any significant updates to the site in the next week and a half. That is to say that the mutators are not going to be developed in the coming week so please bear with me as I get acclimated to the other things that matter in life. I will be in the snow tossing about craziness, reading and practicing my guitar. I hope that I will be able to learn another song than silent night.

In other news, I would like report that my fourth mutator has been released and is in your hands. My previous version of the server advertisement mutator is still available, but the specs provided to me were clearly incorrect considering the responses from all of you viewers and commenter’s. I have not had this much attention since right before I was about to release White, and as such I have to thank you all for lightening up my view on the community of game developers. In the mean time, I am going to look into developing the GUI for the new mutator, although I do not know how it is going to work out because generating controls is not as easy as I would like it to be in UT3. Fear not, I am sure I will wrap my mind around it.

In case I don’t get to wish it to you all, I hope you all stay safe and warm, and dry in some circumstances, this holiday. I will be doing what I can to finish my requirements for December, but I don’t think ill have too much difficulty.

Merry Christmas,
Happy New Year,
Happy Hanukkah,
Happy Kwanzaa,
Happy Holidays…

From one atheist to all of you, regardless of your faith.

WAW Post-Mortem

“It is with much regret that I have been watching from a distance as a battle has raged on; I cannot stay quiet any longer. A few days ago one of my friends brought to my attention that there was a lot of discussion going on over in the WAW forums. The team has opted to take a hiatus (meaning break – of course) from the world of HL2 modding, on the grounds that they were not enjoying it. I have no qualms with this idea, and in fact applaud them for having the balls to say such bullshit and expect many of the folks they ran over in their quest for that big fun ballroom in the sky. Seeing as no one provided any sort of post mortem, and even I skimped on the dictation from that period of nearly 6 months that I was working with them, I provide you with my side of the story. I hope It’s not taken too bad, although I really don’t care for feelings at this point.”

– Robert Chatman April 4th, 2007

Continue reading “WAW Post-Mortem”

Dean – Playmate. Red & White

This weekend I finally broke down and picked up my first guitar. I am officially picking up the guitar as my instrument of choice, and hopefully by this time next year I will be comfortable enough to play something and put it up here. I have a modest goal of being able to play jingle bells by Christmas and maybe serenading a special woman for new years; it feels good to be able to say that I kinda play an instrument. It is probably my largest regret from my youth. Too much time spent learning how computers work and too little spent learning an instrument. Saturday things changed.

Continue reading “Dean – Playmate. Red & White”

Disruptive Environments

When it comes to disruptive environments, I have had few experiences like the one I’ve been dealing with for the last year. Its really amazing how anything gets done around this place, as it really seems to emanate irritatingly loud and unconscionable noises our of every corner of its little universe. As one of the people who has brought a guiding light to knowledge work, Joel Spolsky, has said many a time, Programmers need offices.

Let’s get some etiquette down on digipaper before things get too crazy.

Continue reading “Disruptive Environments”

Manufacturation and why HL2 is done.

this morning I had a meeting with Mike Whitfield, Terry Moenkhaus and I met up, originally intending to meet up with the Iron Grip folks and solidify some of our issues and what not. Well that fell through. They signed someone else and so the topic fell on relief of being able to pull together an idea of our own. We talked for quite some time about what we want to do and unfortunately HL2 is not looking like it should be our focus. Most of the issues with building an HL2 mod are rather simple and hard to ignore, but one overwhelming issue is that there isn’t much that hasn’t been done. I likened it to South Park’s episode about how the Simpsons have already done everything, and they both agreed. We can rehash other game ideas but barring some new idea coming out it just doesn’t peak any of our interests.

Continue reading “Manufacturation and why HL2 is done.”