Author: nigelb

  • Noname.unconf Report

    This post has been long pending to be honest. We had a Noname.unconf planned in Bangalore on 18th and 19th December. The venue we planned was Jaaga. It was meant to be a fun place to meet a bunch of hackers with some talks planned. I met lifeeth, neena, and Hobbes` the previous night when they were setting the place up.

    On Saturday when I walked in, I sat at the registrations table, signing up people who came. We had about 40 people come in. Interestingly, it was tazz’ and lut4rp’s birthday. There was cake and candles and a lot of fun ensued. I met with a small subsection of the hacker scene that day and it was awesome. Lot of geeks. Geeks are different things. Geeks at networking, web design, sys admin, mathematics, and more. We were planning on a conf app that day and decided to write it general purpose so it could be adopted any day. Later that night, we went for dinner together recounting the experience of the day. Again, good fun.

    I went in to day 2 in the afternoon. The talks were going on when I walked in. They were quite interesting including the talk about UID in India, Debian and Ubuntu BoF, to name a few. A few more new people to meet that day and then we packed up. It was a fun weekend of hacking, meeting new friends, and talking to people about stuff.

  • Working with Google Maps

    There used to be a time when there was this huge maps craze, it has since passed, but Google Maps remains the most recognized map applications seen on the Internet. Recently, I worked on Google Maps API for a client. This post is a retrospect look at how it went. I’ve not worked with other map systems, so I cannot compare my experience.

    My task at hand was to create a store locater that would take an address as input and plot all the points on a map that was within 100 miles of the given location. A fairly simple map application, except I decided to innovate. My first stop was the articles page on the Google Maps API Reference page. I found a very handy tutorial which was exactly about creating a store, wow that made my work much easier. What I found very helpful from that tutorial was the formula. this formula.

    SELECT id, ( 3959 * acos ( cos ( radians (37) ) * cos ( radians ( lat ) ) * cos ( radians ( lng ) - radians (–122) ) + sin ( radians (37) ) * sin ( radians ( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20; 

    That is the heart of the entire module. That formula returns coordinates that are within 25 miles of a point with coordinates (37, –122). The complexity (if at all) of the application is to pass data from a database using PHP or other server-side language and passing into a JavaScript function. The tutorial that I was looking at used xml to pass data to the JavaScript function. This of course is nice, but I was a bit lazy and a bit innovative.

    In my quest for something better, I discovered JSON. Now, this seemed simple enough since is 2010 and most languages have JSON support including PHP. So, I put all the results into a hidden textbox as JSON and wrote a JavaScript function that would execute on window load. Using that information, I could then loop through it and mark points on the map from that.

    jQuery being an awesome library provided a means for me to do exactly that. I could loop through each of them and plot points on the map quite painlessly.

    function markOnMap (x, y) {     geocoder = new google.maps.Geocoder ();     //center the map to the coordinates of the searched address     latlng = new google.maps.LatLng (x, y);     var myOptions = {         center: latlng,         zoom: 8,         mapTypeId: google.maps.MapTypeId.ROADMAP,         mapTypeControl: false     }     map = new google.maps.Map (document.getElementById ('map_canvas'), myOptions);     var markers = document.getElementById ('marker').value;     var mapPoints = $.parseJSON (markers);     var marker = new Array ();     i = 0;     $.each (mapPoints, function () {         var latlng = new google.maps.LatLng (this.lat, this.lng);         marker[i] = new google.maps.Marker ({             map: map,             draggable: true,             position: latlng,             content: '<b>Name : </b>' + this.name,         });         google.maps.event.addListener (marker[i], 'click', function () {             infowind = new google.maps.InfoWindow ({ content: this.content });             infowind.open (map, this);         });         i++;     }); } 

    When using infowindows, its very important that the content is stored inside the marker and then used to pop out the infowindow, that’s the only way that works. I spend about 5 hours trying to figure that one out.

  • Ubuntu Hour in Bangalore

    Woo! After a while, the Ubuntu loco community is awakening in Bangalore again. I had announced a meet up on the mailing list a while back. I had my fingers crossed as to how many would turn up and how it would be. Most people assured me if there are 2 people and the other person isn’t your imaginary friend, its a success!

    I’m glad to report that we ended up with 7 people coming in. It started out a bit slow with just me sitting alone in Cafe Coffee Day on Richmond Road. To be a little more noticeable I opened up the laptop and sat in such a way I could see everyone who walked in. Anyone who looked lost was definitely looking for the Ubuntu Hour (note to self: Sticker on laptop sounds like a good idea now).

    Ganesh walked in first followed later by Harish and Arjun almost at the same time. We sat chatting for some time until I saw noticed another guy looking lost and Manish joined the party. Later on Venkatesh also joined us giving us more life!

    We talked for quite a bit about what we do for a living and what we do for the free software community. All of the people seem to be contributing in one way or the other and it was fun to hear about what others do. We packed up at around 5 and walked out to run into a DD, Ritesh, who was planning on making it but got late.

    And we ended up talking for some more time outside the coffe shop. Meeting geeks is fun! We’ve plan to meet up every on the last Saturday of every month with announces sent to ubuntu-in and ilug bangalore list. As soon as the venue for the next one’s confirmed I’ll blog and tweet about it! Thank you all for coming 🙂 The pictures are all on my flickr.

  • Web-based viewer for git

    I’ve been looking for a simple to set up viewer for git that would list out all the git repositories that I have on my git server. It took a bit of a search and I finally discovered viewgit. So far, I’ve found it pretty nice. Setting up viewgit is very simple.

    Download the tarball from sourceforge. Extract it to your htdocs or www folder. Make a copy of example-localconfig.php and rename it as localconfig.php. Comment out the line$conf['projects'] and uncomment $conf['projects_glob'] = array ('/path/to/repo/);. If like me, you store all your git repos in one folder, this is the best viewer for the amount of work I’ve had to do. Maybe I should write about how to store git repos in one folder. A story for tomorrow!

  • Automatic database backup

    I use git extensively for version control. Its nice to use git since it backs up the code, but the database still remains unversioned. Well, thankfully, XAMPP has a script that does a database dump. So, I wrote a script to do the dump and then commit it to git.

    Step 1

    Create a directory in the home directory for the database dump

    $ mkdir projectname-database $ cd projectname-database 

    Step 2

    Initialize git in the directory

    $ git init 

    Step 3

    Do a database dump for the initial commit

    $ /opt/lampp/bin/mysqldump -u root database-name > database.sql 

    Step 4

    Commit the database file

    $ git add . $ git commit -am 'Initial database commit' 

    Step 5

    Now we’ll write a script to do the database dump and add commits. Open your favorite text editor and write the following script. Save the file as probably ‘database-project’ in your home folder

    #!/bin/bash /opt/lampp/bin/mysqldump -u root database-name > /home/username/projectname-database/database.sql cd /home/username/projectname-database/ git commit -am 'Database dump at `date`' 

    Save the script so that you can run it via a cron.

    Step 6

    Give the script executable permissions.

    chmod a+x /home/username/database-project 

    Step 7

    Open crontab with the following command

    $ crontab -e 

    Step 8

    Add the following line

    00,30 * * * * /home/username/database-project 

    This cron will run the script every 30 minutes.

    Basically what happens here is the database dump will be taken every 30 minutes and the change will be committed to a git repository allowing you to keep track of the overwriting. I’ve found it quite useful and I hope you will too.