Saturday, 3 April 2010

PS3 System Update 3.21

Sony appear to be breaking new ground with the PS3: the only games console that loses features with firmware 'upgrades'. Yes, that's right: version 3.21 drops support for the 'Install Other OS' feature. This is almost on-par with the decision to drop software emulation of the Playstation 2, cutting off those large libraries of games that long-time users of Sony's console series have built up.

The best part of it is being held hostage: you can't use the Playstation Network with anything but the latest firmware, so those who stubbornly refuse to upgrade will find themselves stuck with local-only access.

Way to go, Sony! Really making your customers feel valued here.

Thankfully, George Hotz, who is similarly bemused has some advice: don't update. He's already hacked the PS3, and is looking to get a 3.21 firmware that doesn't lose the feature.

The strange thing is, he's the one that Sony will think is out of order.

Wednesday, 10 February 2010

Determining the Function Name of a CODE Ref in Perl

One of the great things about Perl that it inherits from functional programming is the ability to treat functions as data. You can create an function and assign it to a scalar reference. You can take a reference to an existing, named function and do the same. You're then free to pass that reference around, to be invoked later (the latter case is similar to function pointers in C, but the former is very different as the created sub can make use of variables defined in its lexical scope as it forms a closure).

While defining an API to a service I've been writing, I suddenly encountered the need to be able to differentiate between references to named functions and references to anonymous subroutines. Quite simply, once I'd established a set of objects to operate on, a named routine should be invoked once for each, whereas an anonymous routine should be given the entire set to work with (this allowed a great deal of reuse within the existing codebase without limiting flexibility).

While I suspected that Perl might be able to do this, it seemed like it would be some serious magic. Data::Dumper displays sub { DUMMY } when printing CODE references, so it's largely opaque.

However, Perl comes with the B module, providing access to Perl's internals as it's running.


use B;

sub named_routine {}

my $named_ref = \&named_routine;
my $unnamed_ref = sub {};

printf "%s\n", B::svref_2object($named_ref)->GV->NAME;
printf "%s\n", B::svref_2object($unnamed_ref)->GV->NAME;


this yields:


named_routine
__ANON__


So, provided that you're willing to avoid calling your subroutines __ANON__, you've got a good indication of what your CODE reference actually points to.

Friday, 8 January 2010

Centring Emacs on Screen

Something I've wanted to do for a while that's nevertheless eluded me is how to centre Emacs on-screen when it launches. I'm a bit old fashioned and so like the default 80 character width, but I like as many rows as possible.

At first, with functions like (set-frame-height), (frame-pixel-height) and (display-pixel-height), it seems like it should be trivial, but the problem is that Emacs measures its frame height and width in characters, whereas the pixel functions (obviously) work in pixels.

The link comes in the from of (frame-char-height) and (frame-char-width), which give the height and width of an idividual character in pixels. Just evaluating the following expression should centre Emacs on your primary monitor:


(set-frame-height (selected-frame)
(floor (* 0.95 (/ (display-pixel-height)
(frame-char-height)))))
(set-frame-position (selected-frame)
(floor (/ (- (display-pixel-width) (frame-pixel-width))
2))
(floor (* 0.02 (display-pixel-height))))


If you like this (maybe after some tweaking), you can just stuff the instructions in your .emacs to get it every time.

Wednesday, 23 December 2009

Gutting Britain's Education System

I used to think that the Labour party was deliberately attacking the higher education system in the UK. One of their first acts upon being elected into power in 1997 was to abolish the student grant, favouring loans instead and gifting graduates from low income families with £15-20K of debt before they'd even stepped into their professional career. The thing that galled me about how that was announced at the time was when this was credited as an 'enabler' for students from low income families. I come from a low income family, and unless your degree course is conveyor-belt in/out, there's a very good chance that you could leave university with nothing but debt before your course is over. By its final year, my course was less than a third of the size of the first.

Now, 'Lord' Mandleson, our current Business Secretary, is slashing budgets for higher education, and at the same time asking universities to preserve standards of education. I don't know how his brain works, but when the education system has been getting systematically destroyed by 'efficiency savings' for ten years, there simply isn't that much slack. In addition, he'd like this to be accomplished in part by reducing three year degrees to two years 'as a way of easing the funding crisis'! Knocking a third off degree times will result in wonderfully incapable graduates, and weaken the value of the system as a whole.

How about some honest investment? You know, where you put money into something and reap the rewards in the future? Like when your graduates get higher paying jobs as a result of being better educated, and then pay higher taxes as a result?

As I began, I used to think that the Labour government was attacking higher education. Now I just think they're a mob of self-interested, incompetent fraudsters who've lost all touch with the real world.

Monday, 21 December 2009

The Ultimate zsh Prompt

I cram a lot of information into my zsh prompt. I could describe it, but a picture covers it better:



The code behind this, to be stuffed in your $HOME/.zshrc, is:


autoload colors
colors

precmd()
{

PREV_RET_VAL=$?

if [ "$TERM" = "dumb" ]
then
PS1="%n@%m %% "
return
fi

if [ $EUID -eq 0 ]
then
USER_COLOUR=red
else
USER_COLOUR=green
fi

BASIC_COLOUR=cyan

# Basic prompt: 'user@host [history-number'"
PS1="%{${fg[$USER_COLOUR]}%}%n@%m %{${fg_bold[$BASIC_COLOUR]}%}%1~%{${fg[$BASIC_COLOUR]}%} [%!"

# Possibly append '/job-count', if the number of jobs is > 0
if [ $#jobstates -ne 0 ]; then
PS1="${PS1}/%j"
fi

# Possibly append '/error-status', if $? wasn't 0
if [ $PREV_RET_VAL -ne 0 ]
then
PS1="${PS1}/%{${fg_bold[red]}%}$PREV_RET_VAL%{${fg_bold[$BASIC_COLOUR]}%}"
fi

# Close off the brackets for the status section, and finalise.
PS1="${PS1}] %% %{${fg_no_bold[default]}%}"
}


This uses only shell built-ins, so is suitably fast for running at every prompt.

One variant I used at work was to colour the prompt based on the DEPLOYMENT_STATUS environment variables that the SAs set (one of 'prod', 'test', 'dev', 'cont'): red for production, purple for contingency, blue for test, and green for development, but that's not quite as useful at home. :-)

Sunday, 6 December 2009

Readable Perl

Just finished reading this, and thought the examples and notes were excellent.

I'm quite fond of writing readable Perl. Hopefully my first github hosted project, CTCS2, backs that up.

Wednesday, 2 December 2009

Corporate Mistrust

On Monday, my wife called me to mention that she could buy a heavily discounted copy of Microsoft Office 2008 for Mac through a scheme at work. The price was good enough to make it worthwhile, so I accepted her offer to buy me a copy. Within a few minutes, she emailed me the download link and serial number.

The installer asked for that serial number, which I carefully cut and pasted from the email. Within a few minutes, the office icons are in the dock, and the updater was asking if I wanted to grab the latest patches.

All good so far.

Then I launch Word, and it asks again for my serial number. Again, I copy and paste it into the dialog, expecting that, for whatever reason, I'll have to do this for Excel and PowerPoint, too. Except that the serial number isn't accepted. I try again. Again, failure. Exasperated, I opt for the clean uninstall option using the 'Remove Office' application installed as part of the suite. It doesn't work: 'Remove Office' spends literally hours searching for versions of office to remove, and when I eventually cancel, it tells me that it couldn't find any. What, not even in the bog-standard '/Applications/Microsoft Office 2008' folder? Why would it ever have looked there?

So I manually uninstall it, removing all of the fragments that the damn procedure scattered throughout ~/Library and /Library. Reinstalling yields exactly the same procedure.

The first contact with customer support yields a different download link, and them re-sending me the original key. But the file from the alternate link is identical to the original. So, with the same key and the same file, what happens? That's right: another key validation failure.

So now it's back to customer support, this time providing them with a hardware signature, presumably so that they can generate a new key that's completely locked down to my laptop.

This whole experience has left me wondering why I spent any money on the product at all. The automatic assumption of "it's a copy!" has further damaged my already tarnished opinion of Microsoft as a company, and the textbook incompetence of their first-contact customer support is a frustrating waste of my time.

Really, I wouldn't (and haven't) had this problem with OpenOffice, which has the added bonus of being absolutely free. The only reason I want Office is just so that I can open documents sent to me without losing content, and also to produce Word files that I know will open properly for those ridiculous agencies that accept it as their only CV format.

Edit: 3rd December, 2009

Eventually, I got an obscenely long product activation code from Microsoft. It didn't work. The 'Remove Office' utility still doesn't work, so I'm left tossing shattered fragments of this sorry excuse for an office suite into the trash whenever I find them. Definitely falls into the 'worse than useless' category.