Archive for February, 2008

Intro to Grep for M$ People

Sunday, February 10th, 2008

In my “free time” I’ve been idly trying to become proficient at the *nix command line. As told by my previous “converting to Linux” article, I’m trying to make the shift over to Ubuntu full-time, but for a Microsoft-head such as myself, the move isn’t exactly instantaneous.

So, in an attempt to log my efforts, I’m going to start posting little pieces of information that learn/figure out. Today we start with a light lesson in grep.

Side-note(s)
While I am trying to make the switch over to Linux, I find it unfair to my clients to be uncomfortable on my laptop while working billable hours. So this particular lesson will consist of Linux commands, but are run via Cygwin under windows. For those who don’t know, Cygwin is an implementation of the Linux command line and tools that run under windows. Read more about it on the Cygwin website or at the wiki.

My example is at the bash command line. If you’re using a different command line, the methodology may change, I don’t really know (insert lack of Linux knowledge here).

Also, grep is an unbelievably powerful tool. Books upon books have been written on it. This is in no way the only use of grep, nor is it a comprehensive account of using grep in this scenario. I’m just laying the groundwork. The internets (sometimes called blagosphere, tubes, whatever you may like) are a wonderful place, do some more research…

Scenario
I’m working on a website where we had to find all files containing the word “Leads” and change it to “Prospects” (clients… they ask for such weird stuff…). In the project directory, there are a bunch of common website files (php, html, css, js, etc…). But this particular project folder is also maintained by Subversion version control. On windows, that means there is a hidden .svn folder in every directory to maintain the changes to that file. This will make sense in a minute.

Technique – Step 1 – Grep
The manual page for grep says to do a simple search through files is something like this:

grep -R "search value" ./

translation: find every file within my directory and its subdirectories containing this search value.

Technique – Step 2 – | [pipe]
There is a rather handy thing called “piping.” It allows you to run more than one command at once, but also run each subsequent command on the previous commands output. Semi-unrelated example:

ls -la | grep .txt

ls -la will give you a directory listing. What this statement then does is say “ok, with the output of the directory listing, give me only lines containing .txt” giving you a list of all text files in a directory.

ls -la | grep .txt | wc -l

this does the same thing, but wc -l (that is a lowercase L) means “word count, lines only” showing you how many text files you have in your directory.

Back to the task at hand: find all files containing the word Leads.

grep -R "Leads" ./

Output:

$ grep -R "Leads" ./
././.svn/text-base/Popup.php.svn-base:    case 'Leads':
./.svn/text-base/Popup.php.svn-base:            require_once("modules/$currentModule/Leads.php");
./.svn/text-base/Popup.php.svn-base:            $focus = new Leads();
./.svn/text-base/README.txt.svn-base:12. 131  - Sorting Name in Leads
./.svn/text-base/README.txt.svn-base:49. 1161406: Assigned ToUser in Leads can be Assigned to User
./.svn/text-base/README.txt.svn-base:16. FORUM:1276 - Converting Leads and assigning to user
./.svn/text-base/README.txt.svn-base:20. FORUM:1559 - Tasks not working in Leads
./.svn/text-base/README.txt.svn-base:31. SF1095038 - Import Leads - No Mapping Fields
.... more of the same ....

That seems pretty useless because this is all information contained in the .svn files. Eventually, the appropriate info will be contained in there, but make the machine do the work. We want all files containing “Leads” that aren’t in a .svn directory. The -v flag is your friend… It means “find things that don’t contain this.” Code:

grep -R "Leads" ./ | grep -v ".svn"

Output

$ grep -R "Leads" ./ | grep -v "svn"
./include/js/general.js:           if(record_id != '' && module[0] == "Leads")
./include/js/general.js:           if(task_recordid != '' && task_module[0] == "Leads" )
./include/language/en_us.lang.php:'LNK_IMPORT_LEADS' => 'Import Leads',
./include/language/en_us.lang.php:'SINGLE_Leads' => 'Lead',
./include/language/en_us.lang.php:'COMBO_LEADS' => 'Leads',
./include/language/en_us.lang.php:'Leads' => 'Prospects',
... more of the same ...

See the en_us files there? That’s all I’m worried about, so I can do another pipe to only view those files:

grep -R "Leads" ./ | grep -v ".svn" | grep "en_us"

Output

$ grep -R "Leads" ./ | grep -v "svn" | grep "en_us"
./modules/Emails/language/en_us.lang.php:'LBL_LEAD_TITLE'=>'Leads',
./modules/HelpDesk/language/en_us.lang.php:'Leads'=>'Lead',
./modules/Home/language/en_us.lang.php:'LBL_LEADS_BY_SOURCE'=>'Leads By Source',
./modules/Home/language/en_us.lang.php:'LBL_LEADS_BY_STATUS'=>'Leads By Status',
./modules/Leads/language/en_us.lang.php:'LBL_IMPORT_LEADS'=>'Import Leads'

My task is complete. I’ve gotten all the translation files that contain the word Leads, and I can either manually edit them, or use the command line to edit them, but that’s another lesson.

Optional Step 3 – >>

I want to make a checklist that I can print and have on my desk while i’m working with these files. There’s a simple way to do this:

grep -R "Leads" ./ | grep -v "svn" | grep "en_us" > /path/to/file.txt

This will take all the output and drop it in the file I specified. If you use one >, it will create the file if it doesn’t exist, and if it does exist, replace all content in that file with the output from our grep. If you use two >>, it will create if it doesn’t exist and it will append the text if it does exist.

I know it’s a sloppy example, but that’s how I achieved my goal, and it was MUCH faster than finding all the translation files in the application and doing it by hand.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tony Hawk: Proving Ground on the Wii doesn’t even deserve a 5.0….

Saturday, February 9th, 2008

Tony Hawk: Proving Ground - Gamespot Review

I CAN NOT believe gamespot was generous enough to give Tony Hawk: Proving Ground a 5.0. This game is virtually unplayable on the Wii. It’s terrible.

I’ve played every major release of Tony Hawk for the Nintendo non-portable consoles (TH on Gameboy/Advance/DS didn’t appeal to me). I basically majored in 1, 2 and 3 in college. None of the games had let me down. I haven’t played the series in a while, but installed THPS2 on my laptop the other day and thought “maybe I should go buy the new one for the Wii”. Big mistake…

THPG: WiiI’m going to blame all the “Wii sucks, it’s not as good as 360 or PS3″ arguments on this game. The game was ported for Neversoft by a company called Page 44 Studios. Sorry Page 44, but you really f**ked up and you deserve all the bad press you can get. Games ported to the Wii usually have some poorly-implemented, gimmicky way of using the Wii controllers and are usually missing features. The tragic combination of these two ideals would be bad enough if it weren’t for the completion of this terrible trifecta: THE GAME HARD-FREEZES REGULARLY. I’ve never seen this on a Nintendo console before. It’s a fault of the game code, not of the surface of the disc. This disc is pristine, taken out of the case, put into the Wii.

First, let’s start with the lesser faults. The bad implementation of the Wii controller. Part of this could be me but I never liked, nor used, the analog stick for Tony Hawk games. I liked on N64 and Gamecube how you had a choice between the two. Doing a manual (a trick where you roll on the ground on your back or front trucks with the other set in the air) is near impossible to do alone because you have to flip the analog stick forwards and backwards (up/down for a rear truck manual, down/up for a front truck manual). That is difficult enough while you’re moving, but Tony Hawk has had the ability to link tricks by doing what’s called a “revert to manual” off a half pipe to link tricks back and forth for huge multipliers. In their infinite wisdom, they made it so you have to hit the Z button, then quickly manual (up/down on the control stick, same hand). So, think about it: you’re in the air, doing 3 or 4 kick tricks, then right before you land you have to do a really awkward combination of index finger/thumb controls. Attempting this is usually rewarded by my skateboarder landing flat on his face.

To do kick tricks, you hold one button and flick your left wrist in some direction. To do grab tricks, you hold a different button and flick your wrist. While in a manual, or while grinding a rail, you flick your wrist to switch to different styles. Imagine looking at someone through their window while they’re playing this game: you’d look like you’re sitting on your couch having a seizure (well, in most cases, without the droooling). Most games (such as the port of Tiger Woods 2007) have the ability to play with the gimmicky-style controls OR to use the “classic controller” or a gamecube controller if you don’t want. This game, thanks again Page 44, does not.

They also stripped out a bunch during the “port process.” According to reviews comparing the PS3/360 version to the Wii/PS2 version, the ps3/360 version has one huge world and renders characters on the fly, while the Wii/PS2 version has separate levels and pre-rendered cut scenes for loading. I can understand that, we all know that the Wii lost the best-hardware-pissing-match by a long shot. But then they start removing random stuff like the replay editor and the skate lounge. Quite a few of the objectives in the full version throughout the game have been removed also. According to reviews, this causes a disconnect in some of the story lines. Why just randomly not port things, Page 44? Seriously?

All of this could be bearable if I could play the game. I might be able to get into the seizure-mode needed to score some points and check out the full storyline. Remember, those out there who had an NES, when, before you put the cartridge in the system, you would blow into the game to “clear the dust out”? Ever see what happened when you didn’t do that? The screen was a terrible pink color and the audio would be a high-pitched beep that didn’t stop till you turned off the system… This is exactly what my Wii did multiple times during my attempts at playing. The first time I was in the middle of watching a video, so I thought it was a coincidence or something. Wanting to play the game, I reset the system, and when that video came back up, I skipped it. Some time later into the game, it did the same exact thing during gameplay. I’ve tried a few times since then, but have always ended up having to shut the power off and losing whatever progress wasn’t saved to that point.

Needless to say, this game is on the bottom of my list. I’d rather play Wario Ware over and over than this. At least that game allows me to decide when I’m finished playing.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

I’ll throw my hat into the ring…

Monday, February 4th, 2008

So, I’m definitely the least political person…

I don’t even think I can write this, but I wanted to express my opinions about one part: I really don’t see why someone’s personal history matters.

Exhibit A:

I don’t understand why this person thinks he has any clout. I’m going to make a video that says Hillary and I were riding a flying moose while doing lines of coke off of a cardboard box of dead puppies. I’m in no way defending Obama, I don’t know who I’m voting for, but people don’t understand that they’re not just ruining a faceless politician’s career, but they’re squashing the lives of a respectable person and most likely his family as well. All that should count for public office is their public record: how they voted on certain topics, who they were influenced by, etc…

To relate this to something I do have more knowledge in, slander/libel in baseball has the same effect. Take David Ortiz of the Boston Red Sox. Someone mentioned in passing that “David Ortiz is so good, he probably took steroids” followed by a chuckle. The next day, there were articles questioning if he was clean, if someone had given him “the clear” etc, etc, etc… With the media these days, you can’t do that, and on the other side of the coin, you have to take everything you hear with a grain of salt. Even though this guy has no proof, no background, no statement, people are set against Obama because of this video, regardless of it’s “truthiness”.

The real focus shouldn’t be if he inhaled, if she “let” her husband cheat on her (I’ve heard people say “how can she lead a country if she can’t control her husband”)… It should be on people focusing on issues that affect everyone. Enter: The Purple Party. Here’s a mentality that I would be able to identify with. Why do you have to fit into a box? If you agree with the war, are you Republican? If you agree with an immediate withdrawal, are you a Democrat? If I like Obama, but I registered 12 years ago as a Republican for other reasons, shouldn’t I be able to cast my vote in the primaries for Obama? I think adding the wrench of a new “party” into the red/blue war would cause discussion bringing more pertinent topics to the forefront.

But I digress…

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

sproif.com is Digg proof thanks to caching by WP Super Cache!