Create Python Virtual Environment with virtualenv

There are a lot of pros to using a virtual environment to manage different Python environment, which will be independent of each other. The following are the steps to create one under Ubuntu 16.04 with Python 2.7.x

Install the virtualenv with the necessary packages

Create a folder for the virtualenv

Activate & Deactivate the virtual environment

After sourcing the activate script, you can find a “(myenv)” in front of the folder prompt, which is the virtual environment’s name and it has been activated.

Now, the pip can be used to install/update the python modules belongs to this virtual env only.

To deactivate is also very simple.

 

Hands on Algorithm of K-means

In the ICME machine learning workshop, the presenter talked about the algorithm of K-means to do the data clustering. It’s a simple and interesting algorithm. The following is a simple example, which generates the sample data, sets different K.

Mixin by Interface Default Method in Java 8

In Java 8, the feature of interface Default Method was introduced.

Java 8 introduces “Default Method” or (Defender methods) new feature, which allows developer to add new methods to the interfaces without breaking the existing implementation of these interfaces. It provides flexibility to allow interface define implementation which will use as default in the situation where a concrete class fails to provide an implementation for that method.

This is a very interesting feature and also very useful. With it, we can implement kind of Mixin. Let’s see following case.

Before Java 8

In a system, there is real dog and robot dog, both of them can bark. Before Java 8, we may have the following interface and classes.

Maybe you already see the problem. Dog and RobotDog have the same implementation of method bark(). It’s duplication. It’s not easy to fix this problem, since Dog and RobotDog have different parent classes. RobotDog is not a Dog but it can bark. In Java, there is no multiple inheritance.

With Default Method in Java 8

With default method, the implementation can be more elegant. See the following code.

As you can see, the same logic can easily be extracted into another interface and the implementation of Dog and RobotDog looks simpler.

How about making a RobotDog flying? It’s simple and there can have different options of flying.

Now I have a RobotDog, which can bark as a dog and fly as a bird!

Install Ubuntu 16.04 into Raspberry Pi 3 B+

After some investigation, I finally figured out how to install Ubuntu 16.04 into the new Raspberry Pi 3 B+.

Because the bootloader has been updated, with existing Ubuntu 16.04 images, Raspberry Pi 3 B+ can’t be booted. You will be stuck at the rainbow screen.

To fix it, the bootloader and some other driver files needs to be replaced. Here are the detailed instructions.

Download Ubuntu 16.04 Image File for Raspberry Pi 3

On this page, there are several options

I am familiar with Xfce, so I downloaded the xubuntu 16.04.2 image file.

Burn the Image into SD Card

On Windows, you can use a free tool named Etcher

Replace the Bootloader and Driver Files

After burning, there will have two partitions in the SD card. One for boot PI_BOOT, the other for root PI_ROOT

The latest Raspberry bootloader and other driver files can be downloaded from https://github.com/raspberrypi/firmware.

  1. Copy all boot files in folder boot into PI_BOOT partition.
  2. Copy all files/folders in folder modules into PI_BOOT/lib/modules

Boot it

Insert the SD card into Raspberry Pi 3 B+ and connect it the USB cable. It will be successfully booted.

A known problem so far. There has no default wireless network adapter. Need to use a USB wireless adapter.

References