Colorado Give Camp

I did the Colorado Give Camp last weekend, still haven’t cought up on my sleep, who cares right ? This is how it went down, we had 6 charities that wanted tech work done. Mostly build a website or add to an existing one. We had about 30 people that could code, DBAs, etc, didn’t have any UX / graphic designers. It would be great to see some people with that telent show up for the next camp. Things progressed pretty much like what you expect at any given hackathon. The charities presented what their project was about then people joined the group for each. Some chose by what charity they wanted to work with others by what technology was being used for the charity. Then the fun began, simply code from Friday afternoon until Sunday at 1pm. At 1pm present the product and get a pad on the back, some swag doesn’t hurt either. The top prize was $1000 worth of stuff at Pluralsight.com, too bad I didn’t win it :(

I was on a team that used C#, Entitiy Framework, MVC, Razor, MsSql server, Git, TFS and Twitter bootstrap. My first time using MVC and Entity framework on a real project, it was good to get some experience with it. The only thing that didn’t work out so well was the Git repository, after some scratching of heads we turned to TFS. We used TFS ( free for 5 users ) hosted at VisualStudio.com thanks Microsoft. Using Git requires a different thinking then what your used to working with other repositories. Other than that we got a lot accomplished and the charity has a system they can use going forward instead of using Excel spreadsheets.

Unexpectedly our Congress man Jared Polis stopped by and hung out for a bit, it was good to see him. Here is a group photo including Jared.

Databases are for …

Something I read recently reminded me of this.

At one point I was freelancing in New York city. This guy calls me up and wants to see if I can come over and take a look at this pogram “one of his coworkers” wrote. I’m like sure what’s going on with it, well I just want to make sure best practices were followed, we also seem to have some memory problems. Mind you this was early Java days and the program was written in Java. I show up in his office and he takes me to this laptop “the other guys laptop” I looked around but never saw the other guy. The IDE was open and the project loaded, lets take a look. I poked around some, the code seemed ok, the flow was fine.

But then I saw it, and I go hmmmm…. yea, what is it ? do you realize that all the data from the database is loaded into memory, right here. That’s what it’s doing, right ? Yes, that way it’s super fast…. but here is the thing when we have small amount of data the program works fine, but now I have to put it into production and we are using much more data. I tried my best holding a straight face and talking with him about databases and how they are great for querying for data. I left his office and promised to write up some suggestions about the code, how to make it better. I think he gave me a copy of the code to analyze. I wrote a list of 10 or so things and emailed it over to him. Needless to say the first suggestion was about not loading all the data from the database into memory !

A few days later I get an email from him which apperently he sent to everybody that had come over to evaluate the code, 5 or so consultants. He was asking for a short term fix, as the program needed to be demonstrated to management and he was still getting these memory errors when running with the bigger set of data. One of the consultants suggested a solution, increase the memory size for the JVM. It seems to have worked fine as I never got another email from him again, it’s great when you can find resonable fixes to your problems.

GoogleTv getting started

There were some GoogleTv guys ( Les Vogel and Paul Carff ) coming to town to hold a session on GoogleTv development. This event was facilitated by the local Android meetup group. Naturally I wanted to attend, I haven’t looked at GoogleTv before so why not jump on the oppertunity to get to know GoogleTv development a little. To my surprise I was handed a nice GoogleTv T-shirt and a Vizio GoogleTv device as I walked in the door, w00t !

Lets look at developing for the device, it’s recommended that you develop on Linux, as the Google Tv emulator uses KVM virtual machine to run in, most people use Eclipse as the IDE. Other than that setting up for coding for Google Tv is pretty much the same as coding for Android. First download and install the Android SDK, then download and install the Google Tv extension. Here is a little snag I ran into, when running the Android SDK Manager you will have to toggle the radio button to sort by repository rather than API level to find, “Google Inc. ( dl-ssl.google.com )” in the list. Once you see that you can find “Google Tv Addon” below, that’s the one you want, check the box and install the package. With that out of the way, next you need to setup a Android Virtual machine using the Android Virtual Device Manager. When you create your new GoogleTv AVD see if you can set the data partition to 1024 instead of 128, this will help with errors about the emulator not having enough space for installing your application. Otherwise you can also run it from command prompt, after you add the /tools and /platform-tools directories from the sdk to your path. Like this

$ emulator -avd googleTv -partition-size 1024

For some your keyboard might not work either in the Emulator, in order to activate that add Keyboard support in the harware properties of the AVD configuration and set it to “yes”. Now you should be good to go, you might have to start the Emulator from command prompt depending on your setup. Now in your Package Manger, you can look for KVM and install. You will also need computer that supports BIOS virtualization extensions, in order to check on that run

$ kvm-ok

you should see some message like “KVM acceleration can be used” if your good, otherwise you will get some kind of error.

That’s the Emulator at work

I wrote a sample app that plays different media over the internet, it turns out the emulator is not as capable of playing different formats as the regular Android emulator. Most of my streams played on the Android emulator but not on the GoogleTv emulator. It’s a good thing that they gave us GoogleTv devices when we attended the labs event at Google, now I can start coding and try it on the actual device which will work better than on the emulator. The Vizio GoogleTv is only $99 at the moment, if your going to develop for GoogleTv I would recommend getting the device to test on rather than using the emulator.

A lot of Android applications will work just fine on GoogleTv without any modifycation. The most important thing to keep in mind is that the GoogleTv display is Landscape only and the resolution is usually in the Tv format 1280 x 720 or 1920 x 1080. For example my Android BeerWidget runs fine on the GoogleTv without any modifycation.

Linux daily driver

As I posted previously , I was thinking about switching my newest computer I use day to day to Linux instead of Windows. Recently I did the big switch, not really that big when you consider Mac, Linux and Windows are starting to look and feel pretty similar to each other. In any case I installed the latest Linux Mint 13 about a month ago and I’m very happy. I was cautious and installed Win Xp in a Virtual machine with the programs I was already using on my Win xp, frankly I haven’t turned it on for a few weeks now. After the install I plugged in the old Win hard drive, to my surprise Linux mounted it for me without any tinkering. I can access all the windows files directly from the hard drive, sweet.

I was most worried about video production on Linux, I knew Mint takes good care installing all the video codecs, no problems there. I found WinFF which is great for any conversion between different video formats. The video editing software I like the best are Cinalerra, OpenShot and Kdenlive, in my case I like Kdenlive best. I did a couple of short videos with it that came out pretty good. The only complain is that the finer control of video and audio is not as easy as in Adobe Premier. I still have Premier on the Win Xp running in virtual machine, but I’m trying not to reach for it. The overall productivity on the desktop has gone up and one can’t beat the workspaces. With the workspaces you can group together programs your using together. Often I find myself having a browser and email in one workspace. Development tools in another and sometimes terminal, database tools in another. Things seem to be more readily available to you than in Windows. I also like the look and feel, graphics are smother and better overall.

To answer the question I was going to answer. Am I happier on Linux than Windows, do I like the switch ?
Yes, you bet ! I just can’t figure out why I didn’t switch sooner. I might have something to do with old habits. You just get used to something and you stick with it. In the past when I would install Linux on my old box there was always some tinkering under the hood. Not good for the average user that is not technically inclined. However with my Mint 13 install I have not had to tinker under the hood for anything at all, it just works !

iPhone sample code

I figured I would try out developing on Mac Os making an iPhone app. My first experience on the Hackintosh building an application ( my first blog post from it as well ). Anyway, I downloaded the SDK got xCode going and followed some Hello world tutorial. I feel Hello world is just too simple to get a feel for the environment and Objective-C. So I decided to port my HandiCap Android sample to the iPhone, should give me enough time to play with xCode and get a feel for it.

As I started up xCode and started coding first I noticed was the keyboard shortcuts which are strange when using PC keyboard on the Mac, I run the Mac in a VM. I understand I can map that anyway I want so that shouldn’t be a problem if I decide to do some more development. As I knew this sample was going to be short I didn’t bother changing it. When using xCode it doesn’t really feel like an IDE rather a collection of different tools. I had a hard time finding out how to set controls on a view in the beginning once I got the appropriate tools open it was pretty much straight forward. One thing that I don’t really understand is when you link controls to the File owner, why does that link your controls to your code view ? why not link that to the view itself as that is where the code resides ? I guess I will figure that out later as time goes on.

So let’s take a look at the code, first you need to reference the controls in the header file that you already setup in the Interface builder. Yes you need to do that by hand, it is not taken care of by the IDE, more integration is needed on the IDE’s behalf if you ask me. Note the UITextFieldDelegate tag on the controller, this one is needed to hide the keyboard when Return is pressed along with code in the class file.

#import <UIKit/UIKit.h>

@interface HandiCapViewController : UIViewController <UITextFieldDelegate>
{
       
        // First half
        IBOutlet UILabel *lbPlayer1;
        IBOutlet UITextField *txPlayer1;       
        IBOutlet UILabel *lbPlayer2;
        IBOutlet UITextField *txPlayer2;
       
        // Second half
        IBOutlet UILabel *lbWinPlayer1;
        IBOutlet UITextField *txWinPlayer1;
        IBOutlet UILabel *lbWinPlayer2;
        IBOutlet UITextField *txWinPlayer2;
}

- (IBAction) btCalculate_Clicked:(id)sender;

@end

Then we start coding in the class ( .m ) file

#import "HandiCapViewController.h"
#include <tgmath.h>

@implementation HandiCapViewController

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
       
        // Disable the two result fields
        txWinPlayer1.userInteractionEnabled = FALSE;
        txWinPlayer2.userInteractionEnabled = FALSE;
}

- (void)didReceiveMemoryWarning {
        // Releases the view if it doesn’t have a superview.
    [super didReceiveMemoryWarning];
       
        // Release any cached data, images, etc that aren’t in use.
}

- (void)viewDidUnload {
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
}

// Shut down the keyboard
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
        NSLog( @“textFieldShouldReturn start”);
       
        // This code should be made dynamic instead of ugly if / else
        if( textField == txPlayer1 )
        {
                [txPlayer1 resignFirstResponder];
        }
        else if( textField == txPlayer2 )
        {
        [txPlayer2 resignFirstResponder];
        }

        return TRUE;
}

               
// Calculates handicap
-(void) calculate:( double *) pdaPlayers;
{
        // STRONGER is lower handicap
        // See who is better rated coming in,
        Boolean bStrongerFirst =  pdaPlayers[0] < pdaPlayers[1];
        // Holds results
        double strong_race, weak_race;
       
        if( bStrongerFirst )
        {
                // What’s the race
                weak_race = MAX(2, 6floor( pdaPlayers[1] ));
                strong_race = weak_race + round( pdaPlayers[1] – pdaPlayers[0] );
                // set the slots before returning
                pdaPlayers[0] = strong_race;
                pdaPlayers[1] = weak_race;
        }
        else
        {
                // What’s the race
                weak_race = MAX(2, 6floor( pdaPlayers[0] ));
                strong_race = weak_race + round( pdaPlayers[0] – pdaPlayers[1] );
                //  Set the slots before returning
                pdaPlayers[0] = weak_race;
                pdaPlayers[1] = strong_race;
        }
}

- (IBAction) btCalculate_Clicked:(id)sender
{
        NSLog( @“Button clicked start”);
       
        double dPlayerOne = [txPlayer1.text doubleValue];
        double dPlayerTwo = [txPlayer2.text doubleValue];

        // What is the race
        double players[2] = { dPlayerOne, dPlayerTwo };

        // call the function to calculate
        [ self calculate: players ];

        // Display it
        txWinPlayer1.text = [NSString stringWithFormat:@“%.0f”, players[0]];
        txWinPlayer2.text = [NSString stringWithFormat:@“%.0f”, players[1]];

        NSLog( @“Button clicked end”);
}

- (void)dealloc
{
        // First half
        [lbPlayer1 release];
        [txPlayer1 release];
        [lbPlayer2 release];
        [txPlayer2 release];
       
        // Second half
        [lbWinPlayer1 release];
        [txWinPlayer1 release];
        [lbWinPlayer2 release];
        [txWinPlayer2 release];
   
        [super dealloc];
}

@end



I disabled the two result fields in code in the viewDidLoad function as it did not work to set Accessibility Enabled = false from the Interface builder, I don’t know why.
The textFieldShouldReturn function implements the functionality that goes with UITextFieldDelegate in the header file. Simply when the user is done with input in the two text fields he can hit return on the keyboard and the keyboard gets hidden again.
The calculate function is a straight port from the Android code, I only had to include tgmath.h and use the math functions from there.
The btCalculate_Clicked is where all the functionality happens, simply convert the text input from string to double then call calculate and display in the result fields. There is no error checking on the input as I was feeling lazy.
I’m using NSLog to log out to the console, if you want to create a program for production you should maybe write your own logging or use third party library to be able to control the logging level both debug and runtime.
Lastly we have dealloc function where we release the resources the code has been referencing. As pointed out by my friend Mick they are introducing automatic dellocations by the compiler called ARC ( Automatic Reference Counting ) in the near future. That should be welcomed by objective-c developers as they don’t have to keep track of and releasing resources, fewer bugs and more productivity. Some changes discussed on Stack Overflow This experience reminded me of other c / c++ coding with a twist I find the [ class function:param ] syntax strange, but I’m sure I can get used to that.


Below is the app in action and here is the code if anybody is interested HandiCap xCode project

HelloWorld deploy on Google Application Engine 1.6.4

I have seen a bunch of tutorials on how to deploy on the Google App Engine. Let me tell you my experience as well, no it does not take 5 minutes, it’s more like 15-20 minutes to get HelloWorld app going.

First you need application account, go to the location below, login with your Google account and create your own application

https://appengine.google.com/

I use Eclipse ( Indigo ), so let’s look at how you install the Google Engine / SDK and plugin from there. The App Engine just got update to version 1.6.4, naturally that’s what we will use.

Help -> Install New Software

Use the Google Eclipse Indigo ( ver 3.7 ) feed

http://dl.google.com/eclipse/plugin/3.7

You can skip the Android stuff, just check the other 3 check boxes and start your downloads, you will have to Accept the license etc, it’s self explanatory.

After a few long minutes of downloads Eclipse will ask for a restart to install everything properly and you will be in business.

Create a new project,
File -> New -> Other -> Google -> Web Application Project

This will create a sample Google Application Engine project for you.

Then simply choose the blue (g) icon from the toolbar menu, and choose Deploy to App Engine… You will be asked for account info etc, and you will connect this deployment with the app you created in the beginning. Now watch the Console portion as the info about your deployment are displayed until you get success info. Then you can go to your application URL and see your new project in action. To find the URL you can goto My Applications in the Google app dashboard, it will have links on the right ( instances ) click on the link there and it will take you to your app.

Your URL will be something like

http://yourapp.appspot.com/

Its worth to mention that Google will host your app for free, as long as you don’t exceed certain resource limits. They actually have generous free limits, you can read more about the limits and what else you can buy in terms of resources here. You can actually host your own domain on the Google App Engine as long as it’s not a naked domain, That is you will be able to host www.mydomain.com but you will not be able to host mydomain.com. That’s really because of security, you can find further reading about that here.

That’s all, happy coding !