Tuesday, March 31, 2015

Appium for Mobile Application Test Automation

Recently I came across an opensource mobile testing framework named Appium. The great thing about appium is that it works for native iOS, Android or even hybrid mobile web apps. I tested out Appium for iOS and below is a quick guide to the setup process. The appium documentation is a bit scattered so I thought it better to note down the process I followed here,

Step 1:

Install Appium application on mac by downloading the dmg from http://appium.io/. You can also run Appium from the source code if you like.


Step 2:

Launch the installed Appium application and run the 'doctor' (the icon with a stethoscope) to verify all pre-requisites for Appium are installed and setup already. If you see any errors in the doctor console, first fix them. In my case I needed to set the ANDROID_HOME path before the doctor gave me full approval.

Step 3:

Setup Appium settings to run iOS tests. In order to be able to this you need to have Xcode and Command Line tools installed on your mac. In the iOS settings (the dialog launched when you click on the Apple icon), set the 'App Path' and the 'Bundle Id' for the app you want to test. Also make sure that the Xcode path is set. All the other settings are optional. Note that for the 'App Path' you should give the path to the debug version of the .app file of your app, so that it can be run on the simulator. On OSX Maverick the path to this file can be found in the following location ~/Library/Developer/Xcode/DerivedData/.

Step 4:

Write your Appium test. I used the Appium Java API to write my test. I based my test on an example test provided by Appium ( https://github.com/appium/sample-code/blob/master/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SimpleTest.java ). Note that you can use the Appium Inspector to determine the xpaths of elements in your application. Given below is the code I wrote to execute a login test.


Step 5:

Now you can run your test. Make sure you launch Appium first by clicking on the Launch button of Appium. The junit test you write requires Appium to be running in order to execute.


Wednesday, March 25, 2015

Hosting multiple Cordova plugins in the same git repository

The norm for hosting custom cordova plugins is one plugin per git repository. However there are instances when you would want to host multiple custom plugins inside the same repository. The cordova command for adding such plugins into a cordova project is as given below :

cordova plugin add [GIT_REPO_URL]#[BRANCH_NAME]:[FOLDER_PATH]

example :

cordova plugins add https://harinis@bitbucket.org/harinis/gtnexuscordovaplugins.git#master:attachmentHandler


Note that the FOLDER_PATH should point to the main plugin folder that contains the plugin.xml file.

Saturday, January 24, 2015

Google Summer of Code Reunion 2014


This post is long overdue. I've pretty much given up blogging lately. This however needs to be written because of the amazing event that it is about!:)

In late October last year I had the amazing opportunity to participate at the Google Summer of Code 10 year reunion at San Jose, California. I was one of the past 10000+ GSoC students who randomly won the lottery to the event. Also, I was fortunate enough to be in the US (in New York) around the same time for a work related training. Big thank you to our company VP Developer Evangelists in New York, Brian Carelli for enabling me to attend this event. Thanks to him I was able to take a short flight (5hrs) from New York to San Jose on 23rd October 2014 to attend the biggest and most awesomest tech meetup/conference I have ever attended! Sorry if I am inventing adjectives here!:D

The conference was held at the Marriot Hotel in San Jose, California. I was quite overwhelmed by the conference gathering. There were about 500 participants from all over the world. Developers from some of the awesomest (I am using this word too much here!!) open source products in the world, from Google (they were the hosts after all) to VLC to Wikipedia. Products that make everyones day to day life so much easier and more fun. There were also developers from smaller projects/products that were just as exciting. I cannot list it all here because the list was that extensive. All I can say is that it was the largest gathering of open source developers you can imagine (500 is a lot!).

I met so many interesting people at the conference. There were fresh grads and even undergrads. My roommate was an undergrad at UCBerkley and one the youngest participants at the conference. There were university professors and PhD students. I really enjoy meeting people from diverse backgrounds and cultures. It's always so inspiring. I suppose the most inspiring person at the conference was Linus Torvalds, who was the guest of honor at the conference opening ceremony. I was secretly hoping Larry Page or Sergey Brin would show up. I am a little too young to idolize Linus. The other guest for the opening ceremony was Peter Norvig (Director of research at Google) and pretty much one of the biggest names when it comes to AI. All these big names aside, for me the best meetup at the conference was meeting my GSoC 2010 project mentor KaiRo (Robert Kaiser) from the Mozilla foundation. He had also won the lottery for the event and he even did a session at the conference on test automation. KaiRo said that I was his only GSoC student. I suppose I demotivated him a bit from mentorship since I didn't carry forward with the development team after the GSoC project ended. I regret that I could not continue due to various other obligations. However I hope he will decide to take up GSoC mentorship again because he was an excellent mentor and he has such a wide knowledge in programming and technology in general that any student would be lucky to learn from him:) I know I learnt a lot from the project I did! I am posting the picture I took with him at the conference here, I hope he won't mind:)




There were so many exciting sessions at the reunion 'Unconference' that I would probably need another blog post to cover it all. I hope I get around to blogging all that someday soon because I know it is going to help me out with my work as well. Oh, and the other great thing about the conference was that we got to visit The Google HQ. Unfortunately it was a Sunday so we didn't see many employees but it was still great to see the massive expanse of the Googleplex and take pics with the cool android statues and we even had one of the most energetic Googlers and conference organizers, Stephanie Taylor give us a guided tour!:)




All in all the GSoC 10 Year Reunion conference was an amazing event and I am so happy to have participated. I am posting a pic of one of my favorite conference moments of all here. My Google Glass moment. One of the developers at the conference was kind enough to lend his glass for me to try out. I usually hate glasses but surprisingly I loved Google Glass! Not enough to spend a crazy amount of money and buy one but perhaps 5 years from now when glass is just as commonplace as an iPhone, I just might!:)












Sunday, August 10, 2014

Running Kura on Raspberry Pi over Equinox and Concierge

Given below are screenshots of the Kura web console running on my RPi device. It gives a comparison of Kura running over Equinox vs Concierge.

My RPi configuration:

RPi Model B
RAM 512MB
Memory 4GB (SanDisk Ultra 30MB/s)
Raspbian OS

Initial memory usage is ~195MB


Kura over Equinox ~300MB


Kura over Concierge ~330MB



Saturday, August 9, 2014

Running kura web console on RaspberryPi over Concierge

So I finally managed to get the web console up and running over Concierge! I had to include some equinox dependencies to get the kura services running over concierge. I got a lot of help from the Concierge developer community. Thanks Jan S. Rellermeyer, Tim Verbelen and Jochen Hiller!


Below is the console output when running start_kura.sh script

---------------------------------------------------------
  Framework started in 118.902 seconds.
---------------------------------------------------------


Concierge> bundles
Bundles:
[ 0] (active) org.eclipse.concierge
[ 1] (active) Concierge Shell
[ 2] (resolved) Apache Log4j
[ 3] (resolved) Apache Extras Companion™ for Apache log4j™.
[ 4] (active) slf4j-api
[ 5] (resolved) slf4j-log4j12
[ 6] (active) org.eclipse.concierge.service.xmlparser
[ 7] (active) OSGi Release 4.2.0 Services
[ 8] (active) Supplemental Equinox Functionality
[ 9] (active) Equinox Util Bundle
[10] (active) Configuration Admin
[11] (active) org.eclipse.concierge.extension.permission
[12] (active) Common Eclipse Runtime
[13] (active) Extension Registry Support
[14] (active) Event Admin
[15] (active) Meta Type
[16] (active) Eclipse Preferences Mechanism
[17] (active) Declarative Services
[18] (active) Servlet API Bundle
[19] (active) Jetty :: Utilities
[20] (active) Jetty :: IO Utility
[21] (active) Jetty :: Http Utility
[22] (active) Jetty :: Continuation
[23] (active) Jetty :: Server Core
[24] (active) Jetty :: Security
[25] (active) Jetty :: Servlet Handling
[26] (active) Http Services Servlet
[27] (active) Jetty Http Service
[28] (active) javax.usb API from javax-usb
[29] (active) bundle.name
[30] (active) osgi.cmpn
[31] (active) IO Connector Service
[32] (active) Eclipse Paho MQTT Client
[33] (active) HSQLDB
[34] (active) Apache ServiceMix :: Bundles :: protobuf-java
[35] (active) Commons IO
[36] (active) Apache Commons Net
[37] (active) javax.usb Common from javax-usb
[38] (active) Apache Commons FileUpload
[39] (active) User
[40] (active) org.eclipse.kura.api
[41] (active) org.eclipse.kura.core
[42] (active) org.eclipse.kura.core.cloud
[43] (active) org.eclipse.kura.core.comm
[44] (active) org.eclipse.kura.core.configuration
[45] (active) org.eclipse.kura.core.crypto
[46] (active) org.eclipse.kura.deployment.agent
[47] (active) org.eclipse.kura.core.deployment
[48] (active) org.eclipse.kura.core.net
[49] (active) org.eclipse.kura.linux.clock
[50] (active) org.eclipse.kura.linux.command
[51] (active) org.eclipse.kura.linux.net
[52] (active) org.eclipse.kura.linux.position
[53] (active) org.eclipse.kura.linux.usb
[54] (active) org.eclipse.kura.linux.watchdog
[55] (active) org.eclipse.kura.net.admin
[56] (active) org.eclipse.kura.web


Concierge> services
Services:
Concierge System Bundle
    [Service 1] [org.osgi.service.resolver.Resolver]
[org.eclipse.concierge.service.xmlparser-1.0.0.201407191653]
    [Service 2] [javax.xml.parsers.SAXParserFactory]
    [Service 3] [javax.xml.parsers.DocumentBuilderFactory]
[org.eclipse.equinox.util-1.0.500.v20130404-1337]
    [Service 4] [org.eclipse.equinox.internal.util.threadpool.ThreadPoolManager, org.eclipse.equinox.internal.util.threadpool.ThreadPoolFactory]
    [Service 5] [org.eclipse.equinox.internal.util.timer.Timer]
[org.eclipse.equinox.cm-1.0.400.v20120522-1841]
    [Service 6] [org.osgi.service.cm.ConfigurationListener]
    [Service 7] [org.osgi.service.cm.ConfigurationAdmin]
[org.eclipse.equinox.common-3.6.100.v20120522-1841]
    [Service 8] [org.eclipse.osgi.service.urlconversion.URLConverter]
    [Service 9] [org.eclipse.core.runtime.IAdapterManager]
    [Service 10] [org.osgi.service.url.URLStreamHandlerService]
[org.eclipse.equinox.registry-3.5.200.v20120522-1841]
    [Service 11] [org.eclipse.core.runtime.IExtensionRegistry]
    [Service 12] [org.eclipse.osgi.framework.console.CommandProvider]
[org.eclipse.equinox.event-1.2.200.v20120522-2049]
    [Service 13] [org.osgi.service.event.EventAdmin]
    [Service 18] [org.osgi.service.event.EventAdmin]
[org.eclipse.equinox.metatype-1.2.0.v20120522-1841]
    [Service 14] [org.osgi.service.metatype.MetaTypeService, org.eclipse.equinox.metatype.EquinoxMetaTypeService]
[org.eclipse.equinox.preferences-3.5.0.v20120522-1841]
    [Service 15] [org.eclipse.core.runtime.preferences.IPreferencesService]
    [Service 16] [org.osgi.service.prefs.PreferencesService]
[org.eclipse.equinox.ds-1.4.0.v20120522-1841]
    [Service 17] [org.osgi.service.cm.ConfigurationListener]
    [Service 19] [org.eclipse.osgi.framework.console.CommandProvider]
    [Service 20] [org.apache.felix.scr.ScrService]
[org.eclipse.equinox.http.servlet-1.1.300.v20120522-1841]
    [Service 21] [org.osgi.service.http.HttpService, org.eclipse.equinox.http.servlet.ExtendedHttpService]
[org.eclipse.equinox.http.jetty-3.0.0.v20120522-1841]
    [Service 22] [org.osgi.service.cm.ManagedServiceFactory]
[org.eclipse.equinox.io-1.0.400.v20120522-2049]
    [Service 23] [org.osgi.service.io.ConnectorService]
[org.eclipse.kura.core-0.2.0.201408091943]
    [Service 24] [org.eclipse.kura.system.SystemAdminService]
    [Service 31] [org.eclipse.kura.system.SystemService]
    [Service 32] [org.eclipse.kura.db.DbService]
    [Service 35] [org.eclipse.kura.ssl.SslManagerService]
    [Service 36] [org.eclipse.kura.data.DataTransportService, org.eclipse.kura.ssl.SslServiceListener]
    [Service 37] [org.eclipse.kura.configuration.ConfigurableComponent, org.eclipse.kura.data.DataTransportListener, org.eclipse.kura.data.DataService]
[org.eclipse.kura.core.cloud-0.2.0.201408091943]
    [Service 38] [org.eclipse.kura.cloud.CloudCallService, org.eclipse.kura.data.DataServiceListener]
    [Service 39] [org.osgi.service.event.EventHandler]
    [Service 40] [org.eclipse.kura.cloud.CloudService, org.eclipse.kura.data.DataServiceListener, org.eclipse.kura.configuration.ConfigurableComponent, org.eclipse.kura.cloud.CloudPayloadProtoBufEncoder, org.eclipse.kura.cloud.CloudPayloadProtoBufDecoder]
[org.eclipse.kura.core.comm-0.2.0.201408091943]
    [Service 25] [org.osgi.service.io.ConnectionFactory]
[org.eclipse.kura.core.configuration-0.2.0.201408091943]
    [Service 33] [org.osgi.service.cm.ConfigurationListener]
    [Service 34] [org.eclipse.kura.configuration.ConfigurationService]
[org.eclipse.kura.core.crypto-0.2.0.201408091943]
    [Service 26] [org.eclipse.kura.crypto.CryptoService]
[org.eclipse.kura.linux.clock-0.2.0.201408091943]
    [Service 41] [org.eclipse.kura.clock.ClockService]
[org.eclipse.kura.linux.command-0.2.0.201408091943]
    [Service 27] [org.eclipse.kura.command.CommandService]
[org.eclipse.kura.linux.net-0.2.0.201408091943]
    [Service 29] [org.osgi.service.event.EventHandler]
    [Service 30] [org.eclipse.kura.net.NetworkService]
[org.eclipse.kura.linux.position-0.2.0.201408091943]
    [Service 42] [org.osgi.service.event.EventHandler]
    [Service 43] [org.eclipse.kura.position.PositionService, org.osgi.service.event.EventHandler]
[org.eclipse.kura.linux.usb-0.2.0.201408091943]
    [Service 28] [org.eclipse.kura.usb.UsbService]
[org.eclipse.kura.linux.watchdog-0.2.0.201408091943]
    [Service 44] [org.eclipse.kura.watchdog.WatchdogService]


Concierge> DEBUG 17 ServiceReg.getService(): service 'org.eclipse.kura.position.PositionService' is used 2 time(s), object = org.eclipse.kura.linux.position.PositionServiceImpl@1d0440
DEBUG 17 ServiceReg.getService(): service 'org.eclipse.kura.net.NetworkService' is used 4 time(s), object = org.eclipse.kura.linux.net.NetworkServiceImpl@1bf724e
DEBUG 17 ServiceReg.getService(): service 'org.eclipse.kura.system.SystemAdminService' is used 3 time(s), object = org.eclipse.kura.core.system.SystemAdminServiceImpl@65a4ba


Concierge>     

Saturday, August 2, 2014

Debugging OSGi Declarative Services

Figuring out why the declarative services in your osgi application haven't resolved can be a bit tricky sometimes. If you are using the equinox ds implementation you can use the built in debug mode to figure out the underlying issues.

Simply set the below properties

equinox.ds.debug=true
equinox.ds.print=true

Since I am running equinox ds over concierge I specify these properties as,

-Dequinox.ds.debug=true
-Dequinox.ds.print=true

in the concierge init.xargs launch configuration file.

References:

http://eclipse.dzone.com/articles/dependencies-and-services-osgi
http://hwellmann.blogspot.com/2009/04/getting-started-with-osgi-declarative.html



Sunday, July 13, 2014

Measuring bundle start time over an osgi framework

For the kura project I am required to measure the performance of kura on equinox vs concierge framework. For this I need to analyze the bundle startup times, cpu usage and memory usage. In order to measure the time taken by each kura bundle to start over equinox framework vs the time take for concierge, I implemented a bundle that will act as a listener for bundle events. Given below is the source code.

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;

public class Activator implements BundleActivator, BundleListener {
   
    private long trackedStartTime = 0;

    public void start(BundleContext context) throws Exception {
        trackedStartTime = System.currentTimeMillis();
        System.out.println("Starting Bundle Listener - " + context.hashCode());
        context.addBundleListener(this);
    }

    public void stop(BundleContext context) throws Exception {
        System.out.println("Stopping Bundle Listener - " + context.hashCode());
        context.removeBundleListener(this);
    }

    public void bundleChanged(BundleEvent event) {
        if(event.getType() == BundleEvent.STARTED){//a bundle started. update last start time
            long bundleStartTime = getBundleStartTime();
            long bundleMemoryOnStart = getBundleMemoryForStartup();
            String symbolicName = event.getBundle().getSymbolicName();
            if(symbolicName.contains("kura")){//only print out kura bundle startup times
                System.out.println(symbolicName + " , STARTUP TIME : "+ bundleStartTime);
            }
        }

    }
   
    private long getBundleStartTime(){
        long currentTime = System.currentTimeMillis();
        long bundleStartTime =  (currentTime - trackedStartTime);
        trackedStartTime = currentTime;//set tracker time to this bundle start time
        return bundleStartTime;
    }

}


Reference : http://eclipsesource.com/blogs/2013/01/23/how-to-track-lifecycle-changes-of-osgi-bundles/ 

Monday, June 9, 2014

Javascript intellisense in Eclipse using JSDT

JSDoc annotations are a great way to access code completion in Javascript projects in Eclipse. Given below is a link that describes JSDoc annotations in detail..

https://wiki.servoy.com/display/public/DOCS/Annotating+JavaScript+Using+JSDoc;jsessionid=E3E8DE328428CF512BFA4BB158CE0821

Wednesday, May 14, 2014

Running Concierge OSGi framework

To quote the Eclipse Concierge project page, "Concierge is a small-footprint implementation of the OSGi Core Specifications R3 standard optimized for mobile and embedded devices". It was initially developed by Jan S Rellermeyer. Given below is a basic guide for running concierge. 

1. Get the latest concierge source from http://git.eclipse.org/c/concierge/org.eclipse.concierge.git
2. Run the ant program inside the concierge root directory to build the concierge framework bundle.
3. By default concierge runs with no shell, to run concierge with a shell you will need the shell bundle which can be downloaded along with the previous release version of concierge available here: http://sourceforge.net/projects/concierge/files/.
4. To instruct concierge to launch with a shell you will need a startup properties file. Follow the instructions here : http://concierge.sourceforge.net/properties.html.
5. Now you can run the concierge bundle you built in (2) and use the launched framework to install and run other OSGi bundles.


Here is a list of shell commands for Concierge taken from http://sourceforge.net/p/concierge/code/HEAD/tree/trunk/bundles/shell/src/main/java/ch/ethz/iks/concierge/shell/Shell.java#l495

bundles
services
properties
filter
install
start
stop
uninstall
update
headers
restart
quit
exit
printenv


Learning OSGi

It's the 10th anniversary of GSoC and as a part-time masters student I have been selected to participate in the 'Kura' project for eclipse. The project I am working on is an OSGi based project that provides a framework for running M2M applications. This will be my first time working in depth with OSGi so I have a lot of reading to do! Given below are the resources I am using:)

Friday, March 21, 2014

Debugging exported eclipse plugins

When working in eclipse plugin development one thing you come across often is the plugin runs as expected when debugging from the Plugin Project, but when you install the exported plugin things just don't work. Reasons for this could be anything as simple as not specifying external jar files in the 'Runtime' tab of the plugin.xml file to something as unexpected as a runtime exception. The easiest way to debug such issues is to launch eclipse with the console running.

Command to launch eclipse with console:

eclipse -debug builder.options

Now all plugin log messages and exception messages will be displayed in the console.

For more details on debugging eclipse plugins for the end user please see:
http://www.ibm.com/developerworks/rational/library/06/0221_rossner/

Cordova plugin to display image files full screen inside your iOS/Android app

A while ago I blogged about a customized HTML5 canvas/js implementation for full screen image display inside your cordova app. The advantage of this method was that it retained the application header and footer, however the drawback was that pinch zoom did not work well under device orientation changes. For anyone who doesn't want to deal with the complexities of a canvas based pinch zoom capable js solution a much simpler solution is to utilize iOS and Android native capabilities to launch the image in the default image viewer, from inside your application.

iOS

Inside a cordova plugin for ios implement the following call UIDocumentInteractionController.

        NSString *fullPath = @"specify file path here";
        NSURL *URL = [NSURL fileURLWithPath:fullPath];
       
        if (URL) {
            UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
             [documentInteractionController setDelegate:[[[UIApplication sharedApplication] keyWindow] rootViewController]];
            if (![documentInteractionController presentPreviewAnimated:YES])
                NSLog(@"Failed to open document in Document Directory");
}

Also let your cordova applications main view controller implement the UIDocumentInteractionControllerDelegate.

Android

Inside a cordova plugin for android implement the following call to an intent

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.parse(filePath), "image/*");
context.startActivity(intent);

You will need to implement threading to prevent the UI thread from hanging.

For details on setting up a Cordova plugin inside iOS/Android refer to http://devgirl.org/2013/07/17/tutorial-how-to-write-a-phonegap-plugin-for-android/



Tuesday, November 26, 2013

Jquery Mobile Pinch Zoom Image with Fixed Headers

Recently I came across the requirement to build a mobile app with image zooming capabilities. It needed to be something similar to what Twitter uses for displaying tweeted images. Twitter of course codes it using native iOS and Android APIs. My requirement was to do the same thing using jquery mobile so it would be easily cross platform. Lucky for me I came across an open source JQM plugin that allows for pinch zoom of images. With a few tweaks I managed to get this working with JQM. I load the image content dynamically in the 'pageshow' event so that the image content can be altered as required for the page.

Library for pinch zoom (uses html canvas)

https://github.com/rombdn/img-touch-canvas

Modified version with fixed headers for JQM

https://github.com/hariniachala/jqm-image-zoom/tree/master/www

Modify image and canvas parameters as required to suit your application requirement..




Tuesday, June 11, 2013

Push Notifications in iOS Using Cordova + Java APNS

Below is an overview on implementing push notifications in a cordova (phonegap) ios application..

1. Setup the required provisioning profile for developing push notifications in member center of apple developer site.
https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194-CH104-SW1

2. Setup your Cordova iOS application

- Download the latest version of cordova from http://cordova.apache.org/#download (the version I used was 2.8).
- Unzip the downloaded cordova folder and follow the instructions in the README file of the cordova-ios folder to setup a cordova ios project. Be sure to set the project bundle id to be the same as the one you gave for the provisioning profile setup for push notifications.

3. Create a iOS plugin for enabling push notifications in cordova ( currently this functionality isn't built in to cordova)

Follow the tutorial http://cordova.apache.org/docs/en/edge/guide_plugin-development_index.md.html#Plugin%20Development%20Guide , to create an ios plugin. In the objective c plugin class, call the registration method for push notifications.

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];

4. Setup the required methods in AppDelegate to handle the incoming notifications. See http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1

5. Create the push notification java server and invoke push notifications from it. I used java-apns library and followed this tutorial : http://developement.sebastian-bothe.de/?page_id=40.

Now you will have a complete setup for push notifications in iOS. Creating your own cordova plugin, instead of using an existing plugin gives you more control on how the push notifications will work in the app. Coming from an iOS development background, rather than a web development background, I found building my own objective c plugin to be easier and more flexible.

Tuesday, February 26, 2013

Solving problems using GA in Matlab

This was an assignment in the 1st semester of my MSc. in AI, at University of Moratuwa for the subject 'Evolutionary Computing'.

Given below are some example problems and how I solved them using the GA Optimization toolkit in Matlab 2012Rb.

Problem 1 : solving simultaneous equations

2x+y = 8
x+y = 6



Select 'Double Vector' for the population. Set 'Number of variables' as 2. Set 'Integer variable indices' as [1,2]. Use the correct fitness function and run the GA using the rest of the default values.

The fitness function I used is given below..


function fitness = optimization(params)
fitness1 = 8 - 2* params(1) - params(2);
fitness2 = 6 - params(1) - params(2);
if(fitness1 < 0 )
    fitness1 = -fitness1;
end
if(fitness2 < 0 )
    fitness2 = -fitness2;
end
fitness = fitness1 + fitness2;
end


You can change the default values and observe how the output value changes..

Problem 2 : solving a profit optimization problem

Suppose a fruit seller has 5 different kinds of fruits to sell. They are, mango(m), banana(b), strawberry(s), peach(p), orange(o). Suppose the profit from selling each fruit is as follows, mango - 30,banana - 15, strawberry - 50, peach - 20, orange - 10. If the fruit seller wants to make a profit of 10,000 how many fruits of each type should he sell?


Select Double Vector for the population. Since there are 5 types of fruits. You need a chromosome with 5 genes. Set 'Number of variables' as 5. You should specify that the minimum value for each variable is 0 by giving the lower bound as the vector [0,0,0,0,0]. You should also specify that the variables can only take integer values by giving the 'Integer variable indices' as [1,2,3,4,5]. Next you must specify the fitness function.

The fitness function I used is given below:


function fitness = fruits(params)
m = params(1);
b = params(2);
s = params(3);
p = params(4);
o = params(5);
fitness = 10000 - m*30-b*15-s*50-p*20-o*10;
if (fitness < 0)
    fitness = -1*fitness;
end


After setting these values you can simply run the GA with the rest of the default values. The output I got was,
m = 26, b = 230, s= 19, p = 95, o = 292 which gives a profit of exactly 10,000.

The corresponding graphs are give below..


You can change the default values and observe how the output value changes..

Thursday, January 17, 2013

Monitor HTTP/HTTPS connections on iOS/Android device


This post is basically a guide on how to setup your pc as a proxy to monitor HTTP/HTTPS traffic on an iOS/Android device.

Step 1: Download and install Charles on your pc

http://www.charlesproxy.com/download/latest-release/download.do

You can try the 30 day free trail..

Step 2 :

Check the ip on your pc. Set this as the proxy on your phone, in network settings. Make sure the port is set to 8888 (this is the posrt Charles listens on).

Optional : If you are listening to HTTPS traffic on your phone you need to install the charles certificate on your phone.

see http://www.charlesproxy.com/documentation/faqs/ssl-connections-from-within-iphone-applications/

Step 3 :

Now you can start a recording session in Charles and monitor the web traffic on your phone:) This is an easy way to monitor web traffic from mobile applications.

UPDATE

Since Charles is trial software, I recently switched to using Fiddler2 (Fiddler Web Debugger (v4.4.5.3)).

Setup is similar to Charles but in the case of Fiddler you need to explicitly set permissions in Fiddler allowing remote devices to connect..

Tools -> Fiddler Options -> Connections Tab -> check Allow remote computers to connect :)


Monday, January 14, 2013

Distributed Computing for Artificial Intelligence

I am just completing the 1st semester of studies in the MSc. in Artificial Intelligence offered by the University of Moratuwa. During our first semester we followed a course on Distributed Computing for Artificial Intelligence. The course was lectured by Dr. Janaka Wijayanayake. It was a very interesting course especially since it was very relevant to my current field of work in mobile applications development. Below I am sharing some of the work we did for the subject..





Enhanced by Zemanta

Wednesday, December 5, 2012

Kotta Pora Online Game

Below is the link to a java applet game I made for a class assignment. I've hosted it online on a free web hosting site (000webhost). You will need java in your browser to run the game. The computer player in the game is implemented using a random algorithm which randomly increases/decreases the difficulty level of winning. See if you can win at Kotta Pora!:)

Note : Kotta Pora is a game of pillow fight traditionally played in Sri Lanka for the Sinhala New Year.

http://harini.hostzi.com/game.html (the game may take a few minutes to load..)
Enhanced by Zemanta

Friday, November 30, 2012

Need to free up disk space on Windows C drive?

Just used these cool tools to free up space on C drive on Windows 7.

Delete temp files and free up disk space using this tool..
http://www.piriform.com/ccleaner
I managed to free up ~700MB with this tool.

Find out which of your files/folder are eating up your disk space and delete the useless junk using this tool..
http://windirstat.info/

Thursday, August 9, 2012

Running curl commands in command prompt on windows

Recently I came across the requirement of running curl commands on windows. I was trying out the rackspace (www.rackspace.com) Open Stack API (http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_api_operations.html) on windows. I thought downloading curl.exe was all I needed but turned out I needed to install Cygwin as well. This was because running curl commands on windows command prompt gave me annoying "unmatched close brace/bracket" error messages. Cygwin allows you to run linux style commands on windows inside a Cygwin terminal (see their documentation for details).

So here are the steps I followed :

1. Download curl for windows from http://curl.haxx.se/download.html. Extract the zip file and copy the path to curl.exe. You will need this later.
2. Download setup.exe from http://cygwin.com/. Running this file will guide you through the Cygwin setup.
3. I used all the default settings in the setup wizard for Cygwin except for in the 'Select Packages' dialog, I specifically selected 'curl' which is under the section Net (see image below).

4. After setting up Cygwin I launched the Cygwin Terminal and used the cd command to change directory to the folder having curl.exe. You can use the path you copied in (1).
5. Now you can directly run curl commands inside the Cygwin Terminal :)