> Snowflake Christmas card web page on the Raspberry Pi

December 16th, 2014

In this video I will show you how to make an electronic Christmas card for your friends or family using HTML and JavaScript, which means it will be a little web site that anyone can see by going to it in their Internet browser.

I’m doing this on the Raspberry Pi, but you can do the same thing on almost any computer that exists. All you need is a web browser (like Firefox or Internet Explorer) and a text editor (like Notepad or Gedit).

If this looks very difficult, try the video I made making a similar card using Scratch, which is a lot easier: Snowflake Christmas card in Scratch on the Raspberry Pi.

If you’d like to use the snowflake picture I drew, right-click this link and choose “Save link as…” or similar: snowflake.svg.

If you’d like to compare my code against yours, right-click this link and choose “Save link as…” or similar: snowflakes.html.

If you’d like to see what the finished product looks like, just left-click on snowflakes.html above, instead of right-clicking.

> Snowflake Christmas card in Scratch on the Raspberry Pi

December 16th, 2014

In this video I will show you how to make an electronic Christmas card for your friends or family using Scratch.

Scratch can work on most computers – you can download it from http://scratch.mit.edu/.

Scratch is already installed on your Raspberry Pi if you’ve got Raspian or NOOBs on your SD card.

(If you want to get a Pi try my Raspberry Pi: Before we start video.)

If you want to try something more advanced, you can make a similar card as a web page: Snowflake Christmas card web page on the Raspberry Pi.

> Encoding URLs in Java

December 4th, 2014

To encode a URL in Java, create a new instance of java.net.URI and then call toString() or toASCIIString() on it.

DO NOT use java.net.URLEncoder. It is for HTML form encoding, not encoding URLs, despite its name.

Each part of a URL must be escaped differently, so use the multi-argument constructors for URI where you have multiple parts you want to stick together. You can pass in null for arguments you want to omit, and it works the way you’d hope.

This program:

class EncodeUrls
{
    public static void main( String[] args ) throws java.net.URISyntaxException
    {
        url( "http", "example.com", "/x/y/x", "x=y", "pos" );

        url(
            "http",
            "exa\uD83D\uDCA9mple.com",
            "/x/\uD83D\uDCA9/x",
            "x=\uD83D\uDCA9",
            "po\uD83D\uDCA9"
        );
    }

    private static void url(
        String scheme,
        String host,
        String path,
        String query,
        String fragment
    )
    throws java.net.URISyntaxException
    {
        java.net.URI uri = new java.net.URI(
            scheme, host, path, query, fragment );

        System.out.println( "." + uri.toString() );
        System.out.println( "." + uri.toASCIIString() );
        System.out.println();
    }
}

prints:

.http://example.com/x/y/x?x=y#pos
.http://example.com/x/y/x?x=y#pos

.http://exa💩mple.com/x/💩/x?x=💩#po💩
.http://exa%F0%9F%92%A9mple.com/x/%F0%9F%92%A9/x?x=%F0%9F%92%A9#po%F0%9F%92%A9

> Books that changed my life

December 2nd, 2014
  • Further Programming for the ZX Spectrum by Ian Stewart, Robin Jones
  • Foundation by Isaac Asimov
  • Crime and Punishment by Fyodor Dostoyevsky
  • Structure and Interpretation of Computer Programs by Harold Abelson, Gerald Jay Sussman, Julie Sussman
  • Slaughterhouse 5 by Kurt Vonnegut
  • Possibly: Children of Men by P.D. James (too early to say)

> Why I use Linux

December 1st, 2014

I have used Linux at home for quite a few years, and a couple of years ago I changed my work machine from Windows to Ubuntu Linux. It’s made life at work better for me.

Better for me

This move has made me much more productive, saving valuable time and money. Here is why:

Security updates happen automatically, without hitches, and rarely requiring reboots.

Since I changed, security updates are applied almost as soon as they are made available with no interaction from me. I have never seen a security upgrade that broke my system and prevented me working, whereas before I saw this several times.

My computer works faster.

My computer feels much faster to work with. In recent tests for our project, we found that the time spent waiting for a compile on my Linux machine was half that spent waiting on an identical system using Windows.

I work faster.

Because my system is more customisable than before, I can work the way that feels more comfortable to me. Support for keyboard shortcuts is more comprehensive in Linux, and I can work using the keyboard for most things, which helps prevent recurrence of RSI, from which I have suffered in the past.

I can automate repetitive tasks.

It’s much easier to write small scripts on Linux for things that I do every day. This means I spend more time thinking about the work I have to do, instead of all the button-clicking required to do it.

I can have more programs open.

My computer now works comfortably simultaneously running 3 or 4 heavy corporate applications, at least 2 copies of Eclipse, Firefox with many tabs open, several Chrome windows, 3 text editor windows, a 1GB virtual machine and many other programs, without slowing down or crashing. When I used Windows I needed fewer programs open, but because Linux manages memory better and many of the programs are less memory-hungry, I can do more things at the same time.

I can use “virtual desktops”.

It’s hard to explain why until you’ve tried it, but virtual desktops are an incredibly addictive feature. I avoid neck strain by using a single monitor directly in front of me*, but I am able to have lots of separate work spaces and can switch very quickly between them. I use one desktop for email and instant messaging, another for the Internet, and several more for programming in different environments. Switching between them happens as fast as I can press the relevant keyboard shortcut. This is a killer feature of modern Linux desktops in my opinion.

[*Multiple-monitor setups are well-supported too, of course.]

Modern tools work better.

Modern software – especially programming software – is frequently developed on Linux, and has its “home” there, meaning it is easier to install and update than on other platforms. Examples include: Python, Node.js, Perl, Vim, Emacs, Bash and Ruby, all of which are much easier to use and install on Linux than on Windows.

Better for my company

Because I use Linux, my company saves time and money.

  • Administering machines is easier. I get Ubuntu and corporate security updates automatically through the built-in security update mechanisms. The corporate updates are maintained by volunteers at my work in their spare time.
  • It’s cheaper. There is no license fee to use Ubuntu, and no added-value version to buy. Support can be paid for from several companies, including the company behind Ubuntu, Canonical.
  • I am more productive. As explained above, I am able to do more work in the same time because I use Linux.