Friday, August 29, 2014

Recovering files from a formatted hard drive in Linux

Recently I received a request to recover some outlook email files in PST file format in a formatted hard drive. The hard drive was in a laptop which ran Microsoft Windows 7 operating system. By some mistake, the owner has formatted the hard drive and reinstalled the operating system. The requirement is to recover the Outlook emails saved in PST format.

First thing I did was booting the laptop with a 64-bit version of Ubuntu 12.04 live CD. I configured the network setup for the live booted operating system to access Internet through the Ethernet cable. Then I needed to install some tool. For that, I opened the "Update Manager" application and clicked on the Settings button which opened the "Software Sources" window. There, I should remove the check of the "Installable from CD-ROM/DVD" option and then put check on "(universe)" repository.  Now, open a terminal and give the following commands to install the required tool.

sudo apt-get update
sudo apt-get install testdisk

Once the installation gets completed, we can start our data recovery adventure. Since these PST files are so huge, we need a good external storage to hold the recovered files. Therefore I plugged-in a large enough USB drive. Run the command "sudo photorec" in the terminal to start. This tool came with that "testdisk" tool which we installed. When this tool open in the terminal, there are many options you can do. Since it's hard to explain everything, I will just mention the most important things.

Once we open the photorec tool, it will show our hard disk in the laptop. Select the "Proceed" option which will take us to show the partitions inside the hard disk. In this new window, you will see four options and among them what is important is "[File opt]" option where we can select the types of files which we want to recover. Since I wanted only .pst files I just kept the check for that file type and removed the rest. Finally, select a particular partition and take the "[ Search ]" option to start searching for the specified file type in that partition. A destination directory should also specified where the recovered files will be saved. I chose my USB drive as that destination.

The recovery will take a long time depending on the size of each partition. Once the recovery is completed I got the recovered .pst files in the destination directory. These files should be importable into Microsoft Outlook. In case we need to convert the recovered .pst files into some other format, for example for exporting into Gmail or Thunderbird, we need some conversion tool. One such a good tool is "readpst" which we can install from the following command even though I haven't used it for some serious work.

sudo apt-get install readpst

I hope all these tools will help someone to recover their lost data.

Wednesday, August 27, 2014

Preparing letters with Latex

A lot of Latex stuff these days. Today I had to prepare an official letter for a purpose in our lab. I used Latex for it and for that, I had to search in Google and find out the relevant Latex tags. Here is the basic structure of a Letter prepared in Latex.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
\documentclass{letter}
\usepackage{hyperref}

\signature{Asanka Sayakkara}
\address{University of Colombo \\ Schoool of Computing (UCSC), \\ Reid Avenue, \\ Colombo 7, Sri Lanka.}
\longindentation=0pt %for keeping the signature at left side

\begin{document}

\begin{letter}{Dr. Carl Sagan \\ Cornell University, \\ USA..}

\opening{Dear Sir,}

\bigskip
\centerline{\textbf{The title of my formal letter}}

\bigskip\noindent

First paragraph of this letter..

Second paragraph of my letter.

Thank you for your time and consideration.

\closing{Yours Faithfully,}

\ps

\end{letter}
\end{document}

Even though in the first time we need some effort to have a basic structured file as the above one, later we just have to edit the content according to our requirement. Therefore  using Latex for even this kind of simple requirements is a very good idea.

Friday, August 22, 2014

Making Presentations with Latex

When preparing documents such as  research papers, reports, thesis works and even for preparing my CV, I use Latex. However until recently, I didn't use Latex for preparing presentations. I was relying on open source presentation programs such as OpenOffice and LibreOffice when preparing some slides. Finally, I got a chance to explore presentation slide preparation using Latex.

What we need first of all is complete package of Latex for GNU/Linux. I'm using Ubuntu 12.04 and I installed Latex complete package using the following command.

sudo apt-get install texlive-full

It may take a long time to complete the installation since there will be lot of packages installing with huge sizes. After the installation completed, we can move onto try some Latex script. Create a directory called 'Presentation' and save the following content inside that directory as 'slides.tex'. It just contain the minimum things we need in presentation slides. You will note that we are using a document class called beamer.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
\documentclass{beamer}
\usepackage[latin1]{inputenc}

\usetheme{Warsaw}
\title{This is the title of the paper}
\subtitle{here is the subtitle}
\author{Author Name}
\institute{Institutions Name, Address.}
\date{August 22, 2014}

\begin{document}

\begin{frame}
\titlepage
\end{frame}

\begin{frame}{First Slide}
A sample page
\end{frame}

\begin{frame}{Second Slide}
Here is a list of some items.
\begin{itemize}
\item my first list item
\item this is the second item
\item we can have many more
\end{itemize}
\end{frame}

\end{document}

From the terminal, move into this newly created directory and issue the following command sequence, one after the other, to generate our slides in PDF format and view it.

latex slides.tex

dvipdf slides.dvi

evince slides.pdf &

We can extend this basic structure of the latex presentation into any type of complex presentation using tables figure and many other things just like we make them in other Latex documents.

Thursday, August 14, 2014

Hands on Antelpe database on Contiki

Contiki operating system for small low powered devices such as sensor nodes introduced many features of the resource-rich world to the resource constrained world. Among many of those things, in the year 2011, they included a small database management system to run on sensor nodes which is called 'Antelope'. When we download Contiki OS, we receive Antelope with it. Until today, I didn't get a chance to tryout Antelope. Here is a little note on the basics.

I assume that the reader has downloaded Contiki-2.7, installed Tmote Sky tool chain and configured Cooja simulator. With this setup, we can try different examples in contiki-2.7/examples directory such as hello-world example. An Antelope example can be found in contiki-2.7/examples/antelope/netdb. In this example, there is a client program and a server program. The client program provides a serial interface to the user to enter different queries. Once a query is received, client program transmit the query to the Antelope server program running on a particular node in the network. A saved simulation is available here named as netdb.csc in the same directory. By running this saved simulation, client program starts running in the node id 51 and the server starts running on all the other nodes. However, the client program is configured to send queries only to the server program instance running in node id 4.

We can try the example as follows. Start the Cooja simulator by typing 'ant run' in the directory contiki-2.7/tools/cooja. From the file menu in the Cooja simulator, File->Open simulation->Browse and select the simulation file /contiki-2.7/examples/antelope/netdb. The interface of Cooja will be like the the following.


Mote interface viewer is providing the facility to send some text strings to the node id 51 through its serial port. Mote output interface together with a filter will show the output of the mote id 4. Start the simulation from the simulation controller and then we can enter different queries to the serial interface and see the response from the Antelope database on mote 4. Given below are some sample queries we can enter in the interface to play with the database and the responses received from node id 4.

Rime started with address 51.0
MAC 33:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 51.
CSMA nullrdc, channel check rate 128 Hz, radio channel 16
Starting 'NetDB'
NetDB client
> create relation foobar;
865 Transmitting query "create relation foobar;" to node 4
1077 Reply received from 4.0 (2 hops): OK
> create attribute id domain int in foobar;
3079 Transmitting query "create attribute id domain int in foobar;" to node 4
3085 Reply received from 4.0 (2 hops): OK
> insert (23) into foobar;
4101 Transmitting query "insert (23) into foobar;" to node 4
4106 Reply received from 4.0 (2 hops): OK
> insert (12) into foobar;
4785 Transmitting query "insert (12) into foobar;" to node 4
4790 Reply received from 4.0 (2 hops): OK
> insert (79) into foobar;
5481 Transmitting query "insert (79) into foobar;" to node 4
5486 Reply received from 4.0 (2 hops): OK
> insert (38) into foobar;
6655 Transmitting query "insert (38) into foobar;" to node 4
6660 Reply received from 4.0 (2 hops): OK
> select max(id) from foobar;
7815 Transmitting query "select max(id) from foobar;" to node 4
7825 Reply received from 4.0 (2 hops): [relation = db-result, attributes = (id)]
Row 1:79
7827 Reply received from 4.0 (2 hops): [1 tuples returned; 5 tuples processed]
OK

I think I need to study netdb-client.c and netdb-server.c if I want to do something serious in a WSN application with Antelope.

References:

Saturday, August 9, 2014

Integrating Tapjoy mobile monetization SDK with an Android app

Recently I tried some coding on integrating Tapjoy SDK into an Android application. Even though there are good documentations on how to do this, I decided to write the basic steps on my own words for future use. In this article, I only write down about how to put the relevant JAR files and configurations in an Android app to make an initial connection with Tapjoy back-end. The rest of the things are remaining for me to be explored in the future.  As the fist step, we create an account here to get access to the Tabjoy dashboard. After getting logged in to the dashboard, we need to create a new app from there. Select the platform as Android and put a name for our application. Application state is 'note live' yet. Note down the app ID and app secret key which we need in the next step. You will notice that the "Integrated?" filed in the dashboard is currently set to 'No'.

Download the Tapjoy SDK for Android from here and unzip the file. What we will really use from this SDK is the tapjoyconnectlibrary.jar file located in the Library folder in the SDK. Even though Tapjoy SDK comes with Google Play Services Library, I didn't use that since I already had integrated Google Play Services Library in my Android app. What we need to do now is copying the above mentioned JAR file into the 'libs' folder in the Android project in Eclipse. Right-click on the project and goto the Properties folder. In the 'Java build path' section, goto the 'Libraries' tab and we should choose 'Add External Jars' to browse and select the newly added JAR file. Put the check mark for the same library from the 'Order and Export' tab. Now, putting references to the JAR file done. What we need now is configuring our Android app to connect and use Tapjoy.
Add the following lines to the AndroidManifest.xml file.

Permissions:


1
2
3
4
<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />          
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

Activity details:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
  <activity
      android:name="com.tapjoy.TJCOffersWebView"
          android:configChanges="orientation|keyboardHidden|screenSize" />
  <activity
          android:name="com.tapjoy.TapjoyFullScreenAdWebView"
          android:configChanges="orientation|keyboardHidden|screenSize" />
  <activity
          android:name="com.tapjoy.TapjoyVideoView"
          android:configChanges="orientation|keyboardHidden|screenSize" />
  <activity
          android:name="com.tapjoy.TJAdUnitView"
          android:configChanges="orientation|keyboardHidden|screenSize"
          android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
          android:hardwareAccelerated="true" />
  <activity
          android:name="com.tapjoy.mraid.view.ActionHandler"
          android:configChanges="orientation|keyboardHidden|screenSize" />
  <activity
          android:name="com.tapjoy.mraid.view.Browser"
          android:configChanges="orientation|keyboardHidden|screenSize" />

Add the following lines to the proguard.cfg file if we have it in the Android project.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
-keep class com.tapjoy.** { *; }
-keepattributes JavascriptInterface
-keep class * extends java.util.ListResourceBundle {
 protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
 @com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
 public static final ** CREATOR;
}
-keep class com.google.android.gms.ads.identifier.** { *; }

Now open the main activity of the Android project and add the following import and other statements in the relevant locations.

1
import com.tapjoy.TapjoyConnect;

Inside the onCreate() function: (app ID and app secret key should be obtained from the Tapjoy dashboard)

1
2
3
String appID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
String secretKey = "xxxxxxxxxxxxxxxxxxxxx";
TapjoyConnect.requestTapjoyConnect(this, appID, secretKey);

Inside onPause() funtion:


1
2
// Inform the Tapjoy SDK that the app has paused.  
TapjoyConnect.getTapjoyConnectInstance().appPause();

Now its time to build the project and run. After running the app on an Android device, we will notice that 'Integrated?' field in the Tapjoy dashboard becomes 'Yes' which means we have done the initial integration successfully.

Thursday, August 7, 2014

A meal for the elderly house

Sometimes, unexpected opportunities comes into our lives to do some good. Suddenly one day in last month, a visitor came to our home. He had a file with some documents in his hand and looked very tired. He had been walking all over our village from home to home. His request was very simple. There's an elderly house which need our help. They were lack of supply of meals to the resident elders in the upcoming few days. This guy asked us whether if we can provide a meal for the elderly house in such a day. Among the very close dates available in his list, the only one which was affordable to us was the breakfast of 25th July which was after three days from then. We happily accepted it.

To get further details of this alms giving to the elderly house, I decided to visit there and talk to them about how this should be done. One morning I got dressed and went there by walk. This place is called "David Jayasundara Elderly Home" located closer to Thalpavila area. Even though initially I thought that it won't be hard to walk there, it was far from my home than I thought. I had to ask from several people passing by to correctly locate the place. When I visit there, a middle aged person was available to talk about the alms giving. He asked me to sit down and then he explained many things which I should know to perform this alms giving properly. This place gives shelter to about 30 adults in various ages which includes both males and females. The administrative guy told me that there are days where they don't have any meals as donations and therefore they have to cook. So, it would be better if we can give some dry food also so that they can cook it themselves in such days.

After I returned home, we had lot of discussions about what we would offer for the breakfast. Amma, my younger brother and me finally agreed to provide Pittu and Hoppers because I found out from my visit to elderly home that the residents like to eat these food types. Hoppers is something we can get easily by ordering from a small nearby shop. An aunt in a neighboring house offered us that she can prepare Pittu if we provide the ingredients. We provided everything such as coconuts, rice flour, etc. Other suitable side dishes which Amma prepared at home are Kiri Hodi and Seeni Sambol. Additionally we bought Banana. In addition to these food for the breakfast, we decided to donate some other food items which they can use to prepare their meals in other days which includes some noodles packets, Chili powder, salt, etc.

Finally, the time arrived. We helped Amma to prepare the food items which she was supposed to make at home. In early morning, Amma, Lahiru malli and me went to the elderly house by a three-wheeler carrying every thing and arrived there by 7.30am. First of all, all the residents and us joined to perform religious observances before offering the meals. Among the food items we offered, I think they liked to eat Pittu than Hoppers. Perhaps it's because they rarely get a chance to eat Pittu. It was a very delightful moment to see how they enjoy the meal we offered. 

Even though, I'm not a rich guy to spend lot of money on many such good causes, this was good enough to make me feel so happy. I think everybody in my home also felt good after making an alms giving to an elderly house after a long time. This remembered me a nice quote from somebody. 

"If you can't do great things, do small things in a great way"