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 )

Monday, December 23, 2013

Alt-F4 in Win32 Perl::Tk

How to make Alt-F4 work with Perl::Tk under Windows, like it really should by default:

$mw->bind( "<Alt-F4>" => sub { $mw->destroy(); } );

Or of course the sub could call a cleanup method which itself contains the call to destroy.

You don't seem to need the protocol call any more, Alt-F4 will work with just the binding as above.

Wednesday, December 4, 2013

Firestorm

If you want to change the Firestorm cache/chat log directories, NB you have to do this separately for each SL account that uses the application. Until you've done them all, the ones you haven't changed will continue to use the original location.

Wednesday, November 20, 2013

Time::Local

Time::Local's timelocal function is designed to be the reciprocal of localtime - which means it expects the same odd mix of 0- and 1-based numbers in the array you give it.

It departs from localtime conventions only in that it will interpret a year > 999 as a calendar year (it can do this, and still reciprocate localtime, because localtime isn't going to return a number that large in its year element until AD 2900, and the 1970-based seconds totals that time() returns are going to go tits up in 2038 anyway).

Warning: you positively should not attempt to use the localtime convention for years in subtracting 1900 from a 20th century date, because the resulting year < 100 will be interpreted as a year in the 20th or 21st centuries with a rolling century break. So this being 2013, 1940 - 1900 == 40 will be interpreted as 2040, which causes time() to blow up.

Wednesday, November 6, 2013

Perl capture group variables not reset

Perl has a 'feature' which means capture group variables ($1, $2 etc) are not reset if the match fails.

Apparently the only way to force a reset is to do a trivial match, eg "Brian D Foy's shift key is broken" =~ m/Brian D Foy/ .

Monday, September 2, 2013

Change of name by deed poll

Here are the salient facts relating to deed polls that I picked up from my own experience in changing my name in 2013, and from searches, phone calls to the Land Registry and firms of solicitors, leafing through legal textbooks in the library, from a 1971 edition of The Family Lawyer that I picked up for £1, and from page 263 of the excellent John Citizen And The Law by Ronald Rubinstein (pub. 1947).
I'm a programmer not a lawyer - if I was, I'd've charged you £50 for reading this far.

  • Intend to DIY?
    • If you own a house, be aware that the most difficult 'authority' to prove a name change to is the Land Registry. They have strict precautions to stop people stealing title to property, and consequently if you want to register a change of name for free, you'll have to make a journey, in person, with various supporting documents in your old name, to one of their offices. It won't necessarily be the nearest either - it's 100 miles away in my case. The alternative is to pay a conveyancer to handle this paperwork for you, which is likely to cost £100 at least.
    • The best example wording I found was here . You don't have to attach a seal but you must use different wording if you don't. Try replacing 'I have hereunto subscribed my adopted and substituted name of new name in full and also my said former name of old name in full and have affixed my seal' with 'this document has been executed as a Deed', and 'SIGNED SEALED AND DELIVERED' with 'SIGNED as a Deed'. I remind you again with regard to this that I am a programmer not a lawyer.
    • I've been authoritatively told by someone who is a lawyer that you only need one witness, not two as in all the online examples of deed polls. And my deed poll with one witness was readily accepted by everyone I presented it to, including the DVLA.
    • Unless you want to pay for certified copies of your deed poll, you'll have to do multiple versions of the original. Make sure your intended witness is willing to sign your whole stack of copies!
  • Intend to have someone else prepare it?
    • There is no official/public/UK/government deed poll office/service. There are however various commercial firms using names similar to those. I invite you to consider why they might be doing that.
    • Make sure you know what you're getting for your money! You may just be paying for a printed deed poll form which you'll have to fill in, and get witnessed, yourself. If I was going to pay money for a deed poll I'd make sure it included witnessing, and preferably several certified copies. Typically a local firm of solicitors will charge about £100, plus VAT, for those services.
  • A deed poll doesn't put a change of name into effect - your name changes when you start using your new name. The deed is just evidence, for interested parties, that you made the change of name that you're claiming to have made.
  • Deed polls can be 'enrolled' but very few people seem to do this. I've not been able to find what, if any, advantage is gained nowadays by enrolling a deed poll - in the past, apparently the passport service would include your old name on your new passport as well as your new name unless the deed poll had been enrolled. I assume this is no longer the case as no contemporary source mentions it.
    NB a deed poll has to use a certain form of wording to be enrollable. Details are here http://www.justice.gov.uk/courts/rcj-rolls-building/queens-bench/enforcement

Different 'authorities' have wildly different attitudes to checking documentation. Herewith my experience, which may very well differ from yours:
Doctor's surgery
Made a copy of a certified copy of the deed poll
Bank
Made a copy of the original deed poll, and read it very carefully. Declined to check any other documentation as I'd passed their internet/phone codeword procedure. New bank cards arrived after a leisurely interval of 3 weeks. I got a letter from their mortgage division 2 months later confirming that a change had been made - presumably this one!
Optician
Copied new name off certified copy of deed poll
Council (electoral register and council tax)
Made a copy of a certified copy of the deed poll. A week later, I got an electoral register form in the post for me to sign and return. I cautiously included a note to say they'd already seen the deed poll. When I went to vote 2 months later, I noticed my name had been updated on the register.
Dentist
Made change on request, after reading out my address from their system and asking me to confirm. Declined to look at deed poll or any other documents when these were vaguely waved at them
Building society A
Wanted identity papers in new name. Wouldn't take any action until same were produced. Couldn't be arsed in the end, just closed the account.
Building society B
Gave me a form to fill in, and took a copy of a certified copy of the deed poll. Declined to look at any other documentation because my signature on the form matched the one on their system.
DVLC (Driving licence)
Form asked for passport number, old licence and identity card, and original deed poll. As I have a post-war of terror passport with scanned signature, I didn't have to send the actual passport itself. Original deed poll duly returned after a couple of weeks, flat, in the SAE I sent, and new licence came the day after that.
DVLC (Vehicle registration document)
Take note that changing the name on your driving licence and identity card doesn't automatically change the registered keeper's name (if that's you). I had to send the 'change of name' slip from the v.r.d. separately. No fee or documentation is required.
Water board
Made change on request, by phone, after being given account number and address.
Electricity/gas billing company
On phone, asked me to send them a letter requesting the change. Declined offer to enclose certified copy of deed poll. Next bill arrived with my old name on it. In response to my complaint, they claimed they'd never received my letter. 'If anyone wants to believe that, let him do so.'
Subsequent communications from them correctly had new name.
Phone billing company
On phone, asked me to send them a letter requesting the change, and a certified copy of deed poll, and were pretty rude about it too. But then they're like that whatever you ask them. Update: they sent the copy back, when I phoned and demanded that they do so. In retrospect I think they didn't actually need the deed poll, rather that the call centrebot didn't know what to do and made something up on the spot.
Pressure group
Via email, asked me to send them a letter confirming new name and existing address.
Employer
Made a copy of a certified copy of the deed poll.
Inland Revenue/NI/PAYE/etc
Online form - the small print says they may also ask you to send documents. I suspected this meant another copy of the deed poll to send out, but I got email confirmation of the change the next week without any further interaction being needed.
Land Registry (via conveyancer)
Paid firm of solicitors £140 to handle this, the alternative being to take a day off to travel 100 miles to the designated Land Registry office. They wanted something with an address and something with a photo, and my birth certificate - all in my old name - and the deed poll. LR sent a copy of the new entry after 3 weeks, which interestingly didn't record that my name had been changed, rather it replaced the original entry with one using my new name.

Wednesday, August 28, 2013

Clamwin mirror problem

My installation of ClamwinPortable was plagued by the mirror problem, and the only way I could make it work was to download the update files using Firefox.

Then I tried the suggestion about sending them the output of 'freshclam -v' - I found that freshclam wouldn't work because there was no freshclam.conf in the bin directory (where freshclam.exe lives).

So I created a minimal freshclam.conf:

DatabaseMirror database.clamav.net
DNSDatabaseInfo current.cvd.clamav.net
DatabaseDirectory C:\p\ClamWinPortable\Data\db
and freshclam then worked fine from the command line, and also when run from the Internet Update button on Clamwin.

Update: next day, clamwin was again failing to contact any of the mirrors, but freshclam still worked fine from the command line.

Tuesday, July 30, 2013

Perl split

split doesn't return empty string items for trailing delimiters - split(/;/, "a;;;") returns just 1 item, "a".

Similarly in the degenerate case where the string consists entirely of delimiters, no items are returned at all.

Leading delimiters, on the other hand, generate empty items as you'd expect. split(/;/, ";;a") returns 3 items - ("", "", "a").

Tuesday, July 23, 2013

Subquery field qualifiers

With Sybase you could say

insert into t2(f1)
select f1
from t1
where not exists (select * from t2 where t2.f1 = f1)

and have the unqualified f1 in the subquery interpreted as being f1.t1 (the useful interpretation).

SQL Server does not do this, it takes it to be t2.f1 (the useless interpretation).

So always qualify both references to f1 in subqueries like this.

Friday, June 14, 2013

ZX81 numeric printing

I'd read that the ZX81 print routine for floating-point numbers (ie all numbers) was slow, but I didn't realise how slow till I used the very good VB81 emulator to compare a 1-to-100 FOR loop which (a) uses PRINT to print each number, (b) uses a subroutine to calculate the digits and print them as characters, or (c) calls the ROM routine at 0A98 to print numbers between 0 and 9999.

Timings per iteration:
(a) 460 ms
(b) 280 ms
(c) 100 ms

That includes the loop mechanism and various extra BASIC code, but it's interesting to see that the standard number routine is considerably slower than a BASIC subroutine with a lot of division and multiplication, and far slower than the dedicated ROM routine.

Separate handling for integers would have speeded ZX BASIC up no end.

I wish I'd known about the routine at 0A98 at the time, it would have been dead useful for showing scores in machine code games. I only found out about it this week after re-reading Understanding Your ZX81 ROM which I found up in my loft.

Update: The 0A98 routine explains why Electric Pencil's Asteroids game crashed when your score got to 99990. Pity, because otherwise it was the best ZX81 Asteroids implementation by miles.

polipo as a transparent proxy

Successfully used this config file

proxyAddress = "0.0.0.0"
allowedClients = 127.0.0.1, <ip-of-gateway>
maxAge = 0
maxExpiresAge = 0

to set up a transparent proxy on an in-firewall machine to whose port 3183 I'm tunnelling from my PC via <gateway>. The idea being to let me view web stuff from home which I can only view from the in-firewall machine.

Friday, June 7, 2013

pos

Perl pos does, helpfully, return an index 1 greater than the index of the last character in the string if the last match 'left off matching' after the end of the string.

Just to be clear, suppose you have an 11-character string whose last index is, Perl being 0-based, 10. If the last character of the last match in the string is the last character in the string, pos will return 11 after the last match.

Saturday, June 1, 2013

Fixing Firefox

Settings that have to be made to make Firefox work properly

browser.sessionstore.resume_from_crash = false (bug means that session restore always happens, without prompting; this setting turns this off)

dom.ipc.plugins.enabled.npswf32.dll = false (stops plugin-container.exe for Flash. There are other settings if you have Silverlight, Quicktime etc plugins. You may have to create these settings yourself in later versions)

browser.chrome.site_icons and browser.chrome.favicons = false (otherwise wastes time loading site icons)

browser.tabs.animate = false (otherwise get distracting animation when opening tab)

browser.urlbar.trimURLS = false (otherwise http:// protocol bit hidden in location)

layout.spellcheckDefault = 0 (otherwise get distracting red lines in text boxes)

browser.tabs.onTop = false (otherwise tabs appear above URL instead of below)

app.update.enabled = false }
extensions.update.enabled = false } otherwise add-ons update without prompting you

plugins.hide_infobar_for_outdated_plugin (otherwise constant prompts to update Flash etc for minor version changes)

greasemonkey.fileIsGreaseable (otherwise Greasemonkey won't run on local pages)

browser.download.manager.scanWhenDone = false (otherwise FF will, bizarrely, use the Internet Explorer security settings, which generally mean that your downloads get deleted as soon as they complete). You should check this setting before any important download (or use Opera), as I've caught FF setting it back to true more than once. Take note Mozilla, if I wanted to use IE, I'd use IE.

I'm guessing that, unless you want the same thing to happen with your add-on downloads, you should set services.sync.prefs.sync.browser.download.manager.scanWhenDone to false too.

Missing status bar: unfixed bug.

Missing New Tab button: it won't be on the panel of available buttons when you click Customise, it'll be on the tab bar at the far right. Drag it into place from there.

Having to turn off this whole raft of crap every time there's a new version really puts me off upgrading.

Update: most of these settings are preserved across upgrades. However some crucial ones are not:

  • browser.sessionstore.resumefromcrash
  • browser.download.manager.scanWhenDone
  • services.sync.prefs.sync.browser.download.manager.scanWhenDone

Thursday, May 30, 2013

osql

osql will interpret 'go' on a line by itself as a statement separator even if it's inside a block comment. This is a problem if you've commented out part of a script containing go.

Tuesday, May 28, 2013

Vanishing scheduled task

If you create a task, but then can't see it on the list of active tasks, this may be because it hasn't run yet. You can run it with

schtasks /run /tn "name of the task"

If you've forgotten the name, do

schtasks /query

to get a list.

Saturday, May 11, 2013

GoogleUpdate malware

Suppose you want to install some useful Google application like Earth or Chrome, but don't want GoogleUpdate downloading gigabytes of crap behind your back afterwards. Notes toward preventing a GoogleUpdate infestation...
  • Once the app installation has finished and you've tested it, immediately kill off any lingering msiexec.exe and GoogleUpdater.exe threads.
  • Check Scheduled Tasks - there'll be two tasks to run GU, delete them.
  • Check Services - there isn't usually anything Google-related here but it's worth checking.
  • Use msconfig to check Startup - there will be at least one Google-related startup item, disable it. This is important, if you don't, GU will install all the other malware above again next time you reboot.
These steps have been enough for me so far. But you may also want to do a dir google*.exe /s on your Windows installation drive, because in %appdata%\Google and subdirectories, you'll find the GU executables (and other related programs which appear to try and do a Robin Hood-Little John routine to keep GU going if you kill it off).

It seems odd that this sort of warning is necessary for applications openly distributed by a legitimate business company. And also that the installation process doesn't offer a tick box for 'Do NOT install a whole raft of crap, just the application please, I'll update it myself manually as necessary.'

Monday, April 15, 2013

Perl regular expression /m and /s modifiers

All /m does is to make ^ and $ match start and end of line anywhere in the string (rather than match beginning and end of whole string).

You don't have to use /m just because your string contains multiple lines, unless your match has a ^ or $ in it and you expect the match to be looked for on each line.

/s makes . match a newline, which otherwise it won't.

Sunday, March 31, 2013

defined hash

The reason that defined(%hash) is deprecated is apparently that it returns some internal memory-allocation property of the hash, and that this property is true when the hash is undefined in the Perl sense of things (eg having been set to undef).

Just %h is a perfectly good test and returns false if %h has been set to undef or (undef) (which seems to be the same thing).

Furthermore, you can't undefine a hash or array by assigning undef to them:

  • %h = undef results in %h having one key, '', mapped to undef (and also gives an 'odd number of hash elements' warning)
  • @a = undef results in @a having one element, undef
The two correct ways to undefine an array or hash are:
  • undef %h
  • %h = ()

Wednesday, March 27, 2013

Windows start command

You need to start an application with spaces in its path - the answer is obvious right, put quotes round it?

start "C:\program files (x86)(stupid)\appname\app.exe"

Oh no. What start thinks you want there is to start no application at all, in a window with the title C:\program files (x86)(stupid)\appname\app.exe. Something I'm sure hundreds of users need to do every day.

start interprets the first quoted argument as a window title, so the way round this is to use

start "" "C:\program files (x86)(stupid)\appname\app.exe"

Friday, March 8, 2013

Redefining Perl built-ins

Suppose you're writing one of those 'extender' sort of packages that exports subs with nice friendly names. And you want to call one of the subs 'connect', or any other name that's also the name of a Perl built-in function.
  • You can't do seamlessly if the built-in function has complex arguments - eg print. You can test this by checking prototype("CORE::functionname") - if you get back a Perl prototype (eg "$$"), you can redefine the function as an exact replacement.
  • Put use subs "functionname" in your package
  • Define functionname in your package as you normally would
  • If you want the function to be overridden in ALL packages, even ones that haven't imported your extender package, export the function with *{"CORE::global::functionname"} = \&functionname as well as with *{"main::functionname"}. If you only want it to be overridden in importing packages, which is what I want if I'm just trying to give my 'extender' functions friendly names, export it with *{"main::functionname"} as usual.
  • It is sensible to point out in documentation that functionname replaces the built-in (so caller can say CORE::functionname if they wish to use the original)

http://perldoc.perl.org/perlsub.html#Overriding-Built-in-Functions

Thursday, March 7, 2013

De-crapping Windows 7

Although I've sidestepped W7 on the new laptop by using Ubuntu, I can't do that at work. So I'll be accumulating notes here on how to make W7 work properly.

Explorer - address bar: Alt-D to replace drop-down lists with an edit box that you can actually type a fucking location into

Get rid of fading/expanding windows etc: Control Panel - 'Ease of Access Center' - 'Make it easier to focus on tasks' [now 'Make things on screen easier to see'] - 'Turn off all unnecessary animations'

Get rid of rubbish flashy Alt-Tab previews: Control Panel\All Control Panel Items\Personalization, set Theme to 'Windows Classic'. (This gets rid of a whole load of other crap too, notably it sets the buttons, menus and title bars back to grown-up colours).

Taskbar: in Properties set 'Use small icons' and 'Never combine'.

Start menu: Untick both 'Store' options. You can also use Customise to get rid of some of the useless menu options, but All Programs can't be made to expand like it did in XP (unfixed bug).

  • Be warned that Windows 7 doesn't seem to be able to have MRU on the Run dialogue box without having MRU on the Start menu. I got round this by creating various batch files with very short names to run the things I want most often (like 'goe' - Go Explorer - to run Explorer). Well done Microsoft for forcing users to revert to the state of the art circa 1991.
  • It may be possible to get rid of the search box by going 'Start -> Control Panel -> Programs and Features -> Turn Windows Features On or Off -> uncheck Windows Search' but haven't tested that yet (and it probably fucks up a load of stuff behind the scenes, like taking IE off the desktop used to)
  • You can get your own items onto the main area of the Start Menu by dragging them out of Explorer and dropping them on the button. There doesn't seem to be a grown-up way of doing this.
Turn off various taskbar crappery like pinning and Office buttons thusly:
  1. Unpin everything you don't want.
  2. Use gpedit.msc to set the following settings in User Configuration/Administrative Templates/Start Menu and Taskbar to Enabled:
    • Do not allow pinning programs to the Taskbar
    • Remove pinned programs from the Taskbar
    • Remove pinned programs from the Start Menu

This may not be W7-specific, but with a new computer you may have unwittingly installed intellipoint mouse features. This will stop middle/wheel click from closing tabs in Firefox - instead the button takes you into some bizarre fourth-dimensional space between applications, presumably a 'feature' in W7. Use Control Panel/Mouse to set the middle button action back to 'middle-click'.

I love the implicit admission in 'Turn off all unnecessary animations' btw. They might as well have an option labelled 'Make Windows 7 less crap'.

All still working October 2015 - NB the change in the Ease of Access 'Center''s subheadings.

Saturday, March 2, 2013

Perl hash slices

Well blow me tight. Not only can you do hash slices in Perl, but that functionality's been there since Perl 4 at least.

I suppose my understanding of Perl must have been built in such a logical way that it ran a hundred years to the day...

So just as you might have this:

 
@a = (1,2,3); 
print @a[1,2];
and get '23', then you might have this:
%a = qw(alpha 1 beta 2 gaga 3); 
print @a{ qw(beta gaga) };
and also get '23'.

NB that it is an @ and not a % as the first character there.

To slice a hash reference just replace @a above with @$r or @{$r} .

(New) You can also slice in a sort of 'select column' way, where your result is a subset of the hash's keys and values rather than just values:

%a = qw(alpha 1 beta 2 gaga 3); 
%b = %a{ qw(beta gaga) };
and end up with %b being (beta => 2, gaga => 3);

To do that with a reference, replace %a above with %$r or %{$r} .

This works in Perl 5.24 but not in 5.8.2 .

Friday, March 1, 2013

The Deacon's Masterpiece

I've always loved the 'Deacon's Masterpiece' reference in Weinberg's excellent Psychology of Computer Programming - it was
built in such a logical way
It ran a hundred years to the day.
I always imagined the 'Masterpiece' to be some kind of wonderful watch or clock that kept time far faster than necessary, and whenever I found a bug in my code, I'd think 'Yeah, I built it in such a logical way / It ran a hundred years to a day.'

So I'm a bit disappointed, having finally followed up the reference, to find that it's a just some rustic humour by Oliver Wendell Holmes about a 'wonderful one-hoss shay' - that's a chaise to us, one of those bouncy little horse-drawn carriages.

Thursday, February 21, 2013

Perl m// grouping context

m// always returns an array when used with () matches, even if there is only one match. Eg you must say

@a = m/Time (L...)/;

($a) = m/Time (L...)/;

If you assign just to $a in this situation, you'll get the scalar value of the array of matches, in this case 1.

Don't be fooled by testing it with print. print takes a list as its argument - it concatenates all its elements and then prints the result - so it's equivalent to the @a example.

Tuesday, February 19, 2013

Perl glob

Under Win32, if you supply glob() with a string that doesn't contain any wildcards, and there are no files matching your string, you get back one result (your original string). I suppose this makes sense if you are globbing an argument supplied by the user, which might be a single filename or a wildcard spec.

If there are results, they will have a path prefix if there was one in the argument you gave glob. And they won't if there wasn't.

Additionally, the results won't include any subdirectory names that match the wildcard.

Furthermore, with a UNC path you have to represent the leading \\ as \\\\\\\\ - 8 backslashes even in a single quoted string. But you don't have to have more than 1 backslash at any other place in the path.

And beware, you may need to prefix with use File::DosGlob 'glob'; to make glob work natively. NB that even this does not undo the UNC path issue mentioned above - the string that glob is given internally needs 4 consecutive backslashes, and if you construct that string using quotes, the quoted literal needs 8 backslashes.

The documentation says: As a concession to user expectation, therefore, backslashes (under GLOB_QUOTE) only quote the glob metacharacters '[', ']', '{', '}', '-', '~', and backslash itself. All other backslashes are passed through unchanged and this appears to be the same under File::DosGlob.

Further beware that a pattern with a space in won't work in either mode - without the use, glob behaves like split(m/ /,...), and with the use, it returns an empty array.

When are Perl globals initialised?

Code in the main part of a package file (outside any subs) runs during the compilation phase, ie when the "use" statement that loads the package is read by the compiler.

If you set globals (such as package 'locals') in such code, they will not still be set during execution - I'm guessing because globals are initialised to undefined when execution proper begins?

But then if I use a BEGIN block to set globals, they are still set when execution begins, even though BEGIN blocks are supposed to run during compilation too.

The import sub is also a suitable place to use as a workaround (presumably because it runs after BEGIN).

So I have a workaround for this, but I don't know why it works and the other way doesn't.

Perl line number

$. is 1-based. Before any lines have been read it's undefined.

Reading and writing to the same file

Firstly, don't use +> with open, as this truncates the file on opening.

Secondly, +< works, but it appends to the file. You can seek back to the start for reading, but anything you write will go on the end of the file, no matter where the last read was from.

Followers

Blog Archive