Thursday, 20 May 2010

Fixing annoying Australia-centric google results: &gl=

Google seems to prefer giving me Australian results to some of my searches. This is often useful, but sometimes it's annoying.

It looks like adding "&gl=" to the request disables this feature.

Judging by my quick experiments (see below) it's using gl=au by default.

 australian results world results australian results (same as australian results above) uk results

The following searches, however, seemed to have only minor variations, with no obvious country biases:

The effects of the GL parameter seem to be different from using the

* The web
* Pages from Australia

options sometimes available on the left of a google search.

Also note, something I've done (I suspect clicking on the "The web" link) has changed the results I'm now getting for the GL-less seaches.

Oh, I found out about the parameter from

Thursday, 6 May 2010

finding <? that aren't <?php

I'm using this pattern (in vim) to find "<?" that aren't "<?php":


it uses zero-width look behind for the "<?" and zero width negative look ahead for the "php".

And using grep (in perl mode):

grep -P "\<\?(?!php)" -r .

Test cases:

YES <?
NO <?php
YES <?=
YES <? asdf
YES <?adsf
NO asdg

And a quick shell script for fixing a file (I say "quick" because it doesn't always work - e.g. if you have "<?/* comment */?>" it doesn't put in the extra whitespace you need after the "<?php"):

sed 's/<?=/MAGICaaxo3ohW/' | sed 's/<?php/<?/g' | sed 's/<?/<?php/g' | sed 's/MAGICaaxo3ohW/<?php echo/'