Shikhar Nigam's Blog, page 7

June 25, 2014

Making an Android App using Python

I am a huge fan of Python. It's quick, clean and versatile. It's the only language I or anyone else would ever code in, if those sort of decisions were upto me. But, I digress.

So, one day, I was bored in class. And in one of those rare flashes of insight, I got this very simple idea for a word-game. (Yes, a word-game. I'm geeky that way.)


You get a bunch of letters and a grid, and you pick the letters up and put them into the grid - in a manner such that each row and each column contains a valid word. Simplistic. For example:

A  C  EB  A  RS  P  A
The first requirement is a list of all the possible combinations of words that fit into the above described combination. That's easy enough. Google the list of all three-lettered and four-lettered words in the English language, discard the insanely erudite ones, and simple brute-force script using the random library in python, will generally generate a valid set of words within a second or two.

Then, out comes PyGame, a library to quickly create games with python. It was only due to my lethargic attitude and poor coding-chops that it took me over six months to write the code. A good coder would have been able to do it in less than a week. Pretty basic stuff. You make two classes. One for the "tiles" that hold the letters and one for the "cell" that holds the "tiles". Define some basic methods for them to interact such as ...

tile.put_into_cell(cell)
tile.take_out_of_cell(cell)

... update the relevant variables and you're well on your way to creating the code.

Anyway, I got the game working on my laptop. What next? How about making it a windows installable - complete with the always-ignored Terms of Usage? There is a library called py2exe for that, but I didn't make a windows-installer. I set my eyes on something bigger. An android app.

Technically, if you want to do android programming, you should learn Java and the Android library. But, I am a lazy person like that. I've already learnt python. Why can't it suit all my needs? Apparently, it can.

StackOverflow told me to check out pgs4a - the "pygame subset for android", and sure enough after setting it up and tweaking my pygame code - all of which took about three days - I had a functional android-app. That too without learning a shred of Java or Android-programming. All you've gotta do is "import android" and then map certain pygame "events" (such as MOUSEBUTTONDOWN) to the required Android event and you're done. Seriously, that's all you have to do.

The functions provided by the library are pretty basic and the apk will take 6MBs just to store the python library files, but it's one heck of a shortcut! Isn't it?





 

                                             



The app can be found here (Google Play wants $25 that I don't have, that's why the app ain't up there).
 •  0 comments  •  flag
Share on Twitter
Published on June 25, 2014 19:10

June 21, 2014

June 18, 2014

Nature


Be still my heart; cruel is she.
Undone her hands umpteen lives.Generosity naught but a veilO'er horrendous vile.Though – enchants all intricate beautyBeneath beauty lurks intents as knives.Mothers – like setting sun, worried and paleBut seeks only to defile.Springs Spring, to mistrust parryUnder facade harsh Winter liesBlows away hope, mighty galePretends of love all the while.
Be still my heart; cruel is sheMellow rainbow to appear strives.Be not moved; colours soon paleTo expose malicious smile.

 •  0 comments  •  flag
Share on Twitter
Published on June 18, 2014 05:14

May 19, 2014

CAT Practice Essay 6

15 min
TOPIC: Society is responsible for the criminalization of politics.
It has been said that the only thing required for evil to triumph is for good men to do nothing. And since politics in a democracy, aptly described by Abraham Lincoln as 'of the people, for the people, by the people', is only a reflection of the whims and volitions of the general populace of the country, if thesre is rampant criminilization in politics, the responsibility for it falls squarely on the shoulders of the society - they who have done nothing and let evil triumph,
Consider, to begin with, the nomination of politician with ongoing criminal lawsuits. While, 'innocent until proven guilty', works well to keep the honour of a person from being wrongly tainted, is it really too much to ask that such politicians refrain form participating in elections themselves. That we do not do vociferously enough is society's fault.
Next, consider the media. Media, under fiscal pressure, panders to the salacious appetites of the public, If the people are more interested in the latest scandal from Bigg Boss, that's what media houses will highlight. However, if the society is consistently clamouring for political transparency and decriminalization and is always on the lookout for a means of venting their moral outrage, media houses will only be too happy to provide that medium. That they d not do so consistently enough is society's fault.
However, not all is lost. Just as the responsibility for the criminalization of politics is with the society, so is the power to change this unsavoury truth. The movement that spawned the the Aam Aadmi Party is  a clear example of where at least a substantial step has been taken towards clean politics - by the society. And if society can maintain this momentum in the coming general election, the laurels of decriminalizing politics will also rest with the society.
 •  0 comments  •  flag
Share on Twitter
Published on May 19, 2014 03:10

May 12, 2014

CAT Practice Essay 5

Time: 15 minutesTopic: As democracy has failed in India , it's time to look for alternative form of government. Argue.
There are those who look at the state of affairs in our country, sigh deeply, shake their heads and ask, "What is the country coming to?" They point out the dismal status of infrastructure, discordant politicians, oppressed minority, rampant corruption etc. and state categorically that the "system" needs to change. Some are hazy as to what exactly the "system" represents. But there are those that say it is "democracy" itself.
Granted that there are a few odd examples here and there like that of Singapore and Lee Kuan Yew, where dictatorship of the benevolent kind did wonders for the country. But there are also Hitler, Stalin, Pol Pot etc. that far outnumber the benevolent dictators. Clearly, concentrated power in one individual is more liable to be detrimental.
Then there's also the problem with logistics. India is huge. And India is populous. And India is diverse. Mindbogglingly so. It becomes hard, in such circumstances, to see how concentrated power will do justice to each section of the society - which, it must be stressed, needs to be the fundamental basis for a civilised society.
It was Sir Winston Churchill that said, "Democracy is the worst form of government except for all others that have been tried," and right he was. While democracy, especially parliamentary in a country such as ours, does have its shortcomings, it offers up a myriad of benefits that no other form of government could match - an independent judiciary, freedom of expression, voice to the oppressed, right to dissent and most importantly "power to the people". And so, it may be possible that democracy has so far not succeeded completely in certain aspects, it has by no means failed.
 •  0 comments  •  flag
Share on Twitter
Published on May 12, 2014 03:00