Category Archives: Code

Where do you wake up from a bed in Minecraft?

After issuing many /time set night commands, I can tell you the waking-location algorithm for Minecraft. This presumably also affects your spawn point.

Two locations are checked, and if they fail to select an acceptable location the pillow-location is used regardless of consequences of picking this location. An acceptable location is on the same level as the bed, and has two transparent-non-solid blocks above it (i.e. you will be standing next to the bed without your head or body embedded in something that’s killing you).

The process is the same for each of the two locations:

Sweep x-1 to x+1:
  Sweep z-1 to z+1:
    if the location is acceptable, we're done

The locations are checked in the order: pillow-part-of-bed, non-pillow-part-of-bed. The effect is:
From the Minecraft wiki:

For a bed to be usable as a spawn point, the player must be able to stand next to the bed at the same level as it. There must be a solid block at the same ‘floor’ level as the bed, with 2 transparent blocks of space (for example, air) for the player to stand in, in one of the ten blocks that surround the bed. It doesn’t matter if the bed itself has blocks above it.

How to to install the Crypt::Eksblowfish::Bcrypt module, and Crypt::Random

Have you gotten the error
Can't locate Crypt/Eksblowfish/ in @INC (you may need to install the Crypt::Eksblowfish::Bcrypt module)
and wondered what to do? Wonder no more!

sudo apt install libcrypt-eksblowfish-perl

and perhaps

sudo apt install libdigest-bcrypt-perl

What about
Can't locate Crypt/ in @INC (you may need to install the Crypt::Random module)

sudo apt install unzip make gcc
cd Math-Pari-2.01080900/
perl Makefile.PL
sed -i 's/CLK_TCK/CLOCKS_PER_SEC/g' pari-2.1.7/src/language/init.c
make test
sudo make install
cd ..
tar zxvf Crypt-Random-1.25.tar.gz
cd Crypt-Rando1.25.tar
perl Makefile.PL

Easy! Only takes a few hours if you don’t know what you’re doing.

Git: prune those old branches

TortoiseGit’s right-click sometimes appears to freeze.

It can be caused by too many old branches hanging around.

Here’s how to prune the ones that have been merged to master:

git branch --merged master |grep -v master | xargs git branch -d

Obviously you’ll want to make sure your master branch is up to date.

Thanks to my colleague UA for finding that one.

TortoiseGit claims commit message is empty

I was wondering why TortoiseGit* was complaining that my commits had no message in them.

“Aborting commit due to empty commit message.”

Turns out the new version by default strips out messages starting with a # character.

As detailed in this issue report, the over-ride is in Settings / Dialogs 2.

TortoiseGit options

*yeah, I’m not a hardcore Git user, though I do prefer Git Bash on Windows for some operations

Flickr’s new HTML code embedding – how to remove the header and footer

Flickr has altered its default embed HTML to include a header and footer, which includes Flickr branding and the title of the picture.

PT in the Sense8 titles 01

Sometimes I suppose this is okay, but sometimes I just want the picture.

Fortunately it seems to be relatively easy to get rid of. In the example above:

<a data-flickr-embed="true" data-header="true" data-footer="true" href="" title="PT in the Sense8 titles 01"><img src="" width="500" height="282" alt="PT in the Sense8 titles 01"></a><script async src="//" charset="utf-8"></script>

…remove the data-flickr-embed, data-header, and data-footer attributes of the a href, and remove the script tags, like this:

<a href="" title="PT in the Sense8 titles 01"><img src="" width="500" height="282" alt="PT in the Sense8 titles 01"></a>

The result should be just the photo, with the usual linking back to Flickr.

PT in the Sense8 titles 01

It’d be nice if they made this a built-in option when generating the HTML code.

Of course, it also makes me ponder if I should be finding another photo host.

Update 2015-07-20: They seem to have modified their default embedding code a bit so the branding and picture details now only appear over the photo when you mouse over it. Not so objectionable.

PT in the Sense8 titles 01

Flickr’s modified code now excludes data-header="true" data-footer="true" which presumably added the header and footer.

COM+ calling multiple .Net versions risks blowing the memory limit

From the Things I’ve Found That Might Affect Other People But There’s Not Much Detail In Google About It department

Not that I have much to add to the sum total of published knowledge on this, but our situation is we have a COM object (legacy code) calling .Net 2 objects (not-quite-as-old legacy code).

We’re upgrading it all to .Net 4.5, but the .Net stuff is an easier change, so we’ve been doing that first, naturally in a carefully planned, staged manner.

It turns out that COM+ objects have a 1 Gb memory limit.

And it appears that when you have them calling a mix of .Net 2 and .Net 4 objects, the overhead of being able to call two different .Net Framework versions becomes an issue.

At least that’s our theory based on what we’re seeing — looking at ProcessExplorer showed about a dozen assemblies loaded for each version of .Net.

One blog post I read suggested a 600-800 Mb overhead for each .Net version. I can’t confirm that, but certainly we’ve had more Out Of Memory exceptions than we expected.

We’ve resolved it by going back to our .Net 2 code (so only one version is held within the COM+ process at once), and we’ll do the big switch all at once. Hopefully that’ll resolve it.

The COM object will also be switched too of course, and once that’s done, running everything in .Net 4, plus a move from 32-bit to 64-bit machines, apparently will lift that 1 Gb limit to 8 Tb!


SQL Server paranoia mode

This post is for Tony!

Worried about accidentally overwriting critical data with a typo in your database commands?

SQL Server Management Studio has an option for that: SET IMPLICIT TRANSACTIONS, which you’ll find (in 2008 / 2008 R2 at least) under Tools / Options / Query Execution / SQL Server / ANSI.

SQL Server implicit transactions option

Anything you do (from the next query window you open) will automatically be in a transaction, so you can ROLLBACK if you realise you’ve done the wrong thing.

Be warned, you’ll need to get into the habit of manually COMMITting everything. Don’t be tempted to just add the COMMIT at the bottom of your query… that would defeat the purpose.

It’ll prompt you do to so if you close a query window without having done a ROLLBACK or COMMIT. It can get a little irritating, but knowing you can’t accidentally trash all your data may give you piece of mind in return.

FOP and ZXing compatibility

From the I’ve been trying to get this to work — this tip may save you some time department:

Apache FOP is for doing graphics with XML and XSLT.

FOP version 0.95 came out in August 2008. 1.0 in July 2010. 1.1 in October 2012.

ZXing is for doing QR codes.

ZXing 0.1.2 was released in March 2012, and seems to no longer be in active development.

The important bit: As far as I can see, ZXing works fine with FOP 0.95 (which was current when it was released), but not with later versions.

I kept getting these errors:

SEVERE: Image not available. URI: (instream-object). Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for null (No context info available)
org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for null

With any amount of fiddling, I couldn’t get it to work on Windows and Java 1.7. Nobody online appears to have noted this issue. You might have more luck…

Or maybe there is no solution to it. If so, I hope this saves you some time.

(Barcode4J, which we also use, seems to work with all currently available versions of FOP. It also has QR functionality, provided via ZXing, but this is only available in the unreleased code, which presumably has alpha status, and you have to build yourself. Barcode4J also hasn’t been updated in some years, last released in December 2010.)

Unhelpful web help

Just… just… wrong. So wrong.

Firstly, note the error message “Enter a valid email addresss”. Where, pray tell, ought I do this?  Why do I need to upload any attachment again?  Why do I have to prove I’m a human time-after-time, when all I’m doing is wrestling with your completely broken attempt at a web form?

Have they noticed that no-one is submitting help requests via this form, what with its refusal to accept said requests?

Dear Flickr: stop sucking balls.

Political donations are not the problem

Corrupt politicians have recently been in the Australian news.

It has been observed that money, in the form of political donations, is a corrupting influence. This causes hand-wringing, as banning donations is considered to hinder the freedom of political expression.

As a response to this demand for cash to finance political expression, suggestions are made that private funding of politics be replaced by public funding – basically an increase on the funding which parties already receive (something of the order of $2.48 per primary vote in lower house seats in the last federal election, for example). This grates those with a strong dislike of politicians and the political process. In addition, the current funding model of retrospective funding (based on votes received) disenfranchises new political views – it locks in the existing players by funding them, allowing them to campaign for votes that will fund them; those outside the system will not be able to break in.

To allow new entrants into the political system to be funded on an equitable basis, some kind of on-going polling could be done and a funding stream allocated on proportionate support in non-electoral polls.

However, switching to purely taxpayer-funded funding isn’t necessary, even if in effect the tax-deductibility of political donations makes them taxpayer subsidised.

Political donations are not the problem, the problem is that donors can be identified by the political party and and expectation of quid pro quo is raised. Beyond that, large donations from a single donor are also a problem – even if political party donations were anonymised and repudiable the donation’s existence could be inferred by the velocity of money flowing out of any anonymising system.

Let’s say you’re trying to run a corrupt political party under an annoymised donation system. Someone comes to you and says “I will give your corrupt party $10m, and I expect you to make this corrupt thing happen.” You’d then donate the $10m, and your donation would be pooled along with the hundreds of other donations made to the party. The Donor Anonymising Service (DAS) would then hand over a certain amount of money to the party, but it would not be $10m. It would be the stipend that the party had requested from the DAS, along with advice that the current amount held in reserve is enough to last at least X days, where X was the same number (give or take a couple of days) as it was yesterday. You don’t know if the $10m donation was actually made, all your party knows is that it’s got enough money to last X+2 days. You could up the rate of the stipend, but the DAS would scale back the reported window so that no extra information is revealed by the reported minimum duration the reserves will last. You’d limit the rate and number of times the stipend could be changed to discourage probing. Naturally, it would be illegal to make a political party aware of a donation or its amount.

Of course, then you have all the fun and games associated with loaning money to political parties, and with corrupt administration of a Donor Anonymising Service, but you get the gist of where we could go with this idea.

BASIC turns 50

The BASIC programming language turned 50 on Thursday.

This Time article is a great read — and notes the importance of the language on getting school students programming.

What’s the equivalent today? The Raspberry Pi is helping make hardware affordable. Some might dabble in Visual Basic or C# via Visual Studio Express, or the many of the other freely available languages such as Python, PHP, Javascript… or here’s another way of looking at it, from Jeff Atwood: