Category Archives: Technology

Mojito Hello World now live on Nodester

Mojito Hello World now live on Nodester

My earlier “Hello World” case studies are now live at http://m10v-helloworldapp.nodester.com/

References:

btw, in case you are wondering how I got the Mojit up and running using “node server.js” than the regular “mojito start“, read my last post at http://www.m10v.com/2012/06/yahoo-mojito-on-standard-node-servercloud/

And here goes what it looks like:

Yahoo! Mojito on standard Node Server/Cloud

Yahoo! Mojito on Node Server - Nodester

Getting started with Yahoo! Mojito is pretty straightforward. The only catch is, you must issue a mojito start command.

The problem that we get into is that most of the public Node.js clouds have no idea about this new command. All they know to do is node server.js

Recently I tried my hands with Nodester (www.nodester.com). Standard mojito code failed since server.js only instantiated an HTTP server but did not listen.

With inputs from Terry on making the server listen, I was able to run Mojito application on Nodester.

The original discussion between Terry and myself is at http://groups.google.com/group/nodester/browse_thread/thread/e35c7eb3b122ff01

The running application is provisioned at http://gvtestapp.nodester.com/@HelloMojit/index

UPDATE: The application is now available at http://gvtestapp.nodester.com/

Yahoo! Mojito: Part 2 – Enhanced Hello World!

Yahoo! Mojito:: Part 2 - Enhanced Hello World:: Results after Submit

This is Part 2 of the “Hello World” article. In this followup article, we enhance our code to:

  1. Render a form on the landing page which asks user to enter his/her name
  2. Process the data on the submitted form
  3. Say “Hello {user}” rather than “Hello World”

What we will learn through all this is:

  1. One of the various possible options to accept data to the server
  2. Process incoming data
  3. Apply business logic and create the data to be rendered

Let’s get started with customizing the view to create a form…


Read more …

Yahoo! Mojito: Part 1 – Hello World!

Yahoo! Mojito:: Part 1 - Hello World:: Artifacts

Yahoo! Mojito is, now, watched officially by 1027 developers (as of writing this article) on Github (see https://github.com/yahoo/mojito/watchers) and is actively contributed by developers across the board (see https://github.com/yahoo/mojito/network). And I’m pretty sure, there will be several others who would have downloaded, installed and tried.

Before getting into this detailed Hell World tutorial, I assume that you’ve already installed Yahoo! Mojito using the instructions given at https://github.com/yahoo/mojito README. I preferred an npm-install to ensure that I get a stable version.

Defining the “Hello World” application:

  1. The first step will be to create an application with defaults, no customization, and get it running.
  2. Next, we’ll make the application run at port 80 and ensure that the content is available at “/” rather than a strange but intuitive default path.
  3. Subsequently, we’ll change the default contents to reflect “Hello World” in the message
  4. And finally, we’ll make the application interactive by creating a simple form that will accept user’s name and say hello to him/her rather than to the whole world 😉

And here’s some vocabulary before we deep dive:

  1. Yahoo! Mojito: MVC framework for JavaScript based application.
  2. Mojito Application: An application based on Mojito framework.
  3. Mojit: A mojito widget – with its own model, view, controller and binder.

We call this application – “HelloWorldApp” and the mojit as “HelloMojit“.


Read more …

WordPress for Google App Engine?

I love WordPress. A big fan. But then I once-upon-a-time used to be a huge fan of PHP, and then I’ve grown up. I know people will kill me for that statement. 😉

But the fact of the matter is PHP still has serious issues. And most recently, I can’t use it to run WordPress at Google App Engine, something that’s amazingly great for the starters who want to setup quick-and-not-so-dirty app.

I thought… would it be good to have WordPress for GAE? I came across Vosao – Open Source CMS for GAE/J. And I loved it immediately. Has a long way to go, and I do not see any active development on the same… surprised, what happened to the team.

StackOverflow has a question – What CMS runs on Google App Engine, but I personally didn’t like any of them.

And then I thought again… how about writing my own CMS with persistence in a Non-Relational Store with plug-in model so that I can run it on any store, be it GAE’s Data Store, MongoDB or Amazon DynamoDB or whatever.

Let me see if I can hold on my thoughts and really get on with it… At the moment, no promises! :-)

Yahoo! Mojito – My Talk at HasGeek

I’ve started to love HasGeek forum more than others… and there are reasons, mainly the audience and quality – of speakers, planning and execution. I was happily surprised to note that the guys used NFC cards, most probably during breaks. Probably because I had to leave after my session in the morning.

My session at MetaRefresh 2012 was on Yahoo! Mojito, which was recently open sourced at Github.

Below are the slides from the presentation&#8230

Yahoo! Mojito – The Ultimate MVC Framework for Web Apps

Probably. Well, I feel it at least as of date.

More often than not, the web application developers end up in doing the following:

  1. Create a server side logic of the application with all code in PHP, Java, Python, Ruby, C# and what not languages
  2. Choose amazing server side frameworks like CodeIgniter, Struts / JSF, Django, RoR, ASP.Net MVC and what not amazing (MVC or otherwise) frameworks
  3. Create a client side view of the application using HTML / JavaScript / CSS for web, Java for Android, Objective C for iOS etc
  4. Create a middleware for client-server transaction, typically using JSON / XML as content format and serializers and deserializers on either sides in corresponding language (server / client sides)

The issues that typically arise are:

  1. Ensure that the server and client sides of the middleware are always in sync in terms of their contracts
  2. Ensure that the end-points are correctly defined and both the sides are kept in sync
  3. Ensure that the end-points are correctly registered in web.xml, web.config, routes.rb, appropriate Python / PHP files etc
  4. Ensure that if multiple requests are fired to the server to retrieve data, you manage the responses appropriately (this is relatively easier because of jQuery / YUI structures)

I am pretty confident, there are a lot more problems pertaining to client <=> server interaction and state maintenance but these are some of the important ones. I’d love to hear about more crucial issues…

Wouldn’t it be great if it would be possible to answer "YES" for the following…

  1. Can I just do a MyModel.getData(myCallbackFunction) and don’t worry if the piece of code is called on the server or the client?
  2. Can I just call a business operation doWork and don’t worry if it needs data which may have to be retrieved from the server or the client?
  3. Can I just call an operation doWork and don’t worry if it actually gets called on the client or the server?

Well, that’s where – and for lot more reasons – Yahoo! Mojito framework comes into picture.

It seems I just can’t wait to write about it… one piece at a time. btw, my enhancements to Mojito are available at Github at https://github.com/gvaish/mojito

 

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.

Read more …

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”.