Saturday, September 21, 2013

BangPypers September

Attended the monthly chapter of Python Bangalore (BangPypers) for the first time.  I had been a regular at the ChennaiPy meet.  But after I moved to Bangalore, this is the first Python meet I am attending.  Around 20 enthusiasts participated.

Mr. Baiju of ZeOmega hosted the event at ZeOmega office.  It was held in an unconference mode where the audiences shared their views and experiences.

When Baiju finished with introduction to Python for beginners, we realised that the speakers as per the original agenda did not turn up.  So, there was some dead time in between - we started with a brief introduction of ourselves - which turned out to be a self and Python-tools introduction and experience sharing session as well - We just had 30 min after the introduction got over - time well spent in introduction.

Got introduced to quite a few things.  Though some of which was known earlier, I am listing below all that we discussed so they serve as pointers

Django - A very popular Python web framework
Tornado - A Python Web framework for non-blocking network I/O
Mezzanine - A Django Content Management System
Jekyll - Static Site Generator (based on text input) built in Ruby
Hyde - A Python based static site generator
Gevent - A Python networking library
Silpa - Swathanthra Indian Language Processing Applications - A project with a focus of building several Indian language specific tools
Python nltk - Natural language processing Toolkit for Python
Beautiful Soup - A Python based XML / HTML parser
BuildOut - Python based build system
Jenkins - Open Source Continuous Integration Tool - See here for what is continuous integration
Python Koans - A self learning tool for Python written in Python
Learn Python The Hard Way - A much revered python tutorial
Pycassa - Python client for Apache Cassandra (a distributed dbms for big data)
Sophia - A next-gen key value DB for high loads
Leveldb - A light weight key value DB designed by Google
Lucene - Open source search software by Apache

Later, towards the end, Baiju walked us through how a distribution can be created and uploaded to PyPI (Python Package Index) via setuptools


Friday, August 30, 2013

Slidify

Recently I came across a presentation making tool in R called "Slidify", by Ramnath Vaidyanathan.  At the outset, it is impressive.  A few advantages using slidify in R
1. One can embed the R code (or even some other code) directly in the slides.
2. The R code can be executed run time when the slides are prepared  (I suppose other languages can also be executed run time with appropriate set-up)
3. The plots (and other outputs) executed in R can directly be captured in the slides.

Works seamlessly in Chrome and Firefox.

For using the "slidify" we just need 
1. An R environment with required tools installed (one can follow the procedure in slidify.org website)
2. An "Rmd" - R mark down file, where the contents and code are written into.

It has plug and play support with multiple options for
1. Framework - The look and feel, theme of the slides
2. Highlights - The code highlighting support
3. Widgets - Tools for support like equation editing, making online quiz and much more.

For equation editing, the "mathjax" tool is quite good, which is readily supported.  Additional Info:  Many of the coursera courses uses mathjax tool to render mathematical equations.  Further I remember, my Professor Jeff Leek used Slidify for his slides in his "Data Analysis" course in coursera.

Slidify makes use of two key libraries among others.
1. Knitr - This converts the R markdown files to ordinary markdown files. 
2. markdown - This R library converts the markdown files to html files.

The output will be a dynamic, interactive html file with all required support files - css, js etc.  

An off-note on a relevant topic:
Markdown (wiki) was originally conceptualized by John Gruber and Aaron Swartz in 2004.  It has been in wide use since then.


Monday, June 24, 2013

The Lion Park

Visited the Lion Park here in Johannesburg today, with a couple of my colleagues. It is about 40 km from the place I stay, Bruma.

Had no idea about the place before visiting.  Just thought it would be only lions in the zoo which we would be seeing.  On going there realized that it was a safari.  As any tourist place would have it, this too had a few souvenir shop - most of which are over-priced.  Bought the tickets for the 11:30 safari trip and roamed around the souvenir shops in the meantime.  The ticket of 270 Rand each included the Guided safari and a mini-zoo and lion cub interaction session for 2 minutes where you can go and touch the cubs and take some photos.

Started with the safari at first.  The safari van seated around 20 people. Masana, our guide and driver stopped at the first point to show us ostriches, zebras and giraffe.  With stoppage near each animals, he gave lot of information: The pattern of lines on zebra's back is unique, just like fingerprints. The female zebra has a bigger back even during the non-gestation period, in which it stores some gas which it releases to fight predators, when chased.  Zebra at a time can give birth to 2 off-springs.

The female ostrich have grey feathers and the male ostrich have black feathers. Ostriches cannot fly; but can run upto 2 km non-stop.  The eggs of ostrich are the largest of birds, very strong that it can withstand a weight of upto 20kgs.

In the same area of zebras and ostriches, stopped to see the antelopes: impala, springbucks and blazebucks. The impalas have horns only for the males whereas the other two varieties have horns for both genders.  The blaze buch has a white patch on its face, which gets developed when the buck becomes adult.

Okay, then enter the lions - into the lions camp - there are four camps (enclosed areas) for lions and one for wild dogs and one for the cheetah.

The time that we went to see the lions was actually their weekly feeding time.  The lions are fed only once a week - on Sundays 12 noon.  All lions were eagerly looking for the arrival of the feeding van.  The van came with cut pieces of cow / bull meat and distributed.  These meat are supposedly gifted by the nearby farmers in the area.

We also happened to see Letsatsi, a white lion which was the main cast in the 2010 movie "White Lion".  Because of the best performance it did in the movie, Masana told Letsatsi could not be gifted a bungalow or car, but was gifted with 6 lionesses.

A lion can have many lionesses - that is considered a family group.  In some group, there could be more than one adult male lion - but most of these adult male lions are brothers and together with their lionesses live together.  We saw such a group of white lions.  And Letsatsi had all its lionesses brown - the offspings could be pale brown or completely white - we could see both kinds savouring their meal with their mothers.  In one other group, a single brown adult male lion had 3 lionesses in the first camp and all were roaming eagerly awaiting their weekly meal.



And another surprising fact regarding lions:  The lioness discards the weak cubs - it does not take care of them.  In the park, the management takes care of the rejected cubs in a nursery.  Survival of the fittest! These cubs which are rejected by mother will never learn the art of hunting and may not survive longer if left in the wild.

Saw both cheetah and leopards.  Cheetah during safari and leopard inside the cage in zoo.  Cheetah is a muscular animal and can run at speeds of 80 to 120 km per hour - but not sustainable beyond some 200 metres or so.  The body gets heated up and it needs to slow down to cool.  So, it starts attacking the prey with full speed only if it is within the limit, otherwise it just lets go.


Cheetah has a black mark on its face which is needed for the absorpion of Vitamin D from sun light.  Cheetah hunts during the day unlike the leopards which are nocturnal and hunts during nights.  Leopards are smaller in size compared to Cheetah and can climb the trees. (Remember Bagheera in Jungle book, which is a black leopard)




The wild dogs and cheetah are fed thrice a week, unlike lions which are fed only once.  Each has its own metabolism.  And wild dogs are supposed to eat their food very fast and the lions the slowest, savouring each bite.  The lions could end up eating their portion of sunday noon meal late into the evening as well.

On returning, just before the end, a giraffe came and got its neck down into each of the vehicles and did some inspection!

After the safari, visited the mini zoo which housed leopard, cubs etc.  The zoo also featured something called cub world, where visitors can touch the small cubs of lions.

Monday, May 27, 2013

The Shiva Trilogy

So, "The Oath of the Vayuputras" is done and dusted! - the third and final book in the Shiva Trilogy series. Almost every one in my friends and contact list had read or at least bought the book and stored in their shelf to read sometime later.

Well, I started with the first book of Amish in the Shiva Trilogy series, around one year back, when I was shuttling between Delhi and Chennai for one of my consulting assignments.  At that point, already his first two books had come.

The concept behind the story is very simple, but the way it is executed is awesome.  Amish places lots of dots in the plane and connects them well and makes a nice coherent story.  

He asks a simple question "What if Lord Shiva was not a God as he was always imagined to be?  What if He was just a human being?"  And, takes us through the life of a man Shiva, who resided in Himalayas and how he ended up as a lead man for the Quest of His Time.  And what is such a quest? To destroy Evil.

Shiva is made to believe that he is the One to go after Evil.  And, who is that Evil?  Shiva takes up the journey and finds the answer himself.  In his journey, he is helped and guided by many people from a tribe of intellectual and spiritual advisors like Vasudevs to even a beggar outside a temple.

The first book sets up the the context, describes the ways of life of two main tribes Meluhans and Swadweepans (Suryavanshis and Chandravanshis) inhabited across the northern subcontinent.  The book builds up the characters of Shiva and Sati (lead protagonists) nicely.  The book introduces Naga and their unusual living, violence and an inclination for disrupting the normal lives of Meluhans.  Characters like Parvateshwar (the war-general of Meluhans), Lord of the Nagas, Ayurvati, Nandi all introduced and built-up succinctly. 

The second one, "The Secret of Nagas" explores the lives of Nagas. It introduces the readers to other regions like Branga, Panchavati (present day WB, MH respectively). It brings up and reveals some of the ugly secrets which was kept out of reach, for years by people in power.  The conversations that Shiva has with Vasudevs are interesting and have lots of deep philosophical insights.

In all these books, Shiva keeps his search for Evil, the view on what is evil keeps changing every now and then.  What considered evil, becomes not evil - it just a completely different way of leading life.  Shiva proposes many hypothesis and keeps disproving all of them, until what he finds to be the ultimate evil in the 3rd book.

The third book involves lots of battles and strategic thinking behind the wars and battles, not that these are not present in the first two books - but the first two are more philosophical than war-strategic as compared to the third.  The book gives enough hints of nuclear power being used in wars - talks about fission and fusion reactions.

Overall, there is a lot of insights and deep philosophical truths that can be derived from the books.  It is definitely not a one-time read.  Every new read will bring up some insights.

Looking forward to the second read, soon!

Friday, May 17, 2013

Automated Messages

We get messages from the banks, IRCTC, telephone bills, ecommerce sites etc on order status, payments, POS transactions, reminders etc.

Generally these messages start with two letter combination which are like LM, TD, BA, AD, MM, MD, VM, BM, BZ, BP etc

One of my friends who works as a Consultant in Telecom Business told what is the significance of these two letters.

The first letters represent the Messaging Service Provider and the second letter represent the city.  

LM - Loop Mumbai
AD - Airtel Delhi
TD - Tata Docomo Delhi 

An elaborate list here http://goo.gl/QzYBZ

Both the messaging service provider and the message receiving network charge for each such message..


Thursday, April 25, 2013

Visualization tools, Python, Ruby, Web Frameworks and more

Today I came across a tweet mentioning about Rega. Rega is an experimental project of Ruby wrapper for Vega.  Vega is a Visualization Grammar.  You can read more on Vega in this documentation.  Vega is strongly influenced by Protovis and d3.  By the way, d3 is the successor of Protovis - developed by Mike Bobstock et. al.

d3 is a javascript library for Visualization.  Some examples exhibiting the capabilities of d3 are in this Github Gallery I worked a little in d3.  Working with d3 is fun and the visualization that can be created are very cool.

Coming back to Vega, which is a Visualization Grammar - other similar grammars are Grammar of Graphics, ggplot2, Tableau's VizQL.  Tableau is a proprietary visualization software. Also there is Google Chart Tools.  You can play with these charts in Google Code's  Code Playground.  Google Chart is offered as R package googleVis which can be directly integrated from R programming language.

Recently, I had a chance to try Python.  Though, I have been a regular in Pycon talks in Chennai, I never used it much.  Perl has been my favorite for many years.  Now, I have started liking Python.  Also, I tried a few things in django, a web framework in Python - it is very powerful.  There are other web development frameworks available - Pylons (more a content management system), BottlePy, CherryPy, WebPy. Complete list here

And, there is a way you can bring in the power of d3 visualization from the django framework itself. You can explore the django-nvd3 package (which is still in beta).  D3, Vega, GoogleVis etc are relatively very new technologies.  

Also, had a chance to look into Ruby and Ruby-on-Rails.  It can one-on-one be compared to Python and Django.  There are some interesting discussions in StackOverflow discussing the pros-and-cons.  See here for a comprehensive list of Ruby web frameworks. 

Ruby (1995) interestingly is inspired by Perl, Lisp, Python etc. I am yet to try something in Ruby. The designer of Ruby Yukhiro Matsumoto works with Heroku (a PaaS - Platform as a Service company).  Probably, since Pe(a)rl was already there, some discussion went on naming the new programming language Coral or Ruby, and finally settled on Ruby. Interesting! 

Ruby site is generated by a site-generator called Jekyll, the author of Jekyll talks more about it here.

In exploring all these, came across something called CoffeeScript, which is a ease-to-program script which is compiled into a javascript. See this left to right translations of CoffeeScript and JavaScript code to see the simplicity of CoffeeScript.
With indentation for the control, iteration and function blocks, instead of the traditional braces, this looks very similar to Python. An additional info: Dropbox which initially had JavaScript code now uses CoffeeScript.

Thursday, April 11, 2013

Margin of Wins in IPL

Just got curious how the winning margins were in the all 5 editions of IPL combined (from 2008 to 2012).  So, I drew the frequency pattern (statistically speaking - histogram) for the margins in terms of both runs and wickets.  This is how it looks like:


As people expect and want, most of the matches are close contests - with the teams winning by 1-20 runs. 
In this analysis - I have not taken the tied matches into account.  And, in the chasing wins, most do so comfortably by 4 to 7 wickets to spare.

Interesting to look these completely different distributions!

Thursday, March 28, 2013

A Geometric Puzzle







Find the area enclosed by the 4 arcs in the figure (shaded in grey)

The figure is drawn as below

1. A square is drawn with side "a'

2. With the side of square as radius, 4 quadrants are drawn with centre at each of the vertices.


Wednesday, January 23, 2013

Gold Import Duty Raised!

This was the news of the day.  Import duty on gold raised from 4% to 6%.  And, just a day after that announcement, Govt. followed with another one, raising the import duty of raw gold (called Dore, an alloy of gold and silver) from 2% to 5%.   News Item in Live Mint: http://goo.gl/JWQmh

Reason: Controlling the Current Account Deficit.

What is Current Account Deficit? 
It is the amount by which the total imports exceed the total exports.  A country having current account deficit imports more (goods and services) than what it exports and owe the rest of the world from revenues generated within the country.

Why increase import duty on gold?
India imports approximately 900 tonnes of gold per year.  That is approximately 20% of Annual Gold Demand of around 4500 tonnes. (Data: World Gold Council, Demand Trends http://www.gold.org/investment/research/regular_reports/gold_demand_trends/ ).  As quoted from this article (http://goo.gl/7KXaA) of Live Mint Gold imports constituted 11.5% in India's total imports basket in 2011-12 in value terms, growing from 6.9% in 2008-9.\
This means there is a drastic increasing trend in gold consumption.  Gold does not contribute greatly to the real economy of the country - as most of gold imports are for jewelry and coins which get promptly stored in households and safety lockers.  See this article by Nilesh Shah on Indian consumers crazy appetite for gold http://goo.gl/lZA2z  He warns that if Indians stop buying gold, the gold bullion market may crash (and such a price correction may in fact be welcome)

Can I do something as a retail investor?
Yes, one can reduce the consumption of gold.  Or to put in better words - look for investment opportunities other than gold.  Because, the gold investment habit of Indian housholds is costing the country dearly in terms of widening the current account deficit.  And, Govt. of India, at this point is signalling the same to the investors.  It is up to the individual investors to take cue and act accordingly.