Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Tuesday, May 29, 2012

Javascript regular expressions

Do capturing thus

r = /score=(\d\d)/;
a = r.exec("players=2;score=98;duration=2:09:03");
// a[0] is the whole match (score=98)
// a[1] is capture group 1 (98) like $1 in Perl
// if there are more groups, they are in subsequent array items

w3schools says exec returns the matched text, but I always get an array as described above.

If you define the regexp as global (/g) then you pick up successive matches in the string thusly

while (a = r.exec(string)) { ... }

(the regexp object must I suppose have state so that it can remember how far it's got through string on each iteration.)

The /.../ regexp syntax is part of the JS standard and perfectly respectable. Using it creates a RegExp object, of which exec() is one of the methods.

Monday, May 21, 2012

tar invocation

I find the best way to marshal tar options is to remember that 'f' indicates which tar file you want to use, and putting that as the last option immediately before the filename. So

tar -cvf a.tar

to create and

tar -xvf a.tar

to extract.

And similarly

tar -tf a.tar

to list.

Saturday, May 19, 2012

Perl one-liners

HTML links to BB links

s/<a href="(.*?)">(.*?)<\/a>/\[url=$1\]$2\[\/url\]/g

HTML B and I to BB B and I

s/<([bi])>(.*?)<\/[bi]>/\[$1\]$2\[\/$1\]/g

Wednesday, May 16, 2012

XPath evaluate results

If you use XPathResult.FIRST_ORDERED_NODE_TYPE as the result type with evaluate, you don't get back the same kind of node set that you do with UNORDERED_NODE_SNAPSHOT_TYPE. You don't use snapshotItem etc with it, instead use singleNodeValue to get the one node in the set. I think you get null back if there are no nodes.

Good description here http://www.wrox.com/WileyCDA/Section/id-291861.html

Tuesday, May 15, 2012

Greasemonkey script commands

Suppose you have registered a script command which runs a function in your script. You load a page on which your script is included, and then you can use the menu option to run that function as many times as you like.

But Firefox won't load a fresh copy of your script if you change it in between uses of the menu option, even if you're using one of the ways of editing the script from the browser (eg right-clicking the script name on the Greasemonkey menu).

It seems it only loads the script when you reload the page it's included on.

Greasemonkey script won't run

If your script isn't running at all - so you aren't even seeing an alert or GM_log message you've included -

1. Check that it's included on the page (will appear on the Greasemonkey menu with a tick)
2. Check - in the Error Console with 'All' or 'Errors' selected - that there isn't a Javascript syntax error in it.

I've been caught time and time again by this, having set the console to 'Messages' only and not looking at the Errors.

Thursday, May 10, 2012

Greasemonkey metadata

It seems that in later versions, if you have metadata like
// @name           OWA Lite refresher
// @description
// @include
// @include https://email.dugeenswork.co.uk/owa
the first, blank @include will cause the second one to be ignored, as if the blank one means 'don't include this script anywhere regardless of what I subsequently specify'. Yes I agree you wouldn't deliberately put metadata like that in in the first place.

Thursday, May 3, 2012

Google + operator

Google's stupid decision to start replacing your search terms with ones that produced more hits for their advertisers, and to abolish the + operator and start ignoring quoted terms to stop you evading it, can be evaded by using 'verbatim' mode (aka 'actually search for what I fucking told you in the first place' mode).

The pertinent bit of the URL is &tbs=li:1

eg if you're looking specifically for people who've mixed up Pavel Chekov and Chekhov the playwright

http://www.google.com/search?q=chekov+playwright&tbs=li:1

Even Instant Search was less annoying than this. And at least Instant is client-side and can be easily evaded with Greasemonkey. Google have made the mistake here of ignoring the number one principle of computing, which is that computers should do exactly what they're told, even if it's to start a global thermonuclear war.
Perhaps there's been a backlash - I notice that in certain circumstances + is now working again, eg searching for 'proprietry' gets you 'proprietary', but '+proprietry' actually performs the search you require.

Followers

Blog Archive