Monday, October 20, 2014

Messing up with the Java installation on Ubuntu

I started using a laptop used by a previous member of them which has 64-bit Ubuntu 12.04  and it seemed fine. Since I'm OK with the existing operating system version and stuff, I decided not to format the hard drive instead  keep working on the existing system. However, after a while, I wanted to run some Java program and then realized  that the Java versions in this laptop has some issue. Now I can't exactly remember the problem, however I remember  the stupid solution I did to remove those existing Java versions. I went into /usr/lib/jvm directory and deleted everything inside it using the rm command. Then I tried to install Java from the beginning but started to receive weired errors.

At the end, I realized that deleting the content inside that directory have messed  up everything to a level where its hard to fix everything. Since I was busy, I decided to put it aside and use a VMWare guest instance of Ubuntu on top of my host Ubuntu system to run the  required Java programs. Finally today I received an opportunity to search the web with a fresh mind to find a solution. I found a working solution which I followed blindly to get my system fixed however I think its worth writing down the steps I followed. The person who had given that answer is Eric Carvalho in AskUbuntu  forum. This is the link to that forum question where he  had answered.

Following are the steps to remove the messed up Java related packages from my system as I got to know from the above forum. Honestly, I don't understand the functionality of most of those commands  but they worked somehow.

sudo apt-get update

apt-cache search java | awk '{print($1)}' | grep -E -e '^(ia32-)?(sun|oracle)-java' -e '^openjdk-' -e '^icedtea' -e '^(default|gcj)-j(re|dk)' -e '^gcj-(.*)-j(re|dk)' -e 'java-common' | xargs sudo apt-get -y remove

sudo apt-get -y autoremove

dpkg -l | grep ^rc | awk '{print($2)}' | xargs sudo apt-get -y purge

sudo bash -c 'ls -d /home/*/.java' | xargs sudo rm -rf

sudo rm -rf /usr/lib/jvm/*

for g in ControlPanel java java_vm javaws jcontrol jexec keytool mozilla-javaplugin.so orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200 appletviewer apt extcheck HtmlConverter idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc xulrunner-1.9-javaplugin.so; do sudo update-alternatives --remove-all $g; done

sudo updatedb

sudo locate -b '\pack200'
 
Finally, I installed Java in my system using the following command and everything worked fine ever after.

sudo apt-get install openjdk-7-jdk

I realized how big the mess I had made by simply deleting the content of my /usr/lib/jvm/ directory which I will never do again. :-)

Wednesday, October 15, 2014

MatPlotLib for plottiing data in technical documents

Around two months ago, I came across an awesome tool which we can use to visualize data graphically using various plots. That is a python library called MatPlotLib. Until then, I was relying on GnuPlot for drawing graphs in technical documents which has it's own syntax. However I found MatPlotLib more useful because of the language it comes with. As a Python fan, this is what I was waiting for. Moreover, I think different graphs we draw using MatPlotLib are much more beautiful and attractive than the graphs in GnuPlot.

We can easily install MatPlotLib on Ubuntu using the following command.

sudo apt-get install python-matplotlib

After the installation, we can start plotting data straightaway. Following two
sample python scripts are for drawing a graph and a pie chart. Open your favorite text editor and put the following contents in two files. Save those two files with two names as graph.py and pie_chart.py since they are python scripts. Now, just run those python scripts and it will come up with graphs in a new window. We can save those graphs into different file formats using the save button in this new window.

graph.py file


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)
plt.plot(x, x, linestyle="dashed", marker="o")
plt.plot(x, 2 * x, linestyle="dashed", marker="o")
plt.plot(x, 3 * x, linestyle="dashed", marker="o")
plt.plot(x, 4 * x, linestyle="dashed", marker="o")

plt.legend(['y = x', 'y = 2x', 'y = 3x', 'y = 4x'], loc='upper left')

#labels
plt.xlabel("this is X")
plt.ylabel("this is Y")

#title
plt.title("Simple plot")

plt.show()


pie_chart.py file


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import matplotlib.pyplot as plt

# The slices will be ordered and plotted counter-clockwise.
labels = ['Frogs', 'Hogs', 'Dogs', 'Logs']
sizes = [15, 30, 45, 10]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')

plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True)

# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')

plt.show()



Here is an excellent gallery with so many examples. Happy plotting! :)

Wednesday, October 1, 2014

Three visitors to WASN lab

Thiemo, Venkat and Kasun, in UoC ground
Two weeks ago, we had three visitors to our lab from Sweden. Two of them are not completely strangers to me while the other one was a new face. The three visitors were Thiemo Voigt, Venkat Iyer and Kasun Hewage. Among them, Kasun Hewage was a student of our university and played a major role in our WASN lab few years back as a researcher. Now he is a graduate student, doing his Ph.D with Thiemo at Uppsala University. Venkat is a post-doctoral researcher working with Thiemo at the same university.

First slide of Thiemo's presentation
We had lot of important works during their stay since they are working in collaboration with us on some project works. Among different interesting things happened, I would like to highlight few events here. Thiemo conducted a nice talk about the recent research works they have done in Uppsala University and also in Swedish Institute of Computer Science (SICS). Among various works they have done, I noticed the recent trend of moving into the resource rich device based sensing paradigm from the very resource constrained sensing paradigm which we've been talking for more than a decade in WSN community. It seems mobile smartphone based IoT applications and platforms have become a hot topic.

Z1 mote connected to my laptop
Another important event occurred during that week is the two day Contiki application programming workshop conducted by them. I was lucky to attend for the first day of the workshop before I get busy in some other work on the second day. They had brought Z1 sensor motes for the workshop which was a new WSN hardware to me. Since Z1 motes contain a microUSB port on board which can be used to directly connect the mote to a PC for programming. That's very convenient and looks familiar to Sky motes. Unlike MicaZ and ScatterWeb MSB430 type motes where we need different programmer boards and special connector cables to program the motes, Z1 is very user friendly from a WSN programmer perspective.

Venkat at Contiki programming workshop
As the final event we did with them, our lab members visited Udawalawa national park with the three visitors and stayed a night there. Besides the joy of this journey, everybody had another research oriented objective during their one night stay inside a national park about which I can talk someday later with details. However, I couldn't join with them for this exciting journey due to some other work I had to do at the lab during those two days. Since our three visitors were supposed to leave right after the day they returned from Udawalawa national park, I had to say good bye to them the day before they leave for the Udawalawa journey.

During their short stay in Sri Lanka, I had few opportunities to talk with them regarding different subject related matters specially with Venkat and Kasun. I was curious to know what are the tools they use in paper works such as drawing technical diagram and so on. They were so happy to talk about different things they do and were always open for discussions. I'm so glad for the opportunity I received to talk with them during those few days and I learned a lot.

~~********~~