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

Archive for October, 2009

Getting started with Processingjs by writing Analog clock

Posted by Thejesh GN On October - 29 - 2009

As most of you know, I love JavaScript.  Recently I started exploring Processing.js to create some dynamic graphs and animation. I was bowled over by the power of Processing.js.

“Processing.js is an open programming language for people who want to program images, animation, and interactions for the web without using Flash or Java applets. Processing.js uses JavaScript to draw shapes and manipulate images on the HTML5 Canvas element. The code is light-weight, simple to learn and makes an ideal tool for visualizing data, creating user-interfaces and developing web-based games.”

The Processing language was originally created by Ben Fry and Casey Reas for Java. In 2008, John Resig ported the 2D context of Processing to JavaScript. It needs Canvas. So make sure you are using HTML5 capable browser like Firefox 1.

Setup: Download the processing.js. That is the only file you need.

Initialize processing: We need to initialize the processing engine on a canvas. We will have that in the init.js and will include that.

<html>
<head>
<script src="init.js"></script>
<script src="processing.min.js"></script>
<title>Analog Clock using Processing.js</title>
</head>
<body>
<script type="application/processing" target="clock">
//your processing code
</script><canvas id="clock">You need HTML5 canvas support.
Try latest Firefox</canvas>
</body>
</html>

The above code snippet shows the basic setup to run. We need to add our processing code inside

<script type="application/processing">
//your processing code
</script>

The init.js code actually searches for all the script tag type=”application/processing” and applies processing the code on the target canvas. init.js was borrowed from JResig‘s code examples.

Logic for the clock:
Circle has 2PI radians. So for each second/minute we have to move 2PI/60 radians. Given the center of the circle (a,b), radius r and angle t radians. we can find any point on the circle, using
x = a+r cos(t);
y = b+r sin(t);
or
x = a + r (1-t2)/(1+t2)
y = b + r (2t)/(1+t2)

I have used the first set of formula. Processing.js supports time and trigonometric functions by default.

But the 0 degrees start at horizontally and I wanted 0th hour to start at 90 degrees. And hence the subtraction of quarterCicrle which equals = PI/2.

The two main important methods are
void setup() – called initially when canvas gets loaded.
void draw() – called at the rate of frameRate.
Read the rest of this entry »

Logging uncaught exception (redirecting from sysout to logger)

Posted by Thejesh GN On October - 27 - 2009

Uncaught exceptions in Java are handled by the System. The JVM usually logs the exception into the System.err and then shuts down. But in case of web applications its different. It logs the printstack trace to server console and then continues. Even though most of the time System.err is redirected to a file system, I wanted a better way of handling it just like any other exception stacktrace. I wanted logger ( you can use log4j too) to handle it, so I it can help maintainers better.
Java gives Thread.UncaughtExceptionHandler to handle any such exceptions. I implemented my own. Here is demo class
Read the rest of this entry »

Cyclothon – Bengaluru – 2009

Posted by Thejesh GN On October - 21 - 2009

My self and manju took part in first edition of Cyclothon Bengaluru. The distance of amateur race was reduced 36kms from initial planned distance of 50kms. We were not really happy as both of us wanted to do 50km. Never the less we set our own targets. Manju – complete with out walking and me – complete with in 2 hours.

I was surprised with the number of cyclists turned out. I was trying to convert whom ever I met into regular critical mass rider. I hope there will be more participants this month end.

The event started with flagging off men’s and ladies’ race.

Then it took ever for flagging off us. So we into the photography mode. Took pictures of ourselves, crowd and the winners of the race.

That is me and manju. Read the rest of this entry »

Seven Years in IT and Seven things I learnt

Posted by Thejesh GN On October - 13 - 2009

Recently I completed seven years in IT industry. My career started with Siemens and as of now I am working with Infy. Along with Infy and Siemens, my professional life has been greatly influenced by people whom I met at various events, online and open source communities. This is a small note where I want to share what I learnt in this seven years. There are many things to write about, I just wanted to use number seven.

  1. You can’t learn programming in 7 years
    Yes, Plain and simple. Read Teach Yourself Programming in Ten Years by Peter Norvig
  2. Care about people than process
    Most of you would have heard “People are the center of every problem” quoted mainly by managers, HRs etc. But for me, People are the center of every solution. None of the **greatest** process can solve any problem with out right people. In fact all great projects/events in the history of the world are remembered, by remembering the people who were involved rather than process they followed. So give importance to people, break the process but don’t break a human.
  3. Be the worst team member
    At the risk of sounding very controversial, Yes, you should be the worst team member in your team. I believe in learning from team members. You have better chance to learn when everybody is better than you. Where you can learn from every contact, every conversation and every minute. Its good to lead a team. You might get promoted if you lead a team. But you should realize that you are losing on learning. Its very important to be lead by a leader/thinker early in your career and also to work with a great team. Remember: Its good to lead but its best to be lead by a good leader. They also make you better future leaders.
  4. Have personal projects
    Many would have written about it. If your employer supports your personal project then nothing like it. If not make sure to have some personal project. You can start from writing simple tools/scripting. Once you feel better try to contribute to a open source project. Later you can have your own big project. There is nothing like self learning, your personal projects will give you a chance to learn what you want. It also gives a chance to escape from **ordinary regular work**. Updated: You should read Scott Berkun’s post on 20% time.
  5. Use tools or use Unix
    Few days back, my friend was wanted to know why I am not interested in solving sudoku. According to him, its the most famous games amongst geeks just like rubik’s cube. For me I want to solve the problem for ever (I know how stupid I sound). I would probably write a program to solve the sudoku/cube than solving it manual. Now coming back to the point, use tools at work. Even if it is a very boring manual work. Try to automate it, make it a programming problem. Learn different tools. (I met this guy who was working on excel sheet to make some reports. Now it sounded like a very boring stuff. But actually he could have programmed in vb script to completely automate the reporting. Now it sounds better right?) While learning tools..Learn the mother of all tools: Unix commands.
  6. Attend conferences and meet people
    I cant stress enough on this. Every time I talk to somebody at office who comes for advice, this is what I give them. None of the communities in the world is as disjoint as Indian IT (developers) community. Please do go out, attend meets, conferences. You will learn as well as your professional circle gets bigger. Even volunteering at conferences like foss.in or barcamp will give you a great opportunity to learn.
  7. You don’t have to learn to knot a tie
    You know what I mean. Sometimes you need to follow the rules but programmers have their own way of satisfying their own ego! No. I don’t know how to knot a tie and I am not willing to learn in near future.

I hope it helps to somebody at least.

Picture Credit: Wikipedia and FOSS.in

Do you moderate your own tweets?

Posted by Thejesh GN On October - 6 - 2009

There are both positives and negatives being on twitter. I get to share interesting stuff, like live pictures, articles, posts, ideas, travel experience etc. I also get to read. I have got so many great answers to my questions, that i reach to a twitter client as soon as I have a question. Its special while traveling as you get answers in real time. I have also tried to help people. Twitter is the new **water cooler**. Yes I use it to track my boss too :)
Dilbert.com
On the negative side anybody can easily track me easily. There is information overload. You really can not keep up with everybody as you start following more and more people. And last but not the least tweeting when I am angry

The positives have been so overwhelming that I don’t consider negatives as negatives except point #3. So now, I have a rule. Don’t tweet when you are angry. I give two thinkings before I tweet anything negative. Since tweeting is easy, we generally tend to judge everything in 140 seconds. Twitter has bigger effect (as much as a blog post if not more), so we need to responsible before we comment on anything. I must agree those #fail tags have helped me many times but I personally think twice before I tag anything #fail. So do I moderate my tweets? Yes, I do.

Do you moderate your own tweets? In what scenarios?

Get in touch