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.













http://www.google.com.au/search?q=university australian results
http://www.google.com.au/search?q=university&gl= world results
http://www.google.com.au/search?q=university&gl=au australian results (same as australian results above)
http://www.google.com.au/search?q=university&gl=uk uk results


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

http://www.google.com.au/search?q=smtp+server+component
http://www.google.com.au/search?q=smtp+server+component&gl=
http://www.google.com.au/search?q=smtp+server+component&gl=au
http://www.google.com.au/search?q=smtp+server+component&gl=uk


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 http://www.searchmasters.co.nz/articles/204/country-bias-in-google-search-results/

Thursday, 6 May 2010

finding <? that aren't <?php

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

\(<?\)\@<=\(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/'