Code Club

11th January, 2019

Code club logo

I've been taking part in a national after-school club known as Code Club, aimed at kids 9-11 with a view to inspire them and teach them about programing. The code I have been teaching them is based on Scratch, which uses drag and drop 'blocks' of code to control and interact with sprites. I have helped host and run 2 clubs at different schools and the results have been quite different. Here I'm going to share my experiences and some ideas that others may find useful.

Challenges

I'm not a teacher, nor am I great at public speaking, so one of my biggest fears is nerves and awkwardness. It's a bit daunting at first with a room full of 25 kids focused on you and listening to every word you say. I try to keep my talking to a minimum by asking them lots of questions so it keeps things quite interactive and they feel involved. After a while you become used to the classroom noise, become more focused on what you're teaching them and pay less attention to the fact that you're talking.

It's also quite fun when they all shut up and pay attention. One method the schools I have taught at implement is when the teacher claps a short rhythm, then the kids have to repeat the sequence and immediately stop what they are doing and shut up. I found this pretty hilarious the first time I witnessed this, but it seems to work!

Discipline - I seem to find the kids only start messing around or misbehaving when they are bored or no longer focused on the task at hand. Sometimes there's a few kids who consistently don't want to do the work the rest of the class is doing. I try to encourage them to do the work just like the other kids, but if they really want to work on some other projects or play some other game, well at least it's kind of related and they're having fun. I don't want to waste my whole time focused on one disruptive pupil. If a child is really misbehaving there is always a professional teacher in the room who will take control of the situation (though I've not been in that situation so far).

Keep them interested - The first club I helped at, we didn't really know what to expect or what to do. Because of this, we relied heavily on the Code Club worksheets provided on-line. However, I don't think it was wise to rely solely on these. We found a lot of the kids would easily get bored or distracted and start misbehaving, whilst some of the other kids were just blindly copying the code without any thought or understanding. It also meant that people were at lots of different stages of the worksheets, with some kids three or four lessons ahead/behind the others. I have found a better technique is to pick one idea to teach that week, and to go through it with them step at a time. This helps to get every kid up to the same point, and I can ask them questions about why we're doing what we're doing, trying to get them to lead the way to the next step.

Different abilities - Another good technique I have found is to have the kids share a laptop or computer - aka pair programming! It helps keep them focused, and means if one of them has a problem, instead of asking the teacher they can ask their partner, resulting in mutual support!

Technical issues - There is always one or maybe two computers that won't turn on, the Internet isn't working, or some other technical issue. I find it incredibly helpful to have an assistant who is there to help teach, but also to help tackling these individual technical issues which can take some time to resolve sometimes.

Rewards

I find teaching at Code Club very satisfying, it's nice to see these young kids being interested in coding and (hopefully) learning some very useful skills that will help them in the future. It can be very fun to plan the lessons and create the games/challenges with them. Most lessons I come away inspired by something one of the kids has created or said, which feels very rewarding.

There are also self-motivated reasons to take part: I want to improve my teaching and communication skills, so what better way to practice, if you can take something complicated and make it understandable by 11-year-olds then you should be doing okay! What's more it means I can get out of work early one day a week and invest my time doing something very different from normal. It helps get a bit of perspective on what I do day-to-day, and gives me some breathing space away from clients and a hectic workspace. I would highly recommend getting involved!

Lesson Ideas

Although the scratch resources on the code club website are pretty good, I have found it better for the kids to work together led from the teacher rather than a worksheet. Here are some of my lesson ideas below:

Crab Chase

This lesson demonstrates how to choose a backdrop, shows what two sprites are, and how they can be controlled by mouse input. I used two methods to animate the sprites, the starfish always goes to the mouse-pointer, and the crab continually moves towards the mouse-pointer, simulating a chase effect. The crab sprite also has two costumes so you can alternate these every few paces to add more animation. If everyone completes this then I show some collision detection, where the crab announces a message, such as "Got you now" or "You've been crabbed" - I usually let the kids come up with their own (better) messages... There is also a score which continually increments until you get caught, then it resets itself. This introduces the idea of variables.

Play it here

Spider Bug

The premis of this game is a bit like classic arcade game Frogger. A sprite (spider bug) in this case has to make its way over the road and up the building, avoiding moving cars and an airplane. This demonstrates using different inputs - the keys on the keyboard - and creates events when those keys are pressed. Again it shows collision detection, and could also have a timer or more levels to make it more challenging.

Play it here

The Snowman

This is a bit like Flappy Bird or the Helicopter game. Use the space bar to float up, and avoid snowballs and icicles! Demonstrates variables (score and lives), cloning (the snowballs and the icicles), randomness and gravity.

Play it here

Tagged: code club teaching


Docker: my first steps into containerisation

11th January, 2019

Docker logo

I have been intending to experiment with Docker for a very long time and I finally found the time to do so this week.

I do have some basic sysadmin experience, but I am not an opps guy, so some of the things that may have been obvious to some were baffling to me. I don't have much experience with virtualisation or hypervisors either, apart from running Vagrant and a few boxes from my Mac.

The initial install after following the Docker getting started instructions was pretty smooth, I had to upgrade Virtualbox but that was about it. One thing to note that if running on a Mac, like me, then Docker cannot run on the host directly, it has to run on a virtual Linux host, which runs through Virtualbox on your mac. This means that to use the Docker commands, you will need to be logged in to the Docker virtual machine (called default by default). There is a convenient bash script installed with Docker and it's wrapped within the app Docker Quickstart Terminal. This script attempts to start the VM (if not already running) then tries to login to the VM. If you try and use Docker commands without first running from this app you may see something like the following:

$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

To manually solve this, OS X also comes with Docker Machine. You can see a list of your docker machines with $ docker-machine ls. You will probably see a machine called default. To set up the environment commands, issue $ docker-machine env default or whatever machine you want to connect to. This will return some environment details and a command to run, probably eval $(docker-machine env default).

Once you're in, there's a few very useful commands

$ docker ps // for listing all running docker containers

$ docker search // search docker hub for images

$ docker images // list all locally cached docker images

$ docker run [...] // run a container (lots of useful options to apply

$ docker network [...] // manage and list networks and containers within them

$ docker stop // stop a container by it's name

$ docker exec -ti <container-name> bash // open a bash session in the already running container

$ docker rm // remove a container by it's name

I started playing with pre-existing images, namely ubuntu, php and mysql. It's very quick to run a new image, execute a bash script inside of it, or, if it has ports mapped to your host, see what's going on in a browser.

The docker run command takes lots of useful options, some I have used include

-P automatically assign ports

-p [host-port]:[container-port] manually expose and assign a port

-e ENVIRONMENT_VARIABLE=<value> set an environment variable on the container, e.g. -e MYSQL_ROOT_PASSWORD=secret

-t -i run and open a bash command line in the container

-d run in detached mode, or in the background. Useful (necessary?) if you want the container to remain running indefinitely.

--name=[...] manually assign the container name. This must be unique (you can stop/remove unused containers). Useful for when you want to refer to a specific container from a network or another container.

-v [host-volume] [container-location] mount a local directory to the container at the specified location. Useful when you want to be updating files on the host (like your application files) and seeing the results immediately in the container

--link <container-name>:<optional-alias> link another container to this container by name, and optionally an alias.

For a comprehensive list of options see the docs.

There's a few complications, the php image for example was missing a few common extensions like mcrypt, intl, pdo_mysql etc. But these can also be installed.

A beautiful thing about Docker is the ability to extend these existing images, run your own commands or install other software, then save that in a lightweight, readable, portable script called a Dockerfile. You can then build an image from this file, and publish this on Docker Hub - the repository for public Docker images.

Once you get beyond the process of creating a single container and wanting to do more complex tasks you may want to create a system composed of multiple containers. You can do this with docker-compose. The instructions are pretty clear, but you will create a small, readable, portable YML file which contains instructions for running one or more containers, and executing other scripts (a bit like the Dockerfile).

An example might look something like:

docker-web:
  image: drupal:8
  container_name: drupal-web
  links:
   - docker-db:mysql
  ports:
   - "80:80"

docker-db:
  image: mysql
  container_name: drupal-db
  expose:
   - "3306"
  environment:
   - MYSQL_USER=username
   - MYSQL_PASSWORD=password
   - MYSQL_DATABASE=database_name
   - MYSQL_ROOT_PASSWORD=secret

And that is as simple as it gets. Just run docker-composer up -d and Docker will download the base images (if they aren't already cached locally) run both containers and link the database container to the web container. The above is very close to what I used to create this site. You can do more and include data volumes, which are intended for sharing data between containers (useful for migration and for backups).

One thing I'm still struggling with is when sharing local storage from the host to the Docker machine, how to get other users e.g. www-data or apache to be able to write to the volume because they don't have permissions by default.

It's been a whale of a journey (excuse the pun) but I can really see many advantages and will be interested to see how Docker matures and is adopted.

Tagged: docker container dev-ops