An update to one of my previous posts from 5 years ago on the DRM vs Copyright issue.

It seems that Brazil’s copyright reforms are planning to include parts that not only allow breaking DRM for fair use but also penalize people who put DRM on a work that restrict rights of users accorded to them by law.

Link: Brazil’s Approach on Anti-Circumvention: Penalties For Hindering Fair Dealing (via Boing Boing)

Missile Mayhem

April 29th, 2010

Or how to I set up my USB missile launcher to be controlled over the internet with Linux.

Get missile launcher to work with pymissile.

Run pymissile with the –network option. This will allow you to connect to it using UDP on port 20000 and send commands at it.

To test this use the netcat command on the same machine:

nc -u 127.0.0.1 20000

Commands are typed as “<command>:<enter>”

w or up - move up
x or down - move down
a or left - move left
d or right - move right
f or space - fire
s - stop moving
q - move diagonally up-left
e - move diagonally up-right
z - move diagonally down-left
k - move diagonally down-right
r - fire all missiles sequentially
v - fire randomly
esc - close daemon

Available commands can be found in the class MissileNetwork class in the source code

Then I set up a web server (lighttpd because it’s only a netbook) on the local machine and forwarded port 80 through the NAT. The webserver runs a PHP script that sends UDP packets. The sample code was grabbed from the fsockopen documentation and modified to fit.

The web frontend uses the function below and some AJAX to send requests.

<?php
function send_command($command)
{
    $fp = fsockopen("udp://127.0.0.1", 20000, $errno, $errstr);
    if (!$fp) {
        echo "ERROR: $errno - $errstr\n";
    } else {
        fwrite($fp, "{$command}:\n");
        fclose($fp);
    }
}
?>

Then I set up the webcam to stream live on UStream so people could see where they were aiming.

Mock PHP 5 exam

July 25th, 2009

I have been considering going for the Zend PHP 5 certification and bought myself some Zend PHP 5 Practice Exams to see what I need to study up on.

Here is one of the questions I came across.

Which of the following functions are part of PHP's internal Iterator interface?

Answers: (choose 5)
    rewind()
    valid()
    next()
    key()
    current()

Maybe they had problems passing candidates that couldn’t count to five.

How do I unit test this?

February 20th, 2009

Came across a tricky bug a few weeks ago whilst working on some extremely fragile code.

This was the code:


settings.php

$mail_settings = array(
    'server' => 'mail.example.com',
    'port' => 25
);

index.php

function send_email($recipient, $message)
{
    include_once('settings.php');
    $foo = new MailSender($mail_settings);
    $foo->send($message, $recipient); //this was line number in the error message
}
 
send_email('admin@example.com', 'Admin message');
send_email('user@example.com', 'User message');

The tricky part was debugging it, it threw an error on the second call of the send_email function. That’s odd it ran fine the first time and the only thing I could see that had changed was the input to the function, surely that must be the problem? I commented out the second function call error went away, commented it back in and the error was back. This fitted with my hypothesis that the input on the second one was causing the error. But after looking inside the MailSender class I couldn’t see any reason why the function would error there.

I called Kev to give the problem a fresh set of eyes because sometimes when you are working on things like this you end up not being able to see the thing you’re looking for if you stare at the code for too long.

We took apart the function. We created a new file and replaced each function call with the code which was inside the function and were surprised when it worked perfectly. We were confused as to how the exact same code when placed inside a function would have any different effect.

After looking in the wrong places for a while we finally decided to re-examine our assumptions about what the commenting out was telling us. It wasn’t telling us that the problem is in how we were calling the function the second time around, it was the fact that we were calling the function twice.

After realising that it was obvious what was causing the error.

  • Mailsender needs $mail_settings to work
  • variables from settings.php were included with an include once
  • include once will not include a file that has already been included
  • the second function call will not have access to variables from settings.php since they are a) out of scope from first function call b) won’t be included again due to the include once

After changing the include_once to an include the function worked as expected.

This made me think of some questions. How would I unit test this? Should I create a unit test that runs each function n times? How could I ensure that the test wouldn’t fail at n+1 times? How can I be sure my test will be accurate without running the function an infinite amount of times?

Of course the real solution would be to remove the hidden dependencies caused by creating variables in an included file but to do that to this particular inherited project would require a complete rewrite.

Yesterday I bought myself the latest instalment of the Tomb Raider series for the Wii.

I spent a while playing it then I came across got stuck in the Level Puppet No Longer in the last room with the ceiling ring where I couldn’t progress in the game because the switch to open the door had vanished (see forum posts here and here).

I restarted the game and treked back to that point. This time the switch was there and I was able to complete the level.

Later on in the Mexico level I came across another similar bug. One of the switches needed to operate the giant cogs in the floor was missing, instead only a yellow cuboid floated in mid air where it should have been. Fortunately I had a save at the beginning of the level and when I reloaded and got to that point again the switch was there.

Also later there was a bit by where you stop the Archimedes screw from moving the blue glowing liquid into the pool in the main chamber. The column that you’re supposed to shoot down, initially it did not allow me to shoot it, I could aim and fire at it but it had no effect and I couldn’t get the red crosshairs on it as is normally the case with shootable objects.

In conclusion BUGGIEST. TOMB RAIDER. EVAR. I hope I don’t run into any more.

Lego Games

June 9th, 2008

I’ve completed two games to 100% this weekend, Lego Star Wars II and Lego Indiana Jones.

For Lego Star Wars II all I had to do was to complete the Super Story modes on each film which basically means playing through the entire of the story mode again except you get timed. I was under the impression that because the best time was defaulted to 1 hour that if you took longer you wouldn’t get the associated golden brick. This meant that I was restarting the Super Story mode if I felt I took too long on a level. I finally decided to play it all the way through to see what times I was currently getting and then found out that the under 1 hour completion time wasn’t mandatory. So off I went to get the last golden brick in Return of the Jedi which allowed me to complete the spigot outside the cantina which spews studs so I could finally afford the multiplier extras in the shop.

This Friday I got a copy of Lego Indiana Jones for the Wii. It is very fun and I spent the whole weekend playing it finally completing it at 100% on Sunday evening. It’s a fun game and like the Star Wars II Lego game you play through the original three films collecting characters, minikits and posting parcels (which unlock the extras).

Unlike the Lego Star Wars in the Indiana Jones Game I found it much easier to get the treasure multipliers. There was also a sub quest that unlocked Han Solo which involved finding Star Wars characters hidden in the levels. Here’s where I found 4 of the 5 characters (can’t remember the last one)

  • Princess Leia I found in a detention cell in the Temple of Doom (ladder down a cliff face, metal barrier to blow up, nazi needed for guard)
  • Chewbacca – desert city in Raiders of the Lost Arc, door is behind where you find the vehicle which you use to smash the gate near the end of the level (door opened by academic, need short person)
  • C3PO in the first level of Raiders of the Lost Arc next to a minikit.
  • Luke Skywalker – found hanging by feet in snowy cave down a cliff face in ‘Into the Mountains’

Also if you are on the level battle on the bridge the minikit detector will make it appear that there are two minikits beyond the gate just before the end of the level. I think what it’s actually showing are the two minikits hidden in the very beginning of the level, one requires you blow up a metal fence, the other requires you outrun the water.

I liked it better than Lego Star Wars II because you only needed to get the “True Adventurer” (like the Star Wars “True Jedi”) once per level rather than once in story mode and once in free play. I also liked that there wasn’t a Super Story Mode which had to be completed for 100%.

This is my opinion on the topic of a bill outlawing the possession of “extreme pornography” which is set to become law next week. Here’s the BBC article

Why does porn get a different set of standards? It’s perfectly legal to show non-pornographic films which contain “an act which threatens or appears to threaten a person’s life”. In fact in many non-pornographic films we see people seriously assaulted or killed yet no-one applies the same standard to these. If adults can tell the difference between fiction and reality in other films why single out films of a pornographic nature for this harsher treatment?

For once my comment spam on this might actually be on topic.

Yahoo notification script

March 23rd, 2008

Here is a quick script I wrote for my dad so that when he logs in it will tell him if he’s got any new messages.

If it was anything other than a basic yahoo account (webmail only, no POP or IMAP) I could have used the mail-notification package

#!/bin/bash

#requires packages libnotify-bin, fetchyahoo

# include settings from $HOME/.yahoomail, format as shown below
# USERNAME='my-yahoo-email-account'
# PASSWORD='my-password'
. $HOME/.yahoomail

MESSAGES=$(/usr/bin/fetchyahoo --quiet --username="$USERNAME" --password="$PASSWORD" --spoolfile=/dev/null --newonly --onlylistmessages)
COUNT=$(echo "$MESSAGES" | wc -l)

if [[ $COUNT -gt 0 ]]
then
    /usr/bin/notify-send "New Email" "You have $COUNT new messages"
fi

exit 0

I added it to the System->Preferences->Session and now when my dad logs in he doesn’t have to check for emails, the emails will check on their own.

New PC

February 10th, 2008

This week I decided to splash out a bit on a new PC for my parents. Their previous PC was a painfully slow decrepit Windows ’98 install which took about ten minutes to boot and often the mouse would freeze up (meaning that I would have to save whatever document they were editing using keyboard controls only and then reboot).

The new system is a eSys PC pre-installed with Ubuntu which comes with a keyboard mouse and speakers. I have been spent the afternoon preparing it for use.

Due to not wanting to make holes in walls I was forced to open it up immediately and install a wireless card which I nabbed from lifestream, one of my other boxen. Setting up the wireless card took most of the time, it didn’t have any native drivers so I had to use ndiswrapper to beat it into submission. I had managed to get the card working in it’s previous host but it was so long ago that I forgot what stuff I needed. I also forgot to add it to my access points MAC allow list preventing it from connecting until I figured out that what was stopping the DHCP from working was the access point rather than the card as I’d initially suspected.

My parents have only ever used Windows so I am trying to set the interface to look windowsy to help them become accustomed to using Linux. I removed the top gnome menu and put the applications where “Start” would be on windows. I also arranged their icons in the familiar windows layout, putting links to the home folder, trash can on the desktop along with “Web” and “Email” links (which on my dad’s user just runs firefox with the yahoo mail login as the page to load).

There are a few more things that need to be sorted before my parents are completely happy with it, the major one is the printer, a Lexmark X1150 (always complains it’s out of ink when it isn’t) which I’ve yet to get the printing or the copy functionality working.

Guitar Hero III Expert Mode

January 6th, 2008

I’ve found the secret to defeating songs in Guitar Hero III on expert mode… and it is more entertaining than watching someone else play i.e. if you’ve only got one guitar controller.

You need three people, one for the strumming and whammy bar, one for the top three buttons (green, red, yellow) and one for the bottom two buttons (blue, orange).

Me and some friends managed to get past two songs using this technique, Ruby and Holiday in Cambodia. It is still very difficult but it does work if everyone does their bit.

It is easier with the middle person only having two buttons to look out for as their button presses will block notes further up and so they need to be extra careful not to hold notes longer than necessary.