Tuesday, September 30, 2008

XML RFC822 and W3CDTF Validation

I've been tasked to clean up XML pages at work. We streamline the process with a perl script (just like many of our other publishing tools) and then a nice neat XML file is produced.

So, I've been spending my time lately validating XML feeds on FeedValidator.org (very useful validator, bookmark it!). Apparently, some of our date formats were not valid. We weren't following the proper RFC822 format for the "pubDate" tag and W3CDTF format for the "dc:date" tag.

Luckily with localtime and strftime, this process is easy. So, I wrote a new subroutine for our perl module and here we have it!

use POSIX qw(strftime);



sub Now2
{
my $a = shift;

if ($a == 1) {
## returns in RFC822 format:
## e.g. Tue, 30 Sep 2008 12:57:06 -0400
my $now_string = strftime "%a, %e %b %Y %H:%M:%S %z", localtime;
return $now_string;
}
if ($a == 2) {
## returns in W3CDTF format:
## e.g. 2008-09-30T13:00:35-0400
my $now_string = strftime "%Y-%m-%dT%H:%M:%S%z", localtime;
return $now_string;
}
else {
return;
}
}


You basically call the subroutine specifying a "1" or "2" depending on which date format you want it in. So for example to get a W3CDTF date format, call the subroutine like this: Now2(2)

Cheers!

Friday, September 26, 2008

xargs Is a Very Useful Tool

I was recently asked how to remove specific files of a specific extension (.tmp in this case). Well, of course you can find them by doing a find . -type f -name "*.tmp". Easy eh? But how to delete them if they span deep into the directory tree? Well, I suppose you can just append the output of your find command into a text file and then have a script do the rm'ing of the files. But, what if you can do all of that work in one command line?

So, I mentioned xargs and mentioned what it can do and gave a brief example and lo and behold, he saved a good 5 minutes of extra work. Awesome!

Now, to exemplify what I just said:
find . -type f -name "*.tmp" | xargs rm

Just think of all the possibilities now that you have all of this functionality! You can cp, tar, mv, etc. etc.

Enjoy! Cheers!

Tuesday, September 23, 2008

First Android Phone Available October 22

At last, Google/T-mobile have announced a release date of October 22, 2008 for the HTC Dream (aka T-mobile G1) in a press conference today. The phone is priced at $179 with a 2-year contract with T-mobile. I'm curious how much it is without those restrictions...hmmmm...

One major concern for me is the tether-ability; From Ars Technica, "In response to a question about whether the device will be tetherable to a laptop, the company said that the G1 was 'meant to be used as a mobile device, not as a tethered modem.'" Now, I actually love being able to tether my Nokia N810 to my phone just for the accessibility of ssh, email, and the web. Though, I suppose I should be able to get the same functionality via the HTC.

I'm sure another big issue at hand for companies thinking about rolling this device out to they're staff is the support for MS Exchange, which "there is currently no Exchange compatibility". Though, this does not seem to worry any prospective buyers who only want access to their Google Apps as Gmail, Google Maps, etc. will work perfectly fine.

I'm sure the iPhone lovers are curious to compare the similarities and differences that stand out. Right now, it looks like an Amazon (DRM-less) MP3 store and an "Android Market" will compete with the iPhone's iTunes Store and Apple App Store respectively.

I have to admit, I've been anxious about Android ever since rumors flooded the web about a "G-phone", so I'm admitting to being a bit biased. Though, I think that the true test will be when users get their hands on these devices.

Now when does my current cellular contract end... :)

Cheers!

References: T-Mobile, Google finally unveil the first Android phone

Friday, September 19, 2008

Remove ^M Characters in vi

Alright, I've previously blogged this before, but if you can tell from my previous post, I was blogless for a while so, now to fill this new blog with new and old posts.

Anyhow, I'm sure any of you Vi guys & gals out there have run into this wonderful issue of having "^M" appear at the end of each line. This is especially true if you work with *nix and Windows or if your co-workers use Windows.

So, to quickly get rid of this in vi enter the following:
:%s/ctrl+V ctrl+M//g

It will display as: ^M

*Note: Do NOT type in shift+6 shift+m. Remember these are special characters and they need to be entered as so.

That's it! And Bob's your uncle!

Alternatively, you can use sed to make the search/replace. Notice the vi code looks pretty much the same as the sed arguments.

Cheers!

Thursday, September 18, 2008

Lorem Ipsum

So, I usually hosted my own sites in the past, but my leisure time to keep up with hosting issues has become a hindrance. And, well I got a little lazy.
So, the internet was calling me back and I needed to write and now here we are. Also, I figure if/when(?) I get my own site up and running again I can easily just have this blog's RSS feed into it. So everything works out!

Anyhow, this will be my "lorem ipsum" post as my blog looked desolate and lonely. :-)

Cheers!