30 November 2010

Regex mystery, once more

I spent some quality time with Friedl's Mastering Regular Expressions, and I'm beginning to get a better understanding of JavaScript's NFA regular expression engine. I dimly understand how the case I described in an earlier post sent the engine into backtracking perdition. I tested (but did not commit to the codebase) this version. It addresses the specific bad data case, but I don't think it's a comprehensive solution.



var PROBE_REGEX = /client\.org/;
var URL_REGEX = /^(http:\/\/)?(\w+\.?)*client\.org(.*)$/i;

stripUrlPrefix = function (url) {
var regex = new RegExp(URL_REGEX);
var result = jQuery.trim(url);
if (result.search(PROBE_REGEX) == -1) {
return result;
}
var matches = regex.exec(result);
if (matches) {
return matches[3];
} else {
return result;
}
}



It's one or both of the quantified expressions (\w+\.?)* and (.*) that are responsible for the performance issues.

Bronze metaphor

New research by James Evans suggests that the artisans who built the Antikythera Mechanism suggested epicycles to the Greek astronomers as an explanation of planetary motions, and not the other way around. Jo Merchant reports.

11 November 2010

Friendly is good

Joanne Garlow reports on a just-released increment of software to which I contributed, broad support of semantic URLs at npr.org.

15 October 2010

Might come in handy again

The table amgp_release associates UPC codes (amgp_upc) with album IDs (amgp_a_id). You'd think that this would be a one-to-one relationship, but apparently multiple IDs can share the same UPC code. Question: What are the UPCs that are associated with multiple IDs? Query:



select count(*), amgp_upc
from (select distinct amgp_upc, amgp_a_id from amg.amgp_release) tbl
group by amgp_upc
having count(*) > 1

13 October 2010

'N Sync

At this shop, a developer uses a Windows laptop to shell into a virtualized machine running Linux where the source code is compiled into a web application. Most of us use Eclipse as a development studio. I had set up my Eclipse to edit my working copy of the code base directly on the virtual machine, mounting it as an SMB network drive. But over time, I found that some serious latencies would occur sporadically--Eclipse would take several minutes to open a short file of JavaScript, that sort of hassle. So, after some cajoling from colleague Jared, I followed his lead and moved my setup so that my working copy is on my laptop's hard drive. So now, instead of an edit-build-test-think cycle, I have an edit-rsync-build-test-think cycle, but the edit step is much faster.

But I was faced with a new annoyance. Every rsync or ssh to the VM required me to type my password. (The other way with SMB, I just left a shell window open already logged in to the VM.)

(Hunh. I suppose I could have set up rsync to pull from the VM rather than push from the laptop. Never thought of that.)

Anyway, the team's wiki links to a helpful crib on how to make RSA keys to perform an automatic login with ssh, but my first efforts failed. Colleague Harold provided the missing piece. He checked /var/log/auth.log on the VM and found an error message that indicated the file permissions on my home directory were too open. We did a chmod 755 on my home directory, and I was in!