adventures in regular expressions

Given a block of text like the following: BEGIN:VEVENT GEO:48.1667\;-123.1167 TRANSP:TRANSPARENT LOCATION:Dungeness\, Washington DTSTART:20080608T131700Z UID:D56BE4D5-F9A3-4026-B99A-C2D979639220 SUMMARY:High Tide 1.83 meters DTSTAMP:20080617T002129Z END:VEVENT BEGIN:VEVENT GEO:48.1667\;-123.1167 TRANSP:TRANSPARENT LOCATION:Dungeness\, Washington DTSTART:20081012T013000Z UID:373CB6BD-F894-4826-8D04-6683AADFB4C4 SUMMARY:Sunset DTSTAMP:20080617T002129Z END:VEVENT BEGIN:VEVENT GEO:48.1667\;-123.1167 TRANSP:TRANSPARENT LOCATION:Dungeness\, Washington DTSTART:20080125T035500Z UID:1EAC4C71-23B1-456D-9302-1436E407B84E SUMMARY:Moonrise DTSTAMP:20080617T002129Z END:VEVENT BEGIN:VEVENT GEO:48.1667\;-123.1167 TRANSP:TRANSPARENT LOCATION:Dungeness\, Washington DTSTART:20080920T081500Z UID:CF306FB5-480D-433D-9E2C-34569BE0A654 SUMMARY:Low Tide -0.33 meters DTSTAMP:20080617T002129Z END:VEVENT remove all the SUMMARY:Moonrise|Sunrise|High Tide VEVENT mentions, leaving just the low tides.

…#!/usr/bin/perl local $/ = undef; my @low_tides = (); while (<>) { my @header = /(BEGIN:VCALENDAR.*?METHOD:PUBLISH\r?\n)/gs; my @events = /(BEGIN:VEVENT.*?END:VEVENT\r?\n)/gs; my $footer = “END:VCALENDAR\n”; push(@ical, @header); push(@ical, grep { /SUMMARY:Low Tide.*-\d/ } @events); push(@ical, $footer); } # Now @low_tides is an array of strings, each one containing just the # BEGIN:VEVENT through END:VEVENT lines of a single low tide event.

Given a block of text like the following:

BEGIN:VEVENT
GEO:48.1667\;-123.1167
TRANSP:TRANSPARENT
LOCATION:Dungeness\, Washington
DTSTART:20080608T131700Z
UID:D56BE4D5-F9A3-4026-B99A-C2D979639220
SUMMARY:High Tide 1.83 meters
DTSTAMP:20080617T002129Z
END:VEVENT
BEGIN:VEVENT
GEO:48.1667\;-123.1167
TRANSP:TRANSPARENT
LOCATION:Dungeness\, Washington
DTSTART:20081012T013000Z
UID:373CB6BD-F894-4826-8D04-6683AADFB4C4
SUMMARY:Sunset
DTSTAMP:20080617T002129Z
END:VEVENT
BEGIN:VEVENT
GEO:48.1667\;-123.1167
TRANSP:TRANSPARENT
LOCATION:Dungeness\, Washington
DTSTART:20080125T035500Z
UID:1EAC4C71-23B1-456D-9302-1436E407B84E
SUMMARY:Moonrise
DTSTAMP:20080617T002129Z
END:VEVENT
BEGIN:VEVENT
GEO:48.1667\;-123.1167
TRANSP:TRANSPARENT
LOCATION:Dungeness\, Washington
DTSTART:20080920T081500Z
UID:CF306FB5-480D-433D-9E2C-34569BE0A654
SUMMARY:Low Tide -0.33 meters
DTSTAMP:20080617T002129Z
END:VEVENT
remove all the SUMMARY:Moonrise|Sunrise|High Tide VEVENT mentions, leaving just the low tides.

This (?s)BEGIN:VEVENT??.*?END:VEVENT will find just the VEVENT items.

This (?s)BEGIN:VEVENT.*?SUMMARY:Low Tide.*?END:VEVENT gets too much: it grabs everything from the first instance of BEGIN:VEVENT to the END:VEVENT after the Low Tide, no matter how many other events get collected. Looks I need a look-behind: find the END:VEVENT and the Low Tide that came just before it, and then, everything back to the BEGIN:VEVENT.

And ideally, I just pull out the minus tides, especially if I have to go that far (anything that includes a ferry ride needs to be carefully considered).

After a lot of back and forth with a perl guru (I really get tripped up by this stuff), it was clear that I was trying to do much in one pass (better to pull out the events, then extract the ones we want, all with the default delimiter/linebreak turned off). So what I ended up with appears below the fold. I had the regex right (those have always been my bête noire) but I had no idea what to do with what I was getting.

Continue reading “adventures in regular expressions”

phrases I hate

But if they mean a modern embodiment of classic values, as this little boat seems to demonstrate, I can accept it…. Nothing half so worth doing as messing about in boats, and as springs draws out, I feel the call of the water.

“Modern classic” is one of those annoyances I hear and want to ask the speaker what they mean. But if they mean a modern embodiment of classic values, as this little boat seems to demonstrate, I can accept it. Now if they would re-phrase it.

Nothing half so worth doing as messing about in boats, and as springs draws out, I feel the call of the water. But that little beauty wouldn’t be cheap to build, for all its lightweight appearance.

the truth will set you free

It’s by no means clear that emancipation would have happened, as Lincoln seems to have been persuaded to use it as a lever as the war dragged on. He did come to see it as the only honorable and moral thing to do but that took more time to arrive at than the political strength of the move.

…I’m not sure those who deny that the unwillingness to do away with chattel slavery and who refuse to understand that secession was an appallingly bad idea (that would cost uncounted lives (600,000 uniformed men on both sides and who knows how many civilians) and enormous devastation to land and property) are living in the same reality.

I finished reading a great book last night, and this morning, for Read Across America day, we had a local theater company present Minty, from a book about the young Harriet Tubman. florida_2.jpg

It was pretty hard to take in, as raw as I felt after reading the history of the most revised period in American history.

I had just assumed or understood that slavery was at the heart of the rebellion, not realizing how open and honest the people of the time were about it. The code words “state’s rights” are really a modern phenomenon. That phrase was used at the time, yes, but getting a Southerner to admit that slavery was what was meant was by no means difficult. Today, it’s not so easy. But a review of the events of the 1840s through 1861 makes it clear that the irrevocable enshrinement of human bondage into law was the issue, no ifs, ands, or buts.

<via>

Continue reading “the truth will set you free”

I guess I should just turn myself in?

Record Industry Goes After Personal Use — “In legal documents in its federal case against Jeffrey Howell, a Scottsdale, Ariz., man who kept a collection of about 2,000 music recordings on his personal computer, the industry maintains that it is illegal for someone who has legally purchased a CD to transfer that music into his computer.” Which would make Apple and iTunes massive co-conspirators for asking me if I want to import the contents of a music CD every time I insert one.

[update] Welcome, readers from BlogRunner. Consider making a donation to my bail if this all goes badly 😉

Record Industry Goes After Personal Use — “In legal documents in its federal case against Jeffrey Howell, a Scottsdale, Ariz., man who kept a collection of about 2,000 music recordings on his personal computer, the industry maintains that it is illegal for someone who has legally purchased a CD to transfer that music into his computer.” Which would make Apple and iTunes massive co-conspirators for asking me if I want to import the contents of a music CD every time I insert one. But I note the RIAA hasn’t sued them, just us little guys.

[From Record Industry Goes After Personal Use]

Picture 4.jpg

links for 2007-12-15

quote of the day

Why did Mr. Romney not do the obvious thing and include [atheists and freethinkers]? My guess: It would have been reported, and some idiots would have seen it and been offended that this Romney character likes to laud atheists.

Why did Mr. Romney not do the obvious thing and include [atheists and freethinkers]? My guess: It would have been reported, and some idiots would have seen it and been offended that this Romney character likes to laud atheists. And he would have lost the idiot vote.

My feeling is we’ve bowed too far to the idiots. [From Peggy Noonan Admits GOP Is Controlled By Fundies, “Idiots”]

yikes

The post this came from is full of alarming weather-related happenings, but none as awe-inspiring as this:

–Waves as high as 70 feet are reported off the North Oregon coast, and, says KOMO, “the weather buoy off the Columbia Bar become ripped from its tether and is now adrift in the Pacific.”

The post this came from is full of alarming weather-related happenings, but none as awe-inspiring as this:

–Waves as high as 70 feet are reported off the North Oregon coast, and, says KOMO, “the weather buoy off the Columbia Bar become ripped from its tether and is now adrift in the Pacific.” [From Mega Rainstorm All Up in Our Shit]

70 feet?

what the …?

It’s about the atrocious treatment endured by some Fort Lewis soldiers who were escorting the remains of a colleague home to Virginia earlier this month.

Brief background: On the tarmac, an honor guard had been formed by Port of Seattle Police, airport fire and rescue and military personnel as the soldier’s body was placed on the plane.

Generally, these professional curmudgeons are annoying (think: Andy Rooney). But this guy has a real point.

I don’t think things can get more screwed up with airport security.


This isn’t about how investigators were able to smuggle liquid explosives and detonators past TSA screeners earlier this year.

It’s about the atrocious treatment endured by some Fort Lewis soldiers who were escorting the remains of a colleague home to Virginia earlier this month.

Brief background: On the tarmac, an honor guard had been formed by Port of Seattle Police, airport fire and rescue and military personnel as the soldier’s body was placed on the plane.

A police officer then took the escort soldiers up to security.

The TSA screener checked everyone’s ID, including the police officer, and then had the soldiers go through the metal detectors.

Their combat ribbons and medals set off the alarms.

So what does the TSA screener do?

He has the soldiers strip off their uniforms – in front of everyone – down to their tee shirts, pants and socks.

Will someone please tell me what the hell is wrong with these people?

How does some inept, insensitive idiot with the IQ of room temperature even get a TSA job?

That TSA screener should have his ass fired.

And those soldiers deserve at least an apology.

[From Ken Schram: Someone should be fired | KOMO-TV – Seattle, Washington | Ken Schram ]