Pseudo Techie and Hazy Dreams:

Saturday, June 13, 2009

Jquery+JMaps+ Trekking spots in Sahyadris

Here is the quick recipe of the small utility hobby application I wrote some time back. This application adds marker to lot of trekking places in Sahyadris ranges in Maharashtra. Thanks to fantastic jmaps library it made it simpler for me.

So here we go.

  • First step I needed to hold all latitude/longitude data in a format which can be easily consumed by my logic written in JavaScript. So I put everything in JSON arrays named places as follows. And kept this in a separate file called as places.json

{"places":[
{ "name":"Alang",
"lat":"19.58268",
"long":"73.66229",
"elevationFeet":"4852",
"elevationMeter":"1479",
"submittedBy":"Mahesh Chengalva"
}.....n records
]
}

  • On load I make call to JSON file as mentioned above and pass callback function which is added below after this snippet.


(function($){
$.getJSON("places.json", loadMapInformation);
})(jQuery);


  • Once you handle the data part and follow sample examples mentioned on jMaps page you can code google-maps application very easily. Following function does everything required for this maps application. I love Jquery and more than that I like Jquery Plugin architecture so that we can have such wonderful plugins which make life easier.


function loadMapInformation(locationMapInfo){

$('#map').jmap(
'init',
{
mapCenter:[19.38685, 73.77917],
mapType:'hybrid',
mapEnableType:true,
mapZoom:11,
mapEnableScrollZoom:true,
mapEnableSmoothZoom:true
}
);
// add links to right-hand sidebar
$.each(
locationMapInfo.places,
function(i, location)
{
$("
  • "+location.name+"
  • ").appendTo("#links");
    }
    );
    // add markers on Map and html-content to be shown on click of marker
    $('#links a').each(
    function(n){
    $('#map').jmap(
    'addMarker',
    {
    pointLatLng:[locationMapInfo.places[n].lat,locationMapInfo.places[n].long],
    pointHTML:"Place :"+locationMapInfo.places[n].name+"
    "
    +"Elevation :"+locationMapInfo.places[n].elevationFeet+" Feet("+locationMapInfo.places[n].elevationMeter+" Meters)
    "
    +"Contributed By :"+locationMapInfo.places[n].submittedBy+"
    "
    }
    );
    // also add click handler for sidebar clicks
    $(this).bind('click',
    function(event) {
    $('#map').jmap(
    "moveTo",
    {
    mapCenter: [locationMapInfo.places[n].lat,locationMapInfo.places[n].long],centerMethod: "pan"
    }
    );
    }
    )
    }
    );
    }



    Erlang : Quick setup on Ubuntu


    1. sudo apt-get install erlang-base
    2. sudo apt-get install erlang-base-hip

    Once you are done. Head to getting started page on erlang website. Its fun to learn new language.



    Saturday, May 9, 2009

    Notes : Coding and Debugging

    Source: Practices of an Agile Developer - Working in the Real World

    • Program intently and expressively : This summarises whole post literally but read on. Details are important in real life.
    • Code you write must clearly communicate your intent and must be expressive. By doing so, your code will be readable and understandable. Since your code is not confusing, you will also avoid some potential errors.
    • Write a code that is easy to understand.
    • Code iteratively. Have continuous feedback loop ready.
    • Elegant code is immediately obvious in its utility and clarity. But the solution isn’t something you would have thought of easily. That is, elegance is easy to understand and recognize but much harder to create.
    • Develop the simplest solution that works. Incorporate patterns, principles, and technology only if you have a compelling reason to use them. Side Note for me: Thats the way to understand the framework and their purpose. Don't jump start projects based on the frameworks w/o studying why part.
    • Cohesive coding: We follow this in patterns. packages/modules and tiered apps. MVC pattern etc. Each artifact does ONLY one thing very well. this simplifies refactroing and testability of your application.
    • Command-Query separation: Command likes to change the state of the object and returns some value also. Query just returns the state of the object. This separation is important to avoid side-affects. Design time decisions and keep your unit tests ready for this.
    • Substitute by contract: Derived class should "require no more and promise no less than" the methods/services available in the base class.Make a decision based on type of relationship is-a/has-a/uses-a. Delegation is usually more flexible and adaptable than inheritance.Use interfaces in the form of delegation but make sure what interface really promises or requires.



    Friday, April 3, 2009

    Book to read: Refactor Your Thinking Pragmatic Thinking and Learning



    Tuesday, February 17, 2009

    Good Slides Pack



    FREEconomics: The economics of Free Stuff

    Check out this SlideShare Presentation: