Installing dbus on Mac OS using Brew

To install dbus, I follow the steps here:

  • First, open Terminal
  • Run the following command on the terminal:
  • ruby -e "$(curl -fsSL" < /dev/null 2> /dev/null
  • Then you need to install Xcode command line tools:

xcode-select –install

  • After that, run brew:

brew install dbus


Running Thymio Wireless with Python on Ubuntu Virtual Machine

I have written a post on running Thymio using Raspberry Pi. Somehow the wireless connection was not working for me even after I plug the usb wifi. So I decided to try using Ubuntu Virtual Machine on Windows host. And it works.


  • Host OS: Windows 10
  • VirtualBox
  • Virtual Machine OS: Ubuntu 16.04 LTS

After finish installing Ubuntu on the VirtualBox. These are the steps:

  1. Install aseba following the steps here. The official documentation provides steps for Ubuntu.
  2. Install dbus: sudo apt-get install python-dbus
  3. Install gobject: sudo apt-get install python-gobject

Now you can follow the steps to run the python code:

  1. run asebamedulla: sudo asebamedulla “ser:name=Thymio-II”
  2. run python code on a different terminal: sudo python

Running Python on Thymio

I found a link that describes the process here:

The setup that I use is Raspberry Pi 2 Model B+ running Jessie. First we need to setup the hardware connection:

  1. Connect USB from Pi to Thymio
  2. Connect power from socket to Pi
  3. Start Pi

Now, we need to install some software. There is a bug in the software provided by Thymio websites, so I found a forum where they provided the fix for Pi. On your pi, open terminal, and type the following:

sudo apt-get install apt-transport-https

This is to enable apt-get to get source from https.


Now, we add the source by editing /etc/apt/sources.list:

sudo sh -c 'echo "deb jessie main" | sudo tee -a /etc/apt/sources.list'
sudo apt-get update
sudo apt-get install libenki libdashel aseba

After it is installed, we can test if asebamedulla is running. To do this, open a new terminal, and type:

sudo asebamedulla "ser:name=Thymio-II"

If it works, it will output something like the following:

Found Thymio-II on port /dev/ttyACM0

Now, download the sample code. Open a new terminal or a new tab, and run the sample code as follows:

sudo python

It will output:

dbus.Array([dbus.STring(u'thymio-II')], signature=dbus.Signature('s'))
0 0 0 0 0

At this point, it waits for you to enter the command.

  • Type “w” and press Enter to move forward for 1 second.
  • Type “s” and press Enter to move backward for 1 second.
  • Type “a” to rotate to left
  • Type “d” to rotate to right

Type CTRL-C to exit.


Installing zenburn theme on Aquamacs

I followed the steps in to install zenburn theme using MELPA. But I had difficulty making it stick the next time it loads. These are the steps that works with me:

  1. Run Aquamacs
  2. Type: M-x package-install zenburn-theme
  3. I also added (load-theme ‘zenburn t) to “~/Library/Preferences/Aquamacs Emacs/Preferences.el”

But when I close and run Aquamacs again it is not exactly zenburn as the lower bar text are too dark. So I need to load the theme manually:

M-x load-theme zenburn

To make it stick, I follow the steps in:

  1. With zenburn theme loaded, I go to: Menu -> Options → Appearance → Auto Faces → Use Current Face as Default
  2. And I do the next step: Menu → Options → Appearance → Adopt Face and Frame Parameters as Default
  3. Answer “Yes” to the dialog.
  4. Exit Aquamacs and “Y” to save the settings.

Multiple LDAP authentication in Django

Django allows multiple LDAP configuration. The example of the configuration is given here:

To do this we need to create a Python module under site-packages. For example we can create a module called ‘mypackage’.

$ ls /home/administrator/websenv/lib/python2.7/site-packages/mypackage

We can leave empty, and write the following entry into
from django_auth_ldap.backend import LDAPBackend

class LDAPBackend1(LDAPBackend):

class LDAPBackend2(LDAPBackend):

class LDAPBackend3(LDAPBackend):

Now, we can configure the ldap in Django This is an example of a configuration in Django.

import ldap
from django_auth_ldap.config import LDAPSearch


AUTH_LDAP_2_SERVER_URI = "ldap://"
AUTH_LDAP_3_SERVER_URI = "ldap://"
AUTH_LDAP_1_SERVER_URI = "ldap://"



In the example above, we created three backends LDAP1, 2, and 3. We first import the backends to Django and set the URI, DN_TEMPLATE, and bind the domain.

We may need to restart Django and the server:

$python syncdb
$sudo apachectl restart

Erasing External Harddisk that cannot be opened

I got problem with my external hard disk. After some issues of umounting the disk, I couldn’t open the hard disk anymore. I tried to use Disk Util to repair, but it said it cannot be repaired and must be erased. But I can’t even erased it! It says disk can’t be opened. So I finally managed to erase it.

First, go to Terminal and type:

$ diskutil list

This will show a list of disk and partition. It happens that I can’t seem to erase the volume. But somehow I can erase the disk. So this what I do.

$ diskutil unmountDisk force /dev/disk1

and after it unmount, I type:

$ diskutil eraseDisk JHFS+ Backup /dev/disk1
Started erase on disk1
Unmounting disk
Creating the partition map
Waiting for the disks to reappear
Formatting disk1s2 as Mac OS Extended (Journaled) with name Backup
Initialized /dev/rdisk1s2 as a 931 GB case-insensitive HFS Plus volume with a 81920k journal
Mounting disk
Finished erase on disk1

Introducing scikit-learn for Machine Learning in Python

In this tutorial, we will go through a simple steps to classify whether a voltage is a digital 0 or 1. We will make things pretty straight forward with large margin so that we can easily visualize. The idea is just to introduce some of the functions in scikit-learn that we can use for linear classification.

The simple problem we want to do is given a set of voltages and its digital logic, we want to be able to determine what would be the digital logic given a new set of voltages. In this example, we use supervised learning, where we label the data and have the training set. Then given a new data, we want to determine which class it belongs to. We will use linear classifier from Support Vector Machine.

First given a training data sets of voltages, e.g.

>>> import numpy as np
>>> data=[0.5,0.1,0.2,0.15,0,0.3,0.4,0.5,0.35,0.45]
>>> data=np.array(data).reshape(len(data),1)

The first line of the above code import numpy module so that we can use its array data stucture. The second line create a list of voltages as a Python list. The third line, convert the Python list to Numpy array and change from a row vector to a column vector.

We can then train the data set by labeling the voltages. For simplicity, let’s label any voltages below 0.2 to be digital logic 0, and anything above 0.3 to be logic 1. To do this we create a target list according to our data set.

>>> target=np.array([0,0,0,0,0,1,1,1,1,1])

Now we can create our linear classifier using SVM.

>>> from sklearn import svm
>>> clf = svm.SVC(kernel='linear')

The first line import the module svm, and the second line creates a linear classifier. Next, we have to fit the data with the target.


And now we can predict new data. Let’s say we want to determine what the digital logic is for voltage 0.21V, we can type:

>>> clf.predict(0.21)

Or we can also give an array:

>>> newdata=[0,0.5,0.22, 0.1,0.44]
>>> newdata=np.array(newdata).reshape(len(newdata),1)
>>> clf.predict(newdata)
array([0, 1, 0, 0, 1])

As you can see that voltages around 0.2 and below is classified as logic 0 while those around 0.3 and above is classified as logic 1.