User Experience and Application on Google App Engine
So, we have been working on this application… web based, data driven, to be used in “social context”. I think today there’s nothing sexier than using the word social.
We designed this application nicely, fantastic by many ways. We were sure of putting this up on a public cloud, just that we were not sure of which one: EC2 or GAE. One of the most riskiest questions to keep open… but really, we were not sure. The only thing we were sure of was Java + jQuery + HTML5 (as much as possible).
EC2 gives you IaaS but then you must manage all the servers, load balancing, failovers. Even if you happen to choose BeanStalk, a lot of work has to be done, specifically database. Thankfully, we now have ElastiCache (launched around August 2011, IIRC) otherwise managing a cluster of Memcache was yet another task for the admins.
GAE provides you PaaS, so you don’t need to worry about doing all the stuff in previous paragraph yourself. Except that you have strong restrictions… a very small subset of Java SE library – specifically, not threads or direct sockets, no JDBC and Datastore, though amazing, is not an easy meat to digest for those not used to. And above all, the server side execution must complete in 30 seconds (now on what are known are front-end servers).
So, we designed our own data-access abstraction so that we can switch EC2 <=> GAE without any hassles. It took a while, but it’s a great thing that we have.
After writing core entities and business logic layer, it was time to start pushing it all up to the user interface. The dashboard – the landing page after login – has to get updates from various “components” in the system. All components worked great, except that the dashboard took somewhere around 1200ms to load for the first time. Note that most of the public resources (images, JavaScript, CSS) were loaded from GAE CDNs.
Just not acceptable!
January 6, 2012
Tags: Cloud, EC2, GAE, Performance, Technology Posted in: Amazon EC2, Google App Engine
No Comments
Card and Deck – Deal and Shuffle
There are a lot of websites showing how do you write code for the classes Card and Deck implementing two key operations – deal and shuffle. And almost all of them have an O(N) solution for shuffling the cards (N = 52, the number of cards). (For example, http://math.hws.edu/javanotes/c5/s4.html and awesome discussion at http://www.codinghorror.com/blog/2007/12/shuffling.html, or just search on Google for “card deck deal shuffle code” or even “card deck deal shuffle code optimized“)
Recently, somebody asked me – if there’s a better solution.
Now let me just generalize this problem – we have a collection of N items which need to dealed and shuffled. The order in which the items are dealed should not be predictable (that’s what randomness means, right?). Think… can we do it in O(1) with minimal memory? I did it!
For the sake of simplicity, let’s number the cards 1-52 and define the interface for the IDeck as follows:
interface IDeck
{
void Shuffle(); //Shuffles so that the "fresh" deal can start
int Deal(); //Gives me the next card
int Remaining { get; } //Returns the number of cards remaining in the deck
}
Now, let’s look at the following solution…
We need to have an array that will hold these cards, in this case – an array of int – int[] cards.
Then we need an index/count indicating how many cards have been dealt or remaining – int index.
Now, dealing is simple – start picking up the items from the start / end and update value of index appropriately. For example, we can initially have index = cards.length - 1 and decrement it each time deal is done.
But the problem is that during shuffle, we need to randomly put all the cards in the array cards. Now, to randomize and shuffle, we’ll need another temporary array so that we can start picking up the cards randomly and place them across.
Well, almost all of the solutions that Google gave me do the same.
Let’s approach is slightly differently… focus on what we need.
December 26, 2011
Tags: Algorithm, Code Posted in: Technology
2 Comments
HTML5 and Social Games
On 1st October was jsFoo by HasGeek, and I had a talk on “Effective Gaming techniques using HTML5: Single-player, multi-player and Social Games”.
Here are the slides…
October 4, 2011
Posted in: Technology
One Comment
July with 5 weekends once in 823yrs – Know the truth
For last few days, I have been getting spam about the awesomeness and rarity of July with 5 weekends… something that is being claimed to happen once in 823 yrs. It’s all bullshit. Search on Google for “823 years July five weekends” something around it, and you’ll see great results. Once such URL is http://www.google.com/search?q=823+years+july+five+weekends. Even Times of India (the ad and sex newspaper of India) write this in their article here.
I happen to be a mathematician at heart. Reading these news, I got reminded of a calendar that I given to my father by an MR when I was in VIIth standard – that’s about 18-19yrs ago. The calendar was of some 150+ years. I was excited to get such a calendar. And then observing it closely and using some maths – though very trivial now – I realized the Gregorian Calendar repeats itself every 28yrs.
This is how… if there were no leap years, each year would have been for 365 days, that means, the calendar will advance by 1 day a week every year (365 mod 7 = 1), and hence will repeat every 7 yrs. Because every 4th year is a leap year, the reptition happens every LCM(4, 7) = 28yrs.
And in may be around 15-20minutes, I created a infinitely-usable calendar.
Ok. I admit, I have not taken into account 100yr factor… but it can be taken up.
Coming back to this 823yrs crap, and to verify my stats, I just went to TimeAndDate.com and this is what I got: http://www.timeanddate.com/calendar/?year=1983 as the calendar of 1983!(2011 – 28 = 1983).
Check it out closely… the month of July. What does it read — 5 weekends.
And so goes the calendars of 2011 +/- 28*n where n can be any number. Let’s just checkout the calendar of 2011 – 28 * 10 = 1973. Visit this: http://www.timeanddate.com/calendar/?year=1731 and you’ll know the truth.
Thanks for being enlightened! Yet another reason why I hate media… these uneducated people write news that impacts the masses. IMHO, these newspapers and media houses should be banned… donno about any criminal cases of misinformation or anything can be put against them!
July 3, 2011
Posted in: Feedback on News, Personal
3 Comments
Android
I have always wanted to a start a series on Android, noting that I have now spent over 3yrs working on Android, mainly at the application level (what you touch and play with on the device) and at times at the middleware level (drivers and codecs, that runs without your knowledge in the background).
So, I finally I have a go… as and when I get time, I will be writing articles on various application development aspects relating to Android. And no, I am definitely not planning to write another “Hello World” tutorial. You can search on Google for several such tutorials on the web.
I will be writing the stuff on the aspects “Beyond Hello World”.
March 30, 2011
Tags: Android, Technology Posted in: Android, Mobile, Technology
No Comments
