Thejesh GN

A Blog, A Website and A container for all my views with excerpts from technology, travel, films, india, photography, kannada, friends and other interests. I am Thejesh GN. Friends call me Thej

Game of Life with Processing.js

Posted by Thejesh GN On May - 6 - 2011

hacker emblem I was bored. So I thought of playing Game of Life. I got to know about it through hacker logo which is the glider pattern from the Game of Life. While playing I thought let me code it processing.js. Game of life is a simple game with no interaction involved once you start with the initial seed.
From Wikipedia:
The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.[1]
The “game” is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

  1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  2. Any live cell with two or three live neighbours lives on to the next generation.
  3. Any live cell with more than three live neighbours dies, as if by overcrowding.
  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The rules continue to be applied repeatedly to create further generations.

The initial code was borrowed from Ran Tao’s java based program. I rewrote in Javascript version of Processing. Also added player buttons for more control. Also added a way to start with your own seed through it starts with random seed. One more change to the original Life is that you can introduce a living cell while its playing. Just click on the grid. Its kind of against the actual game, but it seemed more fun to me.

Clear it and introduce your own seed using mouse or just intrude, you are God. Go to full page version its more fun. Source code is on GitHub.

Batch transliterating names into Kannada using Google API

Posted by Thejesh GN On February - 4 - 2011

Some times work at Janaagraha throws awesome challenges. Like as part of BEST project we are cleaning up voters list. Voters list in Karnataka will have names in both English and Kannada, Most of the volunteers have filled up only in English and hence we were left with transliterating names into Kannada. I was thinking about automating it. After all transliterating is not as complex as translation, right? Wrong. Its difficult to write one specially when there are so many spelling variations in English for the same name in Kannada.
Like for example both Sreenivas and Srinivas are ಶ್ರೀನಿವಾಸ್ in Kannnada. I found Google transliteration does that pretty well. But they have only Javascript APIs for web pages but nothing for server side code.

But Google worked and I found a non-public API of Google Transliteration API which gives JSON output for a given english input. Cooked up API in PHP to clean up JSON and give an array of results. Code is github for obvious reasons.
Using

$kn = transliterate("thejesh,ramesh,
 uthara,shreenivasa,reddy");
print $kn[0];

Probable drawbacks:
1. Its a non-public API provided by Google. Not sure when they will block it.
2. As of now it can transliterate only 5 words at a time
3. No information about API rate limiting. So be on the safer side.

Let me know what do you think.

40-twits app similar to @davewiner’s

Posted by Thejesh GN On April - 17 - 2009

After looking at Dave Winer’s Top 40 links on twitter app, I wrote my own version of it called TopLinks

It displays the the top links (sorted by number of visits, like digg) shared by me on twitter in last 400 tweets. Its been scheduled to run once every hour.The logic is little different from Dave’s app. He displays latest top 40 links. Since I am not a big link sharer, I choose to display all of them present in my last 400 tweets.

The app uses twitter and bitly APIs. I want to release the code, but I hacked it in 2 hrs, so its not very pretty. Let me clean it before releasing it .

What next? May be a wordpress plugin to show your top links on twitter. Any other ideas?

BTW I am @thej on twitter.

Update: Opensourced

How to kill that Digg Bar Frame

Posted by Thejesh GN On April - 4 - 2009

Digg recently introduced url shortener. This is not your standard url shortener where the shortener does a 302 forward. Digg shortener displays destination site in a frame. Which means the reader still stays on the Digg.

Most of the modern web analytics software will be able to record this visit, but it will problem in finding out the actual referrer.  Also standard traffic counters like alexa don’t count this visit against your site.
So if you don’t like to that DiggBar to be displayed on your blog.  You can add this one line code to your site. Add it to your webpage’s head section.

<script type="text/javascript">
if (top !== self) top.location.href = self.location.href;
</script>

This code in fact doesn’t allow anybody to display your content in their frame. Here is the demo url http://digg.com/u1BSW to check. It should work on all browsers.
Let me know if you have any other suggestions.

RSS Feed for Aamir Khan’s blog using YQL and Pipes

Posted by Thejesh GN On March - 9 - 2009

As you know earlier I had parsed Aamir Khan’s Blog to create a feed. It was custom screen scraping code to generate the feed.Today, after reading Anand’s blog, I did the same using YQL and Pipes. Using YQL/PIPE is much easier than writing custom code and is less buggy.

If you have subscribed to http://feeds.thejeshgn.com/aamirkhan then, you don’t have to worry. The feed url remains the same only the technology behind has changed. Now we have a better technology. If you have not subscribed, I guess its a good idea to subscribe.

The post below is for fellow hackers. I have tried to write a detailed post on the process I followed and technologies I used. Read the rest of this entry »

Get in touch