Diary of a geek

October 2017
Mon Tue Wed Thu Fri Sat Sun
19 20 21 22
23 24 25 26 27 28 29
30 31          

Andrew Pollock


Other people's blogs


RSS feed

Contact me

JavaScript required

Thursday, 10 November 2005

Distributed code reviews are cool

Thanks Sam for your even more compact (but harder to follow) PHP code to find a specific instance of a given day in the month

I haven't tested your first function rigorously, but it seems to hold up to the second and fourth Thursdays of the month, which is mainly what I'm after.

The second function, which avoids function calls, appears to suffer from a partial off-by-one bug.

[13:33] [code] [permalink]

Finding a specific instance of a given day in the month in PHP

When I took over organising the CLUG meetings, I managed to replace most of myself with a small shell script (I even have the t-shirt).

Now that I'm leaving Canberra, Steve Walsh has kindly taken over the running of the script.

So I've done a bit more work on the script, and added a public front end to it, and made an RSS feed (my very first).

So until yesterday, to work out the fourth Thursday of the month, I'd been calling a Perl script that used Date::Manip, when I decided to investigate doing it with PHP natively. Tony gave me some initial code, but I ended up with this:

function nth_day($instance, $dow, $month, $year)
$first_dom = date("w", mktime(0, 0, 0, $month, 1, $year));
    if (
$first_dom <= $dow) {
$first_instance = date("j", mktime(0, 0, 0, $month, 1 + ($dow - $first_dom), $year));
    } else {
$first_instance = date("j", mktime(0, 0, 0, $month, 8 - ($first_dom - $dow), $year));

$instance_we_want = $first_instance + (($instance-1) * 7);

$date = date("j", mktime(0, 0, 0, $month, $instance_we_want, $year));


[02:05] [code] [permalink]

Sunday, 06 November 2005

Obfuscating email addresses with JavaScript

So I got pet peeved by Carlos Laviola in relation to by recent pondering about how MacOS X's SSH agent starts up on login.

Perfectly reasonable grounds for complaint. I have had people contact me in relation to blog posts in the past, so it's obviously not impossible. People know I'm a Debian developer and can put two and two together and wind up at db.debian.org.

Anyway, I'm the first to admit that my blog probably has too many of the Weblog Usability Top Ten Design Mistakes (something for me to work on). To date, I've been avoiding plastering my email address on my website because I didn't want to get it harvested. I try and use a per-list email address for this reason as well, and I haven't enabled blog comments because of comment spam, and because I haven't been clever enough to implement comments with Blosxom full stop.

So I started getting an idea for reversibly encrypting my email address on my blog after reading about Hashcash for Wordpress the other day.

I first started playing around with the Vernam cipher in High School, when I wanted to easily reversibly obfuscate some data for something. I'd read about this cipher in a magazine or something and seen it implemented in Pascal (it's not exactly hard).

So I happened upon the idea of encrypting my email address with the Vernam cipher. Turns out another chap's already got a page for encrypting and decrypting on the fly with JavaScript. It even generates the JavaScript for putting in your own web pages. I had to use a different key to avoid getting dollar signs in the encrypted string, as this confused the tripe out of Blosxom (and me for a while when I tried to figure out what was going wrong).

Then I thought it'd be nice to explain to people who had JavaScript disabled what they might be missing out on, so I fiddled around with some DOM stuff, and had some text get displayed if JavaScript was disabled. When JavaScript is enabled, this text is replaced by the decrypted text.

So of course, like the Wordpress Hashcash, this is largely relying on the inability of spam bots to grok JavaScript. Once they can, this obfuscation technique is all for naught. Meanwhile, you can email me bit more easily now if you get the urge.

View the source of my blog for an example of the implementation.

[03:56] [code] [permalink]

Wednesday, 26 October 2005

Canberra Perl Mongers meeting

The Canberra Perl Users Group is having one of its extremely irregular meetings next week.

If you're in Canberra, or will be on November 2, let me know. The last one wasn't too bad.


[18:06] [code] [permalink]

Sunday, 26 September 2004

Hartley Challenge

Since I've scratched the coding itch, it's only gotten worse. Sarah is taking part in the Hartley Ability Cycle Challenge in November, which is a fundraising activity. I knocked up a webpage for keeping track of how much money they've raised.

It took a bit of lateral thinking to get JpGraph to produce the goods, but it wasn't that difficult in the end. JpGraph is truly awesome stuff. It's just a shame it's got a dodgey dual license that precludes its inclusion (well a more current version) in Debian.

[04:23] [code] [permalink]

Tuesday, 21 September 2004

m4d l33t meeting scheduler

It's been ages since I've set myself a little coding project, but recently when Michael asked if I wanted to take over organising CLUG meetings I immediately saw the potential for yet another automated system.

So I knocked up a very simple PostgreSQL database, a spanky looking PHP front-end (which I should probably apply some access controls to) and wrote a whiz bang Perl script to query the database and send emails (can you tell that I'm a bit chuffed with this thing yet?).

I'm coordinating speakers for the monthly CLUG (fourth Thursday) and CLUG Programmers' Special Interest Group (PSIG) (second Thursday) meetings, and so my funky Perl script checks the database on a Monday to see if there's anyone talking on that Thursday's meeting, and if there isn't, mails the CLUG list asking if anyone would like to talk. On a Tuesday, it announces that week's meeting, with details from the database if there are any.

Noteworthy Perl modules that have to get a mention are Date::Manip, which does so much cool, er well date manipulation, and a new one I found to add to my toolkit, Text::Template.

[00:40] [code] [permalink]