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 )

Thursday, September 17, 2015

Acres and square miles

There are 640 acres to the square mile. But how? The square root of 640 isn't a nice round number.

Take a square mile and divide it into an 8x8 grid, just like a chessboard. There are 64 squares in the grid and each square is 1/8 of a mile on a side, or 220 yards, or a furlong.

Now subdivide each square into 10 strips, vertical or horizontal, it doesn't matter. Each strip is an acre: 22 yards by 220 yards, or a furlong by 1/10 furlong, or a furlong by a chain.

If you recall that an acre is supposedly the amount of ground that could be ploughed in a day, this 'grid subdivided into strips' model immediately seems like a logical one, ploughing being conducted (whether with modern tractor or Anglo-Saxon horses) in long narrow strips in alternating opposite directions.

Monday, August 3, 2015

@models workaround

If can't use @models dynamic because you're forced to use ASP instead of Razor, you can still use code like Html.LabelFor(x => x.Rank) if you change the inherits attribute, from <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> to <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

Friday, June 19, 2015

local and do

'local modifies the listed variables to be local to the enclosing block, file, or eval' - but
  • a do is only 'largely' like an eval - this is one of the respects in which it differs
  • the script that you do may be physically in another file, but when you do it, it is as if it is part of the file where the do is
Or to put it more succinctly, if a.pl uses a filehandle FH, and so does b.pl, and you do b.pl from a.pl, you cannot use local(*FH) in b.pl to stop b.pl's FH from being the same handle as a.pl's.

I worked round this by putting a package X at the top of b.pl, no doubt there are other ways.

Tuesday, June 16, 2015

Always catch exceptions!

I never usually bother to try and catch exceptions when writing experimental code because I expect the runtime to throw up a default exception dialogue.

But after much fruitless fiddling with a toy application using SqlDataAdapter, I found that instead of one of those dialogues, you can just have an infinite hang instead.

I was doing SqlAdapter.Fill(dataset) without first setting dataset to new DataSet(), which (when I eventually put a try-catch round it) I discovered was causing a System.ArgumentNullException - 'Value cannot be null'.

A lesson I shan't forget, because it's wasted about 4 hours today.

Saturday, June 13, 2015

C# project references

The 'dynamic' in DLL as far as C# is concerned, when you've included a DLL reference in your solution, only extends up to the point at which you compile the solution.

So if you have a class library, and a unit test to which you've added a reference to the library, it's no good fiddling with the library in the IDE while running your unit test from a prompt. The unit test will, it seems, have linked into itself the class library DLL as it was when you compiled the unit test: more of a statically linked library in this case.

Accessing Windows share from Linux machine

Just do the first half of this procedure:
www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux
(stop when you get to 'Creating the Share on Linux' - the article describes how to connect in both directions). Apologies for not putting in a link, but for some reason Blogger kept prefixing the address of this blog to the URL.

The only bit I had to change was that my Linux machine couldn't resolve the name of my Windows 7 machine. So

sudo mount.cifs //WOPR/D /mnt/woprd -o user=falken
didn't work, but
sudo mount.cifs //192.168.2.3/D /mnt/woprd -o user=falken
did. In case you don't know, you can find the IP address of the Windows machine with 'ping WOPR' (or whatever its name is) from a command prompt on that machine.

What annoys me most is that I spent all morning wading through articles and forum responses on this subject, and not one of them mentioned that you only need to set up Samba on the Linux machine if you want to access a shared folder on that machine from a Windows machine - the exact opposite of what we require here.

But I did learn something very useful - if you substitute 'linux' for 'ubuntu' in searches, you'll get much more helpful answers, and you won't have to visit askubuntu either. It's vying with the Mozilla forums in uselessness.

Further sayance... what you seem to be doing when you do this is setting up a connection using the CIFS protocol, which I think Windows refers to as SMB protocol, or perhaps it's that Microsoft's implementation of SMB is enhanced to include CIFS functionality. I don't know and I don't need to, because the point is that CIFS and SMB are the keywords to use when doing searches about this stuff.

Which is what I did when I was trying to work out how to see what username I was showing up as from Windows' point of view - do net session to see all SMB connections.

And if you're wondering why you can't paste onto your Windows share from Linux in the original scenario above, even though you've mounted rw, it's probably because you've only given root (at the Linux end) rw permission. You just need to sudo the application in which you're trying to do the pasting (thunar in my case).

Thursday, June 4, 2015

C# class library

If you create a class library which uses (eg) System.Data, you have to explicitly add a reference to System.Data.

I'm guessing that you have to do that in this context, but not (eg) when making a Windows Forms application, because in the latter case the references are included in the project for you when it's generated.

Thursday, April 2, 2015

Making Ubuntu usable

Take note that the logon screen offers you a choice of three 'sessions', which you choose between by (before you log on) clicking the unlabelled Ubunto logo button towards the top right corner of the screen.

The choices are:

  • Ubuntu Studio - just about usably slow (the default when I installed it)
  • Ubuntu - unusably slow
  • Xfce - fastest of the three. Usable.

I also recommend adding '-inurl:askubuntu' to all searches for answers to this issue (or indeed any issue). This will save you having to wade through acres of unhelpful cut-and-paste.

Wednesday, April 1, 2015

Scite

Scite properties files have significant whitespace:

x=1

sets 'x' to '1' whereas

x = 1

sets 'x ' to ' 1'

I've written a few config file parsers in my time, and I know laziness when I see it.

Thursday, March 26, 2015

cp -u and filesystems

The otherwise excellent cp -u variant is no good for copying between ext3 and fat32 filesystems - fat32 records last modification times to the nearest 2 seconds (just like MS-DOS!) and ext3 is much more accurate. So very often cp -u will wish to make an unnecessary copy from ext3 to fat32, and fail to suggest a necessary copy from fat32 to ext3.

There used to be a page at http://vb.mvps.org/hardcore/html/filedatestimes.htm explaining that there's even more bizarreness to the FAT32 date situation than I mention here, but it's been replaced by one of those smart-arse 404 messages, so fuck them.

Saturday, March 21, 2015

dd and 'Safely Remove Hardware'

I spent several hours of the night, early morning and morning trying to write bootable USBs using the dd+iso method. None of them would boot, and all of them showed as 'unpartitioned' to TRK and as having 1 partition to diskpart.

Finally tried not tidily clicking 'Safely remove hardware' before taking the freshly-written USB out of the PC. And it worked fine!

Possibly 'Safely remove hardware' does something to the drive that isn't necessary with a directly-written drive, and indeed that corrupts it.

Btw, I'm glad so many people are finding my original 'dd' post, it's the most popular thing I've ever written on the net by an order of magnitude, so I hope it's helpful.

Wednesday, March 18, 2015

C# try...catch scope

If you do this
XDocument xdocument;
try {
  xdocument = XDocument.Load(args[1]);
} catch (Exception e) {
  MessageBox.Show("All kinds of fucked up shit happened - " + e.ToString());
  Environment.Exit(-3);
}
xdocument.DoStuff();
you'll get a 'use of unassigned variable' error for the xdocument.DoStuff() line.

What C# actually means is that xdocument might be unassigned at that point in the code, cos we didn't assign it on the first line of the example.

Solution is to replace the first line with:

XDocument xdocument = null;

As this page told me.

Monday, February 9, 2015

Perl BEGIN

You can call out of a BEGIN block to other subs, but the code defining those subs must have been read (and so, compiled) before the BEGIN block is reached.

Obvious when I think about it really.

Wednesday, February 4, 2015

Powershell

I think what annoys me most about Powershell is the inconsistency. With PHP it's the inconsistent function naming, with Powershell it's the different parameter interfaces of the cmdlets.

I can't for the life of me see why I either have to use get-member as a filter, or say

get-member -inputobject $a

whereas I can say

$a = new-object DateTime

without having to specify any tiresome -inputtype switch.

Tuesday, January 27, 2015

import

use Themodule;

supplies ("Themodule") to Themodule::import as @_.

use Themodule();

causes Themodule::import not to be called at all. Apologies for the misleading previous version of this point.

use Themodule(<list>);

supplies ("Themodule", <list>) to Themodule::import as @_.

Friday, January 23, 2015

Scanning and printing resolution

Some rambling based on the data here (actually no link due to Javascript clipboard spam).

They're measuring resolving power in lines per mm (lpmm) which I suspect is just another way of saying dpi when the page is viewed at a standard distance.

They suggest that the resolving power of the human eye is not much more than 8 lpmm; assuming a viewing distance to the page of 30cm, a line at 8 lpmm is being seen at 2400 diameters, and the widely accepted maximum resolution of the human eye is 1 arcminute (1/60 degree) or ~ 2500 diameters. So that corresponds.

They also say that a good lens at optimum aperture would exceed 100 lpmm; at the same viewing distance that's 30,000 diameters or about 7 arcseconds (7/3600 degree). That's rather poorer than the 0.5 arcsec resolution of a 250mm reflector, but of course that's separation of point sources (stars) rather than resolving dark features. So I don't think that undoes the correspondence above.

1 lpmm should be 25 dpi, as we can confirm by reading the assertion that printing has to be at 25-30 lpmm (525-750 dpi) to look sharp, and that corresponds to the 600 dpi of decent laser printing.
(They say that this 25-30 lpmm should theoretically be 10 lpmm - the resolving power of the eye as mentioned above - but in practice low contrast images require more resolution).

Now that we've established that their terms can be translated into our terms, we can tackle the question that made me start this post - 'What is the maximum resolution at which it is worth scanning a (positive print of a) BW photo?'

Their figure of 75-100 lpmm for photographic printing paper suggests 1900-2500 dpi, and for what it's worth that corresponds to the sort of resolution I found useful for pulling fine detail (eg text on papers held by people in the picture) out of old photos I'd scanned.

Wednesday, January 7, 2015

Array reference slice

Take an array slice from a reference to an array thusly:

@{$ra}[2..4]

Followers

Blog Archive