Monday, April 7, 2014

How to be a Glasshole - or not!

Thanks to the folks at Silicon Valley Android meetup and Andreesen Horowitz I got a chance to play with the Google Glass APIs and check it out for myself! While I'm not ready to drop $1500 it does seem promising. If it was a $50-150 accessory for your phone then I think there would be a bigger market for it. But back to tech stuff, there are basically two ways to build apps for a Glass aka glassware - the Mirror API and the Glass Development Kit (GDK).



The Glass uses a timeline metaphor and you have cards on your timeline. The Mirror API lets you manipulate the cards using a REST API while the GDK is basically an extension of the Android SDK.

Mirror API 
This is straightforward REST calls head over to the Google developers console, create a project and turn on the Mirror API (you can turn off everything else). Then create the credentials which you will use.


To play with Glass use the mirror starter project. It is a slightly old school Java web app but easy to understand. I have a forked version with some minor changes on Github. Cards are POSTed via the REST APIs and the Glass registered on the account receives them. There is also a Mirror Playground which is pretty neat (just missing a reply feature).

GDK
This is certainly more involved and like developing for Android. You can create simple cards on the timeline but there are Immersion and Live Card as well. For an Android analogy, Immersion is like an Activity and a Live Card is like a Widget. Maybe more on this later!

Many thanks to @geofree!

Thursday, March 13, 2014

Understanding Recursion

What is recursion - In computer science, it is essentially a method/function calling itself.

What do you think can go wrong? Like infinite loops (using for, while) you could have an endless program that will run as far as memory limits allows. However like we can prevent infinite loops we can have methods call themselves safely. Based on certain conditions we can return from the method. This condition is the base case (there maybe multiple base cases as well). Other rules must be present so that eventually all other cases reduce towards the base cases(s).

Consider the method:
What will be the output if a positive integer is passed in for n?

Suppose we want the sum of first 5 numbers. It can be broken down as follows:
sum(5) = sum(4) + 5
           = sum(3) + 4 + 5
           = sum(2) + 3 + 4 + 5
           = sum(1) + 2 + 3 + 4 + 5
           = 1 + 2 + 3 + 4 + 5

Recursion is a way of thinking - trying to find the solution to a problem by thinking about a smaller version of the same problem. The simplest problem is the base case.

A popular example is the Fibonacci series. The series goes 1, 1, 2, 3, 5, 8, 13...
The first and second terms are defined to be 1. Subsequent terms are the sum of the previous two terms. To define it more formally:

fib(0) = 1
fib(1) = 1
fib(n) = fib(n-1) + fib(n-2)

Writing some code:

Another example - notice the slight difference in the order of calls in the two options. What do you think is the output if both methods are called with the same number?

Factorial - factorial of n is the product of all numbers 1 to n. For example 5! = 5*4*3*2*1=120. More formally:

factorial(0) = 1
factorial(n) = factorial(n-1)*n

Factorial is undefined for negative numbers.

Saturday, January 11, 2014

Java Coding Conventions - Basics

Camel Case
All class names, method (subroutine) names and variable names must use came case. For example: MyClassName, myMethodName, myVariableName.

Note that:
  • Class names must begin with an upper case letter
  • Method and variable names must begin with a lower case letter
File name and Class name
The file name must be the same as your public class <Name>. For example MyClassName.java and public class MyClassName

Indentation
To make code easier to read and understand use a tab or 4 spaces for each “level” your code is indented.
Here is an example. Note how code is indented further in each time a new block of code starts. Also the end “}” aligns with where “{“ began.


Tip: In Eclipse you can use Source > Format to indent your code.

Tuesday, April 9, 2013

1500+ installs!

Noticed on the Google Play console that installs have passed 1500 and more on Amazon! I need to get back to making the promised updates :) Thank you for the support!

Monday, September 10, 2012

Running multiple Couchbase servers on one physical

So it turns out there is no simple way to run multiple Couchbase nodes on a single machine (purely to play around) unlike other DBs  - eg: mongo. I haven't been able to figure out how to change ports on Couchbase either. So using VirtualBox to run couple VMs. Loaded with Ubuntu. Hope this helps you out!

Step 1 - Create two Ubuntu VMs
I'm running under Win 7. Choose your OS and run VirtualBox. Start with creating a new machine, give it a name and pick Linux -> Ubuntu. Pick a small RAM size (default 512M). Follow the wizard to the end. Upon starting it will prompt you for the image - download your version of choice and use that (I am using the Desktop version). Follow the wizard.

In the Settings change the Network to "Host-only Adapter"



You should end up with a 192.168.* address and allows other VMs and the host to have access.

TIP - You can right-click and "clone" to create a second one quickly! - Just change the host name in /etc/hostname

Step 2 - Install Couchbase
Follow the instructions on Couchbase site to setup the first node. Follow the install on http://localhost:8091 to create a new cluster.

On the second node after installing, pick to join a cluster and you should be set!