Parallel operations in R

I thought I’d start a list of some code examples I’ve found online which enable you to perform parallel operations in R and take advantage of multi-core processors.

I’ll try to add to this list from time-to-time when I come across new examples.

Read More
Renaming all files in a directory with Bash

In the past when I’ve needed to automate a task, such as renaming thousands of files, I’ve tended to use the Python OS module. However, lately I’ve started to write Bash scripts to achieve these tasks, because of how quickly and easily it allows me to work within the Unix filesystem. Last week, one of my programs produced thousands of images with random names. I decided that I needed to write a script to rename all the jpg files in a directory incrementing from 0:

Read More
Filming long videos with the Raspberry Pi camera

I’ve been interested in trying to use the Raspberry Pi to film really long videos which can last for several days. If you set the time flag (-t) for raspivid to 0, then the camera will record until you kill the program. The command is below; note that I’m only filming at 10 frames per second and that the “-n” flag cancels video preview:

raspivid -n -fps 10 -t 0 -o $temp

Read More
First impression of Swift (Apple’s new programming language)

Swift is Apple’s new programming language, which promises to allow you to write iOS and OS X apps more easily than with Objective-C. Apple have released a free eBook titled “The Swift Programming Language” which provides an overview of the language. This is where I gained my main impressions on Swift. To give you a little background on myself: while I have had an interest in getting into app development for a while, at this point I haven’t touched any Objective-C – I am currently programming mainly with C, C++ and Python.

The first thing I thought when I started looking at the Swift code examples, is how much it reminds me of Python. Consider the first Python script most of us learned:

Read More
What I learned while learning C++

C++ is regarded by many as one of the most difficult programming languages to become proficient in. After spending the past couple of months learning and writing a lot of C++ I am positive that while I quite like the language, it is definitely not a good first language for someone just starting out. There’s a reason a lot of first year computer science courses lean towards teaching Python and Java, leaving C++ for later, when students have a good grip on the fundamentals of programming.

One of the things I’ve discovered since I started learning C++ by myself online, is that there are many, many websites out there with tutorials and guides to the language. They looked professionally done and I was happy to use them. However, after I wrote my first tutorial on the C++ language and asked others for feedback on reddit, it was pointed out to me that a lot of C++ resources online can be misleading to learners. I’m not sure if its due to the complexity of the language or the authors’ of such tutorials wanting to keep things simple, but the result is a lot of tutorials online encourage bad practice, and even code that is not compliant with the C++11 standard.

Read More
C++ for beginners

In this tutorial, I’m going to provide an introduction to the basics of the programming language C++. I’ll describe how to compile your first program with the gcc compiler on Linux and Mac, although the code should also work on Windows using the Visual Studio compiler. If you’re new to programming, I’d probably recommend getting started with an easier scripting language like Python, before you get into C++. That said, hopefully the information in this post should still be useful for the complete beginner.

What is C++?
C++ was invented by Bjarne Stroustrup in 1978 as an extension of the popular C programming language. It added classes and the ability to write object orientated code.

Is C++ worth learning?
Although C and C++ came out decades ago, they remain extremely popular when speed and performance are a crucial requirement. Although C is a great language, C++ added a lot of functionality which comes in handy for big projects. While knowing C will give you a head-start when understanding C++, it is not essential. Personally, I started off learning C before changing to C++ because the imaging library I use for a lot of my work (OpenCV) is written in C++.

Read More
Find sequence descriptions with BioPython

Image you have a lot of nucleotide sequence identifiers and want to find out what organism the DNA is from. You could go to the NCBI website and spend a long time finding out, or you could write a short Python script using BioPython to find out the headers from each fasta file the identifier refers to:

Read More
Python Regular Expressions

Before today, the only real use I’d had for regular expressions in Python was to just find the first instance of a pattern. For example, if I want to find the contents of the text between the first set of single quotation marks (in this case ‘26245730’), I would proceed like so:

import re

all_id="'26245730': 817, '389595538': 735, '541129065': 529, '541129071': 340, '558870185': 305, '444325280': 287, '573974252': 272, '281314044': 222"

first_id ="'(.*?)'",all_id)

The arguments passed to define the pattern I am looking for: The single quotation marks on either side of the brackets show that I am looking for a pattern between them. The “.” within the brackets tells Python that I am happy with finding any character, number, etc and the “*” next to these mean it will look for 0 or more instances of this text. Finally, the “?” ensures that the expression isn’t greedy. What does it mean to be greedy with a regular expression? It means that instead of finding the pattern between the first two single quotation marks, it will find the pattern between the first and the last quotation marks! So I’ll end up with practically all of my string being returned!

Read More
Where to learn C++

C++ is the most recent language I’ve acquired, and while I certainly still have a lot to learn, I’ve gained a reasonable understanding from the following free resources online:

  1. – Learn C++
  2. tutorialspoint – The C++ Programming Language
  3. – C++ Language
  4. – C++ Video Tutorials
  5. Google Developers – C++ Class
  6. – Programming Tutorials – C, C++, OpenGL, STL
  7. University of Southern Queensland – Object oriented programming in C++
  8. Stephan T Lavavej – Core C++
  9. Professor Peter Sommerlad – Modern and Lucid C++ for Professional Programmers
  10. Software Design Using C++


I was recently alerted to the fact that some of these resources can contain incorrect information/bad practices. Here’s a great list of C++ resources which have been vetted by the reddit learnprogramming community. One recommended resource is a book titled “C++ Primer 5th edition”. It was published in 2012 so it covers the C++11 standard.

Read More
Best resources for learning OpenCV (Python and C++)

Here’s a list of some of the websites, books and videos (for both Python and C++), that I have found very useful while learning OpenCV.


  1. Using OpenCV with Python and ROS (Video) – Great introduction to computer vision and OpenCV.
  2. PyImageSearch – Website has a lot of great tutorials on many different applications of OpenCV.
  3. OpenCV-Python Tutorials (Website) – Official Python documentation and tutorials.
  4. OpenCV-Python Tutorials (Website) – Comprehensive set of tutorials.
  5. OpenCV Python (Website) – The original Python tutorials I started with, most of these have been ported to the website above.
  6. OpenCV 3 With Python (Website) – Great list of Python tutorials.
  7. Tentative NumPy Tutorial (Website) – As OpenCV reads images into NumPy arrays, its useful to have an understanding of this library.
  8. Python – Getting started with OpenCV (Website) – Introduction to using Python with OpenCV.
  9. Programming Computer Vision with Python (Book) – How to use Python to build computer vision programs.
  10. OpenCV Computer Vision with Python (Book) – Short book on getting started with OpenCV and Python.
  11. Building an image processing pipeline with Python (Video) – Talk about how Python and OpenCV are used in industry.
Read More