Tuesday, March 25, 2014

Practical Assessment - basics of CORBA

Requirements:


"You are required to develop an application that allows users to register for an online
account with the Kamarad mobile operator. The Kamarad online account will allow
users to top up their account, and to get the credit balance."

Solution:


kamarad.idl

module kamarad {
    struct KamaradAccountDetails {
     string name;
     string address;
     string phoneNumber;
     string bankAcNumber;
     double credit;
     string uniqueId;
    };


    interface OnlineKamarad {
     void register(in KamaradAccountDetails accountDetails, out any uniqueId);

     void getAccountDetails(in string uniqueId, out KamaradAccountDetails accountDetails);
     void topupAccount(in string uniqueId, in double amount)
 
    };
};


OnlineKamaradImplemantation.java

import kamarad.*;
import org.omg.CORBA.*;
import java.util.*;

import java.util.Hashtable;

public class OnlineKamaradImplementation implements OnlineKamaradOperations {
    private ORB orb;

    //create HashMap to store userData
    Hashtable<String, KamaradAccountDetails> hashTable = new Hashtable<String, KamaradAccountDetails>();

    public OnlineKamaradImplementation (ORB orb) {
        this.orb = orb;
    }


    public void register (kamarad.KamaradAccountDetails accountDetails, org.omg.CORBA.AnyHolder anyUniqueIdHolder) {
        Any anyUniqueId = orb.create_any();


        // Add logic to allocate a new unique id for this registration and store the new account
        // for subsequent retrieval
        String uniqueId = UUID.randomUUID().toString();
        uniqueId = uniqueId.substring(uniqueId.length() - 6);

        anyUniqueId.insert_string(uniqueId);
        anyUniqueIdHolder.value = anyUniqueId;
  accountDetails.uniqueId = uniqueId;
  hashTable.put(uniqueId, accountDetails);
    }


    public void getAccountDetails (String uniqueId, kamarad.KamaradAccountDetailsHolder accountDetailsHolder) {
        // Look up and retrieve the account details for this user
        KamaradAccountDetails accountdetails = new KamaradAccountDetails();
        // Put the account into a holder object for returning
        accountDetailsHolder.value = hashTable.get(uniqueId);
    }

    public void topupAccount (String uniqueId, double topup) {
        // Look up the account details for this user and update the credit by adding the
        // specified top-up to the exDsting balance

        KamaradAccountDetails accountDetails = hashTable.get(uniqueId);


        accountDetails.credit  += topup;
    }
}



OnlineKamaradRegister.java

import kamarad.*;
import org.omg.CORBA.*;
import java.io.* ;
import java.util.* ;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;


public class OnlineKamaradRegister {

    public static void main(String args[]) {

        try{
            ORB orb = ORB.init(args, null);

            //Obtaining the object reference to the Name Service            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
            //Narrowing the object reference of the Name Service to the correct Type            NamingContext rootCtx = NamingContextHelper.narrow(objRef);
            //Creating a name of the desired object that we want to get the object reference from the name server            NameComponent[] path = new NameComponent[2];

            path[0] = new NameComponent("Kamarad", "Context");
            path[1]    = new NameComponent("OnlineKamarad", "Object");

            org.omg.CORBA.Object objRefKamarad = rootCtx.resolve(path);
            // Converting the retireved object reference from the Name Service to the correct type            OnlineKamarad kamaradRef = OnlineKamaradHelper.narrow (objRefKamarad);
            // Prompt user for account details or get them as command line arguments            String name = getName();
   String address = getAddress();
            String phone = getPhoneNumber();
            String bankAcNumber ="";
            double initialCredit = 0.0;


            // Create our account details object            KamaradAccountDetails accountDetails = new KamaradAccountDetails(name, address, phone, bankAcNumber, initialCredit, "REGISTER accountThingy");
            // Creating an any holder that will hold the unique id parameter from the register operation call            AnyHolder anyUniqueIdHolder = new AnyHolder();
            // Register the user            kamaradRef.register(accountDetails, anyUniqueIdHolder);
            // Display the newly allocated user id            String uniqueId = anyUniqueIdHolder.value.extract_string();
            System.out.println("User registered as: " + uniqueId);

        } catch (Exception e) {
                System.out.println("ERROR : " + e) ;
                e.printStackTrace(System.out);
        }
    }


    private static String getName(){
      String name = null;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      System.out.print("Enter Your Name:");
      try{
       name = br.readLine();
      }
      catch (IOException ioe){
       System.out.println("Error trying to read your name!");
             System.exit(1);
      }
      return name;
     }


     private static String getAddress(){
      String address = null;

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.print("Enter Your Address:");
      try{
       address = br.readLine();
      }
      catch (IOException ioe){
       System.out.println("Error trying to read your adress!");
             System.exit(1);
      }
      return address;
     }


     private static String getPhoneNumber(){
      String phoneNumber = null;

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.print("Enter Your Phone Number:");
      try{
       phoneNumber = br.readLine();
      }
      catch (IOException ioe){
       System.out.println("Error trying to read your phoneNumber!");
             System.exit(1);
      }
      return phoneNumber;
    }
}

Wednesday, March 19, 2014

Gay Dublin Guide

Hi everyone, here's a nice app for those traveling to Dublin.

 
 
You can see more details in this video shot.
 



You can downloaded at http://appshopper.com/travel/gay-dublin-guide.

Wednesday, February 26, 2014

Phonograph - New technology meets the old

Shot with Nikon D7000


Rolling links - CSS3 + JS example

"Rolling link" is a great example of CSS and JS combination. I found it the other day at this great site http://www.webdesignerdepot.com/2013/09/the-ultimate-guide-to-flat-design/ full of flat-ui design inspirations.

This tutorial shows you how to create catchy "rolling links".

 

What we need

  1. Notepad++ (or any other html editor of your choice)
  2. jQuery  (you can download jQuery file from  http://jquery.com/download/ or you can add this markup into head section of your html file <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"> </script>

 

Create Html file


We'll start with the simple html file. Let's save it as index.html

<!DOCTYPE html>
<html>
   <head>
       <title>Fancy Rolling Link</title>

   </head>
   <body>
   </body>
</html>

Add div box into body section. We will apply CSS3 and JavaScript to everything inside the <a> tags, in our case it'll be "Flat design".

<div>
    <article>
       We love <a href="#" >Flat design </a>.
    </article>
</div>


Styling rolling links


You can create a CSS file or else you can include CSS into head section of he HTML file. We'll add this CSS markup to our html file in this tutorial.  

 <style>
  
a {
   color: #9b59b6;
   font-weight: bold;
   text-decoration: none;
   }
  .roll-link {
   display: inline-block;
   overflow: hidden;
   vertical-align: top;
   -webkit-perspective: 600px;
      -moz-perspective: 600px;
       -ms-perspective: 600px;
           perspective: 600px;
   -webkit-perspective-origin: 50% 50%;
      -moz-perspective-origin: 50% 50%;
       -ms-perspective-origin: 50% 50%;
           perspective-origin: 50% 50%;
   }
   .roll-link:hover span {
    background: #9b59b6;
    -webkit-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
       -moz-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
        -ms-transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
            transform: translate3d( 0px, 0px, -30px ) rotateX( 90deg );
    }
   .roll-link span {
    display: block;
    padding: 0 2px;
    position: relative;
    -webkit-transition: all 400ms ease;
       -moz-transition: all 400ms ease;
        -ms-transition: all 400ms ease;
            transition: all 400ms ease;
    -webkit-transform-origin: 50% 0%;
       -moz-transform-origin: 50% 0%;
     -ms-transform-origin: 50% 0%;
      transform-origin: 50% 0%;
    -webkit-transform-style: preserve-3d;
       -moz-transform-style: preserve-3d;
        -ms-transform-style: preserve-3d;
            transform-style: preserve-3d;
    }
    .roll-link span:after {
     background: #9b59b6;
     color: #fff;
     content: attr(data-title);
     display: block; 
     left: 0;
     padding: 0 2px;
     position: absolute;
     top: 0; 
     -webkit-transform-origin: 50% 0%;
        -moz-transform-origin: 50% 0%;
         -ms-transform-origin: 50% 0%;
             transform-origin: 50% 0%;
     -webkit-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
        -moz-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
         -ms-transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
             transform: translate3d( 0px, 105%, 0px ) rotateX( -90deg );
     } 
 </style>


JavaScript


This simple JS function is executed immediately after the DOM has been fully loaded. It finds all <a> tags, adds class="roll-link" to it and encloses text inside <a> tag with <span> tags. 


<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"> </script>
<script>
  jQuery(document).ready(function(){
   initFancyRollingLinks();
  });

  function initFancyRollingLinks(){
   jQuery('a').each(function(i,e){
    var link = jQuery(e);
    link.addClass('roll-link');
    link.html('<span data-title="'+ link.text() +'">' + link.html() + '</span>');
   });
  };
 </script>


Demo


Demo to this tutorial is not available at the moment. But you can see working version on this site http://www.webdesignerdepot.com/2013/09/the-ultimate-guide-to-flat-design/


Friday, November 2, 2012

Mobile Website vs Hybrid App comparison

Mobile Website  App

 Strengths
  •  cheapest / easiest / fastest to develop
  •  works across all platforms
  •  updates are immediately available to end users
  •  can work offline
 Weaknesses
  •  cannot use device's native hardware features
  •  slower that native apps 
What can we access?
  •  geolocation api (GPS)
  •  device orientation (accelerometer)
  •  battery
  •  web audio/video (NOT supported by majority of older browsers ) 

Hybrid App

Strengths
  •  code once and deploy the app to multiple platforms
  •  can work offline
  •  content can be updated easily
 Weaknesses
  •   partial access to the device's native hardware features
  •   major changes to the app will require the user to update the app
 What can we access? (using PhoneGap for example)
  •  accelerometer
  •  camera
  •  capture (media files using device's media capture apps)
  •  compass
  •  connection
  •  contacts (devices contact database)
  •  device (device specific info)
  •  events
  •  geolocation
  •  globalization
  •  media (record and play back audio files)
  •  notification
  •  splashscreen
  •  storage