An Interesting Rivalry: Facebook and Google

A few days ago, a good friend of mine invited me to a wedding. I was checking the details of the wedding location on Facebook when I noticed to my delight that Facebook displayed a map of the location below the address. How nice of Facebook to make it so easy for me to visualize locations. So I thought, with a bit of scepticism, what if the map isn’t right? After confirming with Google maps, I was happy to know Facebook’s map was accurate. It was at this point I made an interesting realization: Facebook does not use Google maps! Facebook uses Bing instead. We all know Google is the king of maps, so what prompted Facebook to avoid Google. Surely, there’s more to this than coincidence. So I did a bit of digging.

It turns out that Zuckerberg had had talks with Google in the past about possibly letting Google handle search queries Facebook can not handle itself, but he wasn’t satisfied with Google’s terms of service. Apparently, Google’s privacy policy was too inflexible for Zuckerberg’s liking. Microsoft, on the other hand, was more flexible in their privacy terms. Facebook wants its search suppliers to be able to remove Facebook users’ details quickly if need be based on user privacy settings. So, it will seem that Google takes its mission statement: to organize the world’s information and make it universally accessible and useful much more seriously than keeping data private for business customers. Well, we can’t blame Google much for this. What else will you do if you are the biggest Search Engine company in the world? As a side note, how much of the world’s internet traffic does Google actually handle? According to Forbe’s article ‘Fascinating Number: Google Is Now 40% Of The Internet’, Google is responsible for 40% of internet traffic. To get a more visual context of this figure, consider this: On August 16, 2013, all of Google services were down for a few minutes. Here’s what the graph of global internet usage looked like in that period.

google-downtime

Courtesy of GoSquared in their article https://engineering.gosquared.com/googles-downtime-40-drop-in-traffic

Also, it turns out that Microsoft is a Facebook investor, which must have given it some leverage in negotiating with Facebook. That’s the way, Microsoft! Do your thing.

Now, having cleared up why Facebook doesn’t use Google for search, I found out something even more interesting. Facebook is testing its very own search engine! Facebook introduced Graph Search in March 2013. Graph search is considered to give you results instead of links like traditional search engines and you can use it to search for places, people, pages, check-ins, objects with location information, posts and comments. Imagine being able to search for people ‘who are single in London and from Nigeria’. If you’re looking for buddies to go watch that geeky movie, you could search for people ‘who like star wars and star trek’ and Facebook will check through your friends list and potentially through the rest of its 1 billion user base to find answers based on what your friends have shared with you privately and what Facebook users share publicly. That this could take a chunk out of Google’s search shares should be quite obvious. It appears that English users in the USA have now been using Graph Search since August last year. Hopefully we here in the UK get to try it out soon. Facebook is most likely looking to get more and more of its users to become comfortable searching for things on Facebook, starting with social entities, which Facebook is already well known for. I assume they believe it’s only a matter of time before they roll things out into general search. Eventually, Facbook could also make a killing in advertising revenues as businesses fight tooth and nail to rank highly on Graph Search.

So, what can Google do about it? Well, Google will need to continue what it’s already doing – engaging its huge user base. From the recent Google I/O we can see that Google has big plans for the future, from integrating Android into smart watches, to cars – Android Auto, to improving the OS and user experience on Android phones, to allowing you use Android apps on TV (Android TV), to making it possible to use your cherished Android apps on Chromebooks. Basically, Google plans to make your life revolve around Android in the near future. If things go according to plan for Google, you may wake up a few years from now and think back saying “How did we ever live without Android back in the day?” From what we’ve seen in recent years, Google has been making conscientious efforts to integrate its services, providing a rather seamless experience for users. On my Nexus 4 phone for example, I can start doing a Google search at a tap of a button and the search will be done both on my phone and on the web. How cool is that? The idea is that the tighter Google keeps you around its ecosystem of products, the more reluctant you will be to try out other things.

Nevertheless, Google may want to consider this so-called semantic search method Facebook is using in one way or another rather than just sticking to keywords.

As these two companies continue to innovate and compete, we can expect to see more and more interesting features produced to make our lives easier and more pleasurable. Let’s see what these tech giants have up their sleeves as this rivalry unfolds.

Continuous Integration in Android with Jenkins and SVN

In this article I discuss how to implement continuous integration for an android project using a Continuous Integration (CI) server, Jenkins, and SVN.

Setting up project and test project

First, create an application project in eclipse. Let’s assume it’s called ‘project’ and is at /home/user/Documents/project

Next, create a test project for the aforementioned project. Let’s call it ‘test project’. So, in eclipse, go to File > New > Android Application Project. Uncheck ‘Create Project in Workspace’ and set the Location field to /home/user/Documents/project/tests. This way, both project and test are under one folder and can be managed easily with version control software. Also, uncheck the Create Activity checkbox.

After creating test project, we need to add the main project to its build path so that it can access the main project resources. To do this, right click the test project in Package Explorer view and click Properties. Then click ‘Java Build Path’ in the left sidebar. Click on Projects tab, click Add and choose project. Click OK to save.

Update the AndroidManifest file of the test project so it reads something like:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project.tests"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.project" />
<application
>
<uses-library android:name="android.test.runner" />
</application>
</manifest>

Setting up Ant

Jenkins, our CI server, requires Ant in order to manage Android projects. So we must supply Ant information to the project (build script and properties file). Thus we need to install Ant

Get Ant from http://ant.apache.org/bindownload.cgi. Unpack it somewhere on local machine. Create an environment variables ANT_HOME and JAVA_HOME and add the path to the directory containing ant binary to your PATh by adding the lines below to your ~/.profile file. Be sure to adjust the paths accordingly.

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

export ANT_HOME=/home/user/development/apache-ant-1.9.2

PATH="${ANT_HOME}/bin:$PATH"

Test that ant is installed properly by running the command ‘ant’ on a terminal. You should see something like

Buildfile: build.xml does not exist!

Build failed

Generating ANT build scripts

cd to your project directory and run the following command:

android update project -p .

This will update and rebuild your project, then generate a build.xml file in your project’s root folder which will be used by ANT to build your project.

cd to your test project directory and run the following :

android update test-project -m .. -p .

Note that the general form of the command is: android update test-project -m _PATH_TO_ANDROID_PROJECT -p _TEST_PROJECT_PATH_

This will update and build your test project, generating a build.xml file in its root folder. So we now have two build.xml files.

Add the test project’s build.xml and ant.properties file to version control. Also add the project’s build.xml to version control. Do NOT add the test project’s local.properties file to version control as that is machine-specific.

Building with ANT

cd to your project’s root directory and run the following :

ant clean debug

This should build the project.

Next, cd to your test project directory and run the following code:

ant clean emma debug install test

This will build the test project, run code coverage with the EMMA code coverage tool, install the application on your emulator or device and run your JUnit tests on the application.

Install Jenkins

Now we will install Jenkins on the CI server. Website: http://jenkins-ci.org/. For ubuntu servers, this involves running the following code:

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key \
	| sudo apt-key add -

sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > \ 
	/etc/apt/sources.list.d/jenkins.list'

sudo apt-get update

sudo apt-get install jenkins

By default, Jenkins listens on port 8080. To avoid having to type this port number in the browser everytime, you could proxy the web server to point port 80 to 8080. For that, assuming you use apache, create a file /etc/apache2/sites-available/jenkins and add the following code to it:

<VirtualHost *:80>


	ServerAdmin webmaster@localhost

	ServerName ci.company.com

	ServerAlias ci

	ProxyRequests Off

	<Proxy *>

Order deny,allow Allow from all </Proxy> ProxyPreserveHost on ProxyPass / http://localhost:8080/ </VirtualHost>

Enable mod proxy, enable the site and restart apache using the following code:

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2ensite jenkins
sudo service apache2 restart

Now Jenkins is installed. You should be able to access it by going to http://ci.company.com/

Install Android SDK on the server and all relevant versions.

Install Android Emulator Plugin. This involves, going to the main page, then clicking on Manage Jenkins > Manage Plugins. Then click on Available tab, find the plugin, check the checkbox next to it, and click ‘Install without restart’ button.

Check if Subversion plugin is installed. If it isn’t, check if it available for download. If it isn’t, download and install it manually. To do this, visit the plugin page at https://updates.jenkins-ci.org/download/plugins/subversion/, download the latest plugin, and move the downloaded file into Jenkin’s plugin folder at /var/lib/jenkins/plugins/

System Configuration

Configure required paths (e.g. to ANT, SDK, etc) by going to Manage Jenkins > Configure System

Create Project on Jenkins

Create a new job by going clicking New Job. Enter name of job and check the Build a free-style software project radio.

Next, configure the new job.

Go to the homepage and click on the job. On the job page, click Configure link on the left sidebar. Enter the project name and description. Under Source Code Management, check Subversion Modules. Enter the url for the repository.

If your repository requires authentication, then an error message will show saying Jenkins couldn’t access the repository. To fix this, first create a new svn user for Jenkins on your repository. On the error message section, there will be a link for Credentials. Click that link and enter the username and password of a user you have just created. The error message should disappear. Click the Save button.

Now test that the job can access the repository. On the job’s page, click Build Now. Jenkins should checkout the project and create a workspace. On the workspace you should see files for the project.

Building project with ANT

Next, we will configure Jenkins to build the job with ANT.

Go to the job page and click Configure.

Under Build section, click Add Build Step button. Select Invoke Ant build step on the dropdown that appears.

In the build step’s command textfield, enter the following:

clean debug

This will build a debug version of the app. Test that it runs fine by saving and clicking Build Now link.

If there’s an error about sdk.dir not found, you can add this to the step by visiting Configure page, clicking Advanced button for the build step, and entering the following line, where the path is changed to reflect where you installed the sdk. I assume you should see this error if you entered the data under System Configuration:

sdk.dir=/home/user/android-sdks

Run android emulator to run tests

On the configure we need to run the emulator in order to run tests, so check the Run an Android emulator during build checkbox. A form will appear asking for avd details. Fill it in as shown below

Add another build step.. Choose Invoke Ant. Set the command to

clean emma install debug test

Next, tell Jenkins where the build file is for this step. To do this, click Advanced button, and enter the following for Build file:

tests/build.xml

Test it by saving and clicking Build Now link. If there’s an error about sdk directory, then go back to the Configure page, click Advanced for this step, and enter the following for Properties:

sdk.dir=/home/user/android-sdks

where the path is updated accordingly.

Save and build the project.

Tip: while build is in progress, you can move the mouse next to the build time on the main page, click the down arrow button that appears and click Console output in the dropdown that appears. This will show you the commands being run in real-time.

Publish JUnit and EMMA coverage report

Next, we will make Jenkins generate JUnit test result and EMMA coverage report when tests are run.

To do this, go the Configure page of the job. Under Post-build Actions, add an action called Publish JUnit test result report. Set Test report XMLs to tests/junitreports/*.xml

Add another Post-build action and this time choose Record Emma coverage report. Set the Folders or files containing Emma XML reports to tests/bin/coverage.xml

Save.

Note that JUnit reports get stored on the emulators and Jenkins doesn’t have access to this. To get around this problem we can use the android junit report by Jason Sanky.

Here are the steps:

Visit the Jsanky github at https://github.com/jsankey/android-junit-report. Go to the downloads page and download the latest android-junit-report jar.

Place the jar file in your test project’s libs folder.

Update the test project’s AndroidManfest file. Specifically, change the android:name attribute of the instrumentation tag from

android.test.InstrumentationTestRunner to com.zutubi.android.junitreport.JUnitReportTestRunner

cd to the test project’s root folder and edit ant.properties. Add a line as follows:

test.runner=com.zutubi.android.junitreport.JUnitReportTestRunner

We also need to update the run configuration of the test project to use the library. To do this, click on the arrow next to the Run button and click Run configurations. Under Android JUnit Tests, click on the test project. In the Test tab, update the Instrumentation runner to com.zutubi.android.junitreport.JUnitReportTestRunner

Click Close .

Next, we need to add a target called fetch-test-report to the test project’s build.xml file. Edit that file and add the following code:

<target name="fetch-test-report">
<xpath input="${tested.project.dir}/AndroidManifest.xml"
expression="/manifest/@package" output="tested.package"/>
<echo>Downloading XML test report...</echo>
<mkdir dir="junitreports"/>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}"/>
<arg value="pull" />
<arg value="/data/data/${tested.package}/files/junit-report.xml"/>
<arg value="junitreports/junit-report.xml"/>
</exec>
</target>


Save and close the file.

Finally, update the second Ant build task in the Configure page of the job in Jenkins. Change the command from

clean emma debug install test

to

clean emma debug install test fetch-test-report

Press Save button.

Click Build Now. The project should build and you should get both coverage and junit report.

Automatic Build

If you want to notify Jenkins immediately commits take pace and trigger a build automatically, you can do this using a post-commit hook. Here’s how.

In the project’s repository, create a file called post-commit in the hooks folder.

Add the following code to the file:

#!/bin/sh
REPOS="$1"
REV="$2"
UUID=`svnlook uuid $REPOS`
/usr/bin/wget \
  --header "Content-Type:text/plain;charset=UTF-8" \
  --post-data "`svnlook changed --revision $REV $REPOS`" \
  --output-document "-" \
  --timeout=2 \
  http://ci.company.com/subversion/${UUID}/notifyCommit?rev=$REV
# let's build the project too
/usr/bin/wget \
  --output-document "-" \
  --timeout=2 \
 http://ci.company.com/job/job/build

Note that on the last line, the general format of the link is

http://ci.company.com/job/YOUR_JOB_NAME_IN_JENKINS/build

Save and close the file. Make it executable and make sure the svn user (e.g. apache) is able to execute it.

That’s it. When you commit henceforth, Jenkins will create a build.

How to Run Raw SQL Query on Zend Framework

This tutorial describes how to run raw SQL script inside a controller on Zend Framework.

For running non-queries, use the following:


Zend_Db_Table_Abstract::getDefaultAdapter()->query($sql);

In order to return a single row, use the following:


Zend_Db_Table_Abstract::getDefaultAdapter()->query($sql)->fetch(); 

To return all rows, use the following:


Zend_Db_Table_Abstract::getDefaultAdapter()->query($sql)->fetchAll(); 

How to get VIM-like functionality in Eclipse

This article describes how to get VIM-like functionality in Eclipse. It’s for the user who enjoys the speed of VIM but also needs to use Eclipse for software development.

There’s a great eclipse plugin called Vrapper. It is obtainable from the Vrapper website. It gives you VIM-like functionality while retaining the power of eclipse. It works pretty well.

How to copy from vim in ssh session to local clipboard on Mac

If you are using a Mac computer and editing vim inside an ssh session, then you can’t copy from the remote vim session to your clipboard using the familiar “+y. This is because the remove vim doesn’t know anything about your local pc’s clipboard. So, how do we copy text from a remote vim session to your local clipboard? There are 2 options :

1. Highlight the text with your mouse then press cmd+c

Note: if you have

set mouse=a

in your .vimrc file, this won’t work as any highlight with mouse switches vim to visual mode making cmd+c invalid. In this case you could press and hold alt before highlighting.

2. Put the text in a temporary file and transfer it to your local pc by scp, then put it in a the clipboard with pbcopy, i.e. go to local terminal and run these commands:

scp username@remotehost /tmp/stuff.txt
cat /tmp/stuff.txt | pbcopy

How to Download Media Files from the Internet

This article discusses an easy way to download media files from the Internet. These include mp3, flv, swf files, etc using Firefox.

Get and install Video Download Helper add-on from https://addons.mozilla.org/en-US/firefox/addon/video-downloadhelper/

After installation, an icon will show on the menu bar. If you browse a web page with downloadable media the icon will light up.

You can then click on the arrow button next to the Video Download Helper icon to see the list of downloadable files·

Then click on the one you want to download. That’s it!

How to install Canon MP250 on Ubuntu 11.10

This article discusses how to install the Canon MP250 all-in-one printer on Ubuntu 11.10

1. Download the printer drivers from the Canon website. You will need to select you Linux under ‘Operating system’ and your language. I choose English in this case.

2. Extract the contents of the archives. You can do this by opening a terminal (ctrl + alt + t), changing to the directory containing the drivers archive and running the following command :
tar xf mp250\ printer\ driver\ 3.40\.tar

I assume the name of the archive is ‘mp250 printer driver 3.40.tar’

Once done, you will have 3 archives created cnijfilter-mp250series-3.40-1-deb.tar.gz, cnijfilter-mp250series-3.40-1-rpm.tar.gz, and guidemp250series-pd-3.40-1_en.tar.gz.

3. Extract the contents of cnijfilter-mp250series-3.40-1-deb.tar.gz using the command :

tar xzf cnijfilter-mp250series-3.40-1-deb.tar.gz

This will create a folder called cnijfilter-mp250series-3.40-1-deb in the same directory.

4. Change to the cnijfilter-mp250series-3.40-1-deb directory. You will find 2 folders (packages and resources) and a file (install.sh).

5. Change to the packages directory. You will see 4 archives :
cnijfilter-common_3.40-1_amd64.deb
cnijfilter-common_3.40-1_i386.deb
cnijfilter-mp250series_3.40-1_amd64.deb
cnijfilter-mp250series_3.40-1_i386.deb

The archives ending with ‘amd64.db’ are for 64-bit machines while those ending with ‘i386.db’ are for 32-bit machines. For the next steps I assume you’re using a 64-bit machine. If using a 32-bit one, do the same on the corresponding files.

6. Double-click cnijfilter-common_3.40-1_amd64.deb. This will fire up Ubuntu Software Centre and install some drivers. Once done, you will see a check mark and the word ‘installed’ for ‘IJ Printer driver for Linux’

7. Double-click cnijfilter-mp250series_3.40-1_amd64.deb. This will fire up Ubuntu Software Centre and install some drivers. Once done, you will see a check mark and the word ‘installed’ for ‘IJ Printer driver for Linux’

8. You’re done. Now test the printer by printing a test page. If all goes well, you will find it works.

Note : I tried using the install.sh file mentioned earlier to no avail, even after commenting out and updating some parts of it as recommended in some articles on the Internet, so I advise not to bother using install.sh.