Wed, 9 May 2007

Extracting Scripts from Javascript pages using Javascript

— SjG @ 1:56 pm

Here’s a weird one. There was the need to extract the contents of all Javascript <script> … </script> tags from an html page, using Javascript in an Ajax-y environment*. I tried using a similar regular expression to the one published by Matt Mecham, but found that IE threw an error. IE didn’t like the [^] construct.

So, since I knew that the pages that this would need to process would be standard strings with nothing odd in them, I substituted [^\0]. Works in Firefox and IE. I don’t know if it breaks under different encodings, though.

The other problems was conceptual — I didn’t remember that regex.exec() only gives you the first match in the resultant array (but gives you your submatches); I confused it with the behavior of string.match() which doesn’t give you your submatches. *sigh*

So the code looks like this:

var reg = new RegExp("<script[^>]*>([^\\0]*?)<\\/script>","ig");
while( (m2 = reg.exec(http.responseText))  != null )
        for( i = 1; i < m2.length; i++ )
           alert(i + '('+m2[i].length+')' + m2[i]);
           // do other stuff

(Please note that WordPress seems insistent on munging that code. Spacing, in particular, might be corrupted.)

(* note that use of the passive voice. To protect the innocent, we won’t say who/why it was needed.)

Thu, 3 May 2007

McCarthy’s Bar

— SjG @ 8:16 pm

McCarthy’s Bar, Pete McCarthy, 2000, Hodder and Stoughton.

Like Red Haired Girl from the Bog, McCarthy’s Bar starts with an author of Irish descent undertaking a search for identity in Ireland. McCarthy, however, has a much more down-to-earth approach, which begins with the rule that you should never pass up a bar with your name on it (sage advice for someone traveling in Ireland with the name of McCarthy, no doubt, but for us Goldsteins it should be understood that we might have to assume an alias to avoid serious sobriety and/or dehydration).

McCarthy’s writing is reminiscent of Bill Bryson — self-deprecating, incisive, descriptive, and howlingly funny in places. The humor shouldn’t suggest that he’s not very serious about his quest, nor does it soften the keen edge to his observations.

Monaghan’s writing makes it seem that she was relatively comfortable in accepting the mantle of identity. She is in many ways more distant from her heritage, and is able to project certain things on them (being poets and sennachie). McCarthy dwells more, perhaps, on what identity means to him. He meets more relatives on his trail, is accepted as a relative to people who may or may not be blood relations, and ruminates on non-Irish who are working at becoming Irish.

Of the two books, McCarthy’s Bar is probably a better travelogue. Reading it meshed more closely with our experiences, and sometimes this added to the humor (e.g., the derelict Titanic themed bar we passed in Cobh, which he describes as being planned but observes that the local predictions for it are not promising).

Filed in:

The Red Haired Girl from the Bog

— SjG @ 7:49 pm

The Red-Haired Girl from the Bog: The Landscape of Celtic Myth and Spirit,
Patricia Monaghan, 2004, New World Library.

I recently returned from three weeks traveling through Ireland with The Right Reverend Oakes. It was something of a whirlwind tour; we visited a lot of different places both on and off of the standard tourist track. Along the way, I finished up reading The Red-Haired Girl from the Bog, which is an interesting blend of Irish history, Irish mythology, and philosophy, along with a fair amount of rumination on the meaning of place, thoughts on personal relations, and observations on poetry, all wrapped loosely in a collection of personal anecdotes structured by regions in Ireland.

The book is not really a travelogue, per se, as it’s more concerned with mythology as it pertains to place, but it does provide counterpoint and commentary to someone traveling through the places described.

Monaghan starts the book with a not-very-mystical quest involving identity — what does Ireland tell a person about herself as a member of the Irish diaspora. It quickly goes beyond that, and shows the complex intertwining of the mythological layers in Ireland, from Pagan to early-Christian to Roman Catholic to neo-pagan. Monaghan also talks about how those beliefs may mesh and coexist in a way that is fairly alien to us Americans. The bulk of the book uses personal experiences as segues into mythology, and vice versa, in a very readable way.

Monaghan is clearly extremely well read, which allows her to bring together a broad perspective on topics, but also results in an overuse of descriptions of the form “what writer X has called ‘Y‘.” I appreciate the need for attribution, but personally find footnotes less disruptive. As someone who is at best marginally familiar with Celtic, Irish, and Christian mythology (or history, for that matter), I also found the flurry of names and references somewhat dizzying. Fortunately, if you’re as undisciplined as I, you can let the references wash over you without needing to absorb them all — Monaghan’s overall narrative is good enough that you don’t need all the specifics.

Filed in:

Wed, 2 May 2007

More Avian Dogfights

— SjG @ 8:37 pm

So today, on my walk home from work, I was almost knocked off the sidewalk by a frantically swerving, low-flying crow. It was flying erratically, fast, and croaking in a tone I haven’t heard before.

Why the corvid distress? It was trying to lose a humming bird, which was tight on its tail, and bombing in like a bird on a mission (I suspect it must have seen the crow too close to a nest or something). The hummer was probably no larger than the crow’s head, but it sure had the larger bird on the run. They did some crazy swerving over the road, between some trees, and vanished among the houses across the street.

Then, upon coming home, I saw a similar scene re-enacted in the back yard. This time, the pursuer was a mocking bird.

It’s impressive just how fast and agile they are. As Elizabeth phrased it, they were “hellbent for feather.”

Filed in: