Tag: Python

Programming Merit Badge presentation (2020)

This year, my elder son graduated from Cub Scouts to Scouts (time flies very fast!) and I signed up to be a counselor for Programming (and Public Health) in his troop.

Today, February 1st, 2020, was Merit Badge Day and I taught 6 scouts what is programming and the basics of programming in Python (and Scratch – but they all knew that already) (and nobody chose Public Health …).

I am now sharing my presentation and a few tips and tricks. Feel free to re-use, improve and give me any feedback to make it better.

Here are the presentation files (they are also on GitHub):

I want to highlight that some content was taken from other counselors who made their presentations available online too:

The Boys Life magazine has also a dedicated page with a lot of resources for this Merit Badge. One of the nice features is that scouts can see the same simple program coded in different programming languages, allowing to compare them. They can be the basis for some of their requirements too.

It was the first time I gave this Merit Badge and having 6 scouts is a good number. You’ll face some issues helping them start programming, especially if all of them are new to programming. Also, it’s interesting to have scouts of approximately the same age: they will have similar reactions and they will be at similar level of programming. I had 5 6-graders and one older scout: the older scout had already a higher level of programming (and he kindly helped younger scouts). Also, big mistake from first-time counselor: do not give them the WiFi password at the beginning of the session! 🙂 Ask them to pre-install Python (if they bring their Windows laptop) and only allow them on internet when coding … You’ll thank me later 😉

I went through Safety, History of programming and Programming today in about 1 hour and 20 minutes, which was a bit too long (despite the good interaction and participation).

Then I programmed with them a converter between degree Fahrenheit to degree Celsius. Typing with them and running the script line by line was a good way for them to understand basic programming concepts like variables, case-sensitivity, functions and branching. The files we used as examples and code are on GitHub. From no knowledge of Python to this temperature converter: about 1 hour.

Finally, I covered Intellectual Property and Career in 10-15 minutes. That’s a little bit short. We had no time to enter into too many details. But scouts will have the additional pointers at the end of the slides and this will be a good introduction already.

Final thought? It’s time consuming to prepare all this material (and I thank the other counselors who shared their material!) but it’s also very rewarding to see children (well, teens) discover programming! I encourage you to share things you like as Scout Counselor!

Installing Pwytter on Fedora 11

This morning, it was impossible to post tweets on Twitter so I finally gave in to install a Twitter client. Amongst many software available, Pwytter seemed interesting to try: free software, written in Python were my two criteria.

Unfortunately, the installation process is not straightforward (although its use of the general python setup procedure). Here is how to install it on Fedora 11 from the command line:

  1. Download Pwytter, unzip it, enter directory pwytter-0.8
  2. Install ImageTK: as root, type “yum install python-imaging-tk” (in Fedora, ImageTK was renamed python-imaging-tk)
  3. Install simplejson: as root, type “yum install python-simplejson
  4. (optional) launch: python setup.py build
  5. launch: python setup.py install
  6. Complete the installation by copying some files with the 4 lines below (type them as root too) (a comment in pwytter blog helps to solve the pwCache installation bug):
cp pwCache.py /usr/lib/python2.6/site-packages/pwytter-0.8-py2.6.egg
cp pwCache.pyc /usr/lib/python2.6/site-packages/pwytter-0.8-py2.6.egg
cp -r media/ /usr/lib/python2.6/site-packages/pwytter-0.8-py2.6.egg
cp -r theme/ /usr/lib/python2.6/site-packages/pwytter-0.8-py2.6.egg

Now you can launch pwytter from any user! In addition, since the source code is available and Identi.ca supports a Twitter-compatible API, let’s see if it’s easy to modify pwytter for Identi.ca 🙂

pwytter screenshot

Short script to add a timestamp on pictures

Here is a short script (1.6kb) to add a timestamp on all PNG pictures in a directory. It requires Python and the Python Image Library (PIL). In order to use it, modify some parameters in the beginning to suit your needs (images directory, font file and size, etc.) and launch ./timestampFiles.py. Here is a before/after example (size of pictures is reduced to fit in this blog):

Before/after example of adding a timestamp to a picture

Note 1: the font is not included in the script. Here, I used FreeSans which is a true free font (GNU GPL with font exception). It is available here (local copy, just the FreeSans font, 753kb).

Note 2: I chose to convert PNG images to JPG ones for 2 reasons. First, my capture script gives me PNG images (see previous posts). Second, I want to be able to copy all JPG pictures in a MJPEG movie. It shouldn’t be difficult to change the different file formats to suit your needs (ask me if you can’t do that).

Note 3: I guess this would also have been possible using a bash script and imagemagick, Perl or any other programming language 😉

Watch your webcam with mplayer

A small post just to keep this command at hand:
mplayer -fps 30 -tv driver=v4l:width=640:height=480:device=/dev/video1 tv://
This allows you to watch what your webcam “sees” (provided it uses a video4linux webcam). Btw, Cheese is funny to use too!

I was also trying to find a decent Python library for video4linux but I only found outdated ones (libfg, 2003, and pyv4l, 2002). I guess I’ll have to use some C library for a small project I’ll tell you about later 😉