A Wonderful World

We Live In A Wonderful World

We Live In A Wonderful World

I’ve been sitting bored for quite a while now. The only thing that I’ve been doing is to procrastinate. A lot of interesting things happened since my last post. A friend got engaged, we had Vishu, and a lot of other stuff, some of which are being kept secret for now. I’ve been spending a lot of time just reading and watching videos of all sorts. My newly found interest is in Ars Technica, and I’ve been reading news and articles from the specific website way more than I read from every other. Overall, things are going normal, I guess.

The only thing that I have made that I’d like to show everyone is a simple one-page website, created for no reason at all. One day, I was sitting and just felt that I could do a single page website! Then I asked myself, what topic should I choose? Now, I’m a really simple person who believes that everyone in this world deserves some minimum facilities that we are getting. And hence, I just made the following page. A Wonderful World. It’s nothing AWESOME, but to be honest, it wasn’t meant to be. It was created to act more as a reminder for me. To remember not to overuse anything. To not waste anything. And to help others.

But in case you would like to share the page, please do! Here’s the link again. A Wonderful World
Seriously Crazy.

HTML5, WebGL, Three.js Experiments ….

 

Where was I all this time? Where did I go ignoring my urge to write a blog post once in a week? Well, I’ll tell you! I was busy reading and learning about HTML 5 and WebGL. Okay, it is not accurate to say that I was learning HTML 5 as a whole. But the thing I was more interested in was the <canvas> element. I had the pleasure of reading a book titled “Foundation HTML5 Canvas” by Rob Hawkes. I haven’t finished reading it completely, but I’m reaching there. It’s an interesting read, especially if you are into drawing and animating things. I can’t say that I’ve become a HTML5 Canvas Guru but rather, I now have some understanding of how these things work.

HTML 5 Canvas (2d Context)

I had so much fun playing with the 2D Context of HTML 5 Canvas element. Especially, playing with images. You could easily  make a simple image editor using the functions provided. And there are a lot of libraries available, like CreateJS suite, KineticJs, Quintus, ImpactJS, LimeJs, …etc. These libraries make the usage of canvas a breeze, providing you with all the tools necessary to make wonderful interactive graphics and games.

Three.js

The next thing I was busy experimenting with was Three.js. It is an awesome JavaScript library which acts as a wrapper for Canvas and WebGL. The project is still in major development phase, but what it can do currently is great. There are many examples listed in the project page and one of them is the famous “FindYourWayToOZ” website. I’m now deeply regretting not listening and learning the trigonometric functions and vector mathematics properly. I’m currently having to go through some of these functions regularly and I end up spending more time learning Mathematics! I guess it is a good thing too.

 

I’ve created a GitHub repository containing examples of things that I’ve learned during the past few weeks. If you feel like it, you could check those out. I’m in no condition to write a tutorial or an article on these topics as I feel that my knowledge is greatly limited at this time. But may be, in the future, after I’ve accumulated enough information, I’ll write something. Most probably a guide. For now, I’ll leave you guys with some links and demos that shows the great potential Web Graphics holds.

My GitHub repository : github.com/rahules/html5-canvas-examples

A simple canvas demo : jsbin.com/onurig/3

Learn HTML 5 Canvas : www.html5canvastutorials.com

Three.js  : mrdoob.github.com

HexGL (A game using HTML 5, JS and WebGL) : hexgl.bkcore.com

 

Seriously Crazy.

Angler Inspiration!

I think I’m recovering. Recovering from the drought that had occurred to my ability to create something. Recovering from the lack of inspiration that I had felt for long. Everything is getting back to being exciting again. It’s not every day that I would sit and work on something for hours if I weren’t asked to. But today was different. I spent a few hours making different copies of a new wallpaper, which I think is “cute”, or may be, “interesting”?

Here is the wallpaper I had cooked up today.

res32.deviantart.com/art/Ooooo-Pretty-Light-357214990

Oooo Pretty Light!

I have been experiencing problems uploading the original versions of the image here. So please see and download it from my deviantArt page: http://res32.deviantart.com/art/Ooooo-Pretty-Light-357214990 (1920×1080 px)

The angler fish, the prey fish and the jelly fish were done in Inkscape. Everything was assembled in GIMP and some filters were applied to get the effect. I am starting to love the “Apply Canvas” filter in GIMP. It has been proving to be really helpful in making the image look neater.

On another happy note, the last wallpaper “Landscape” has been accepted in SmashingMagazine’s March wallpaper section. There are some awesome wallpapers created by some very talented people. Check it out and download the one’s you like. http://www.smashingmagazine.com/2013/02/28/desktop-wallpaper-calendar-march-2013/

I’ve also started reading more about the HTML canvas and game development using Canvas and Javascript. Should be interesting. There has been a sudden interest toward the whole Web technologies, which I think is a good thing. We will see what happens as time moves on. But this is it for today.

Seriously Crazy.

jQuery Plugin – Quadratic Plot

OQAAAI1PPrJY0nBALB7mkvju3mkQXqLmzMhxEjeb4gp8aujEUQcLfLyy-Sn4gZdkAas6-k8eYbQlGDE-GCjKfF5gIrUA15jOjFfLRv77VBd5t-WfZURdP9V3PdmT

 

 

 

I’m excited! Well, not very much, but yes, I’m excited a bit. Compared to last week when I was completely incapable of completing something, I should be excited now. OK, let me explain now. Last week was a nightmare. I couldn’t think straight. I was unable to finish things that I had started. I couldn’t do some projects that I had hoped to do. I wasn’t even able to imagine things. Everything was blank. I guess my brain just switched to power-saving mode, or something like that. And those are the reasons for the lack of blog posts last week. But the weather has changed. Like the sudden rain that came out of nowhere in the middle of the night yesterday,  an idea came to my mind too. No, it’s not a revolutionary idea. Neither is it even close to being good. It’s a crappy idea, but considering the situation, it felt like a blessing!

So, you may be wondering what the hell I am talking about. Well, I managed to write my very first jQuery plugin. Yes! After a long time, I’ve accomplished something! Isn’t it great? (No, this is not sarcasm. It’s pure joy).  Anyway, looking at what the plugin does, I actually took a lot of time learning how to do things, rather than implementing it. But let me tell you that it was pretty darn easy. Seriously, it is! And I have been encouraged to write more, or may be enhance on the current one, to learn more about jQuery plugins. It took me about a day to write it, which when considering what it does,  is not actually necessary. But since this is my first time, I think it’s acceptable.

The Plugin

I know. I still haven’t said what the plugin is about. Well, it plots the graph of a quadratic equation on an HTML canvas element. Yes, that’s it. There’s nothing more. I told you it was crappy! Anyway, it also supports a few options like smoothness, scaling,drawing the axis, grids, and colours. Now do you want to know how I created this super awesome plugin? You don’t? Yeah, I figured you wouldn’t. There are plenty of articles lying around which guides you to write jQuery plugins. Here is the official documentation of authoring a plugin. Actually, this document in itself explains pretty much all the basics.

jQuery Documentation – Plugin Authoring

You will also want to use the jQuery Boilerplate to get you in gear. The boilerplate is very useful since you don’t have to start things from scratch. And it’s heavily commented so that you will know where everything fits. For me, I also had to look up a bit on the HTML5 canvas element and it’s properties and functions. Trying to use the plugin inside a WordPress post is not working and as such I’m unable to demonstrate the plugin here. So you can check it out on my GitHub page.

GitHub – rahules/jquery-quadratic-plot

or view a live demonstration at jsFiddle

The problem with the plugin is that it only works with equations in one variable. That is, of the for ax^2+bx+c. It runs over a loop where it iterates the x value, substitutes the value in the equation, calculates the point and then plots it. I have seen that there is a quadraticCurveTo() function defined, but I haven’t been able to use it as of yet. Below is a small piece of code from the plugin which draws the curve.

while(Math.abs(prev_y1) < params.max_y ){

    //Calculate value of the function for value of x
    y = (-1)*((a*(x*x))+(b*x)+c);
    //Convert the values in to pixels and multiply with unit for scaling
    new_x=x*this.options.unitPixels;
    new_y=y*this.options.unitPixels;
    //Calculate the symmetric value for x for the current point
    negx =new_x+2*(temp_h-new_x);
    //Draw the 2 lines. Only x value changes for symmetric points
    this.drawLine(prev_x1,prev_y1,new_x,new_y,ctx);
    this.drawLine(prev_x2,prev_y1,negx,new_y,ctx);
    //Store current values for use in next iteration
    prev_x1=new_x;
    prev_y1=new_y;
    prev_x2=negx;
    //increment x with the defined step value in options. 
    //the smaller the value, the finer the curve. Default is 0.5
    x+=this.options.step;
}

 

Another thing I’m looking forward to is extending the plugin to be able to plot other equations. But I’ll just create it as a completely new plugin if I move on to doing it in the future. There are plenty of plugins out there which could do these things. So the chances of me doing it is slim. For now, I’m trying to finding ways to optimise this one and may be add support for quadratic equations in two variables.

Ok, that’s it for now. Time to move on and learn some more mathematics! And if you haven’t checked out the source yet, here’s the link one more time!

GitHub – rahules/jquery-quadratic-plot

Ciao!

Seriously Crazy

Fooling Around

I’m not always bitter! And when I don’t feel like complaining about things, I take the time to sit back and relax. I’ll unplug the headphones and let the music out and loud through the laptop speakers. I sing along to the songs and lets myself go. Then, may be get a pen and paper and sketch random stuff. Today was such a day. Even though I had some things to finish, I decided to procrastinate! A quote I read gave me the inspiration to do so. Well, I’m not going to say what the quote is, as it doesn’t matter. The point is that I had some time and I just scribbled stuff. And here are a few.

 

DSC00256

DSC00257DSC00258

 

 

 

 

 

You could go to http://res32.deviantart.com to see more sketches and other stuff by me. How awesome is that!

That’s it for today. As I said, this was a day to relax. And I’m going back to watching Homeland which is the show that has currently got my attention. Till tomorrow.

 

Seriously Crazy.

Who Wrote This!

 

Source: XKCD

Source: XKCD

Recently,  I was assigned to fix certain bugs and possibly add a few changes to an already complete PHP project (or that’s what I thought ). Since I had nothing better to do, I welcomed the job with open hands. I had some good experiences with PHP and it felt like home ground. Just some bugs; easy stuff,  I said to myself. I was SO wrong. I was given the code a few hours later.

Who wrote this code? was the first thing that came in to my mind.  It looked as if it was written by someone who didn’t bother to think that someone else would be looking at his code. I am someone who believes in writing clearer code, even if it means writing longer lines. There’s no point in writing something if you can’t convey your message to others. Source code for a program, like any other writing, needs to be clear. It should be readable and understandable. No one reads a book if they have to spend hours looking up what a single line in it means. And the same holds true for programming.

Now, I don’t want to sound like I am exaggerating. But the truth is that the most difficult part in this job was understanding the code. To make matters worse, there were no comments, which made my life even more difficult! Here’s an example.

<?php
$mhc=array();
$d1=array();
$d2=array();
$mqry=mysql_query("SOME SQL SELECT STATEMENT");
$mrow=mysql_num_rows($mqry);
$mc1=0; $ldt=$fdt; $pmhc="";
for($mc=0;$mc<$mrow;$mc++)
{
$md=mysql_fetch_array($mqry);
if($pmhc=="") $pmhc=$md[1];
if($md[0]<$fdt)
{
$mhc[0]=$md[1];
$d1[0]=$fdt;
$d2[0]=$tdt;
}
else if($md[0]>=$fdt && $md[0]<=$tdt)
{
$mhc[$mc1]=$pmhc;
$d1[$mc1]=$ldt;
$pd=strtotime($md[0]);
$pd=date('Ymd',strtotime("-1 day",$pd));
$d2[$mc1]=$pd;
$pmhc=$md[1];
$mc1++;
$ldt=$md[0];
}
}
if($mc1>0)
{
if($d2[$mc1-1]<$tdt)
{
$mhc[$mc1]=$pmhc;
$d1[$mc1]=$ldt;
$d2[$mc1]=$tdt;
}
}
?>

The unfortunate thing is that this was the file that I opened the very first time. I literally said the F word then and there. I knew that this was just the beginning. Over the weeks that passed, I learned and understood more about the code. A lot of the code was redundant and it would’ve been easier using OOP and functions.The database query statements could have used prepared statements.  There are many other examples that I would like to show but the blog entry may just become huge if I were to point out mistakes. But here is another small example where the coder tries to convert a date string from m/d/Y format to Ymd format. (02/05/2013 to 20130205)

$dt=substr($jdt,6,4).substr($jdt,0,2).substr($jdt,3,2);

One of the easiest way he could have done this, instead of using substring,  is:

$dt = date("Ymd", strtotime($jdt));

Another thing that fascinated me was the use of 4 different formats for storing date and time in the database tables. I am not saying that I always write good code. But I try to be clear and concise as far as I can. Revising the code is another thing that I try to do. When I write something, I am pretty sure that the code will be unstable and inefficient. From there, I pickup and try to clean everything up.

Despite all this, I must say that the coder alone is not to blame.  I have no idea how much time he had in his hand and how many times the requirements changed. Yes, over the course of last few weeks, I have also gone through situations where the requirement has changed multiple times. This is a problem with offshoring. There is no direct contact between the original client and the programmer. Everything is done through a middleman and it gets really ugly. I had to go through a situation where I enquired if there’s a chance for a requirement to change and the reply was “For now, it is to be implemented as given“. Sure enough, there was a change in the specific requirement a few days later. I still haven’t got any time to revise the code that I have written. And since the requirements are to be implemented over a code that was not designed to be scalable, it makes the code; a maze that cannot be solved.

So where does the problem lie? I believe that the project got to this stage because the client didn’t monitor the quality of the code. They should have checked if the code is efficient and written under acceptable standards. If that were the case, maintaining the code would have been a breeze. I pray that I don’t have to bother about the project once this is finished.  As I have mentioned previously in an older post, some poor guy will possibly end up in my current situation. As for me, I am blaming myself for accepting the job in first place. The one good thing that has come from the whole situation is that I have learned that I should go over the code thoroughly before accepting jobs like this. Now that’s something to cheer for!

We are all human. We make mistakes. But when we decide to qualify ourselves as a programmer or software engineer or a person of any other profession, people expect us to show a certain amount of proficiency in that field. And we should strive to get to a position where people start appreciating us for the work we are doing. A position where we start respecting ourselves. A position where there are less complaints and more compliments. This is a gradual process that takes a long time and all we can do is try.

 

Seriously crazy

Purchase Management What?

 

Image courtesy of Baloocartoons.com

Source: Baloocartoons.com

Seriously? Purchase Management Systems? It has been done plenty of times! There are open source projects available that adhere to the standards. There are free alternatives that look and work almost as good as the paid one’s but just need a bit more configuration. Why are we doing this over and over? I have no idea. It is “almost” like reinventing the wheel. Almost; because we do change the colour of the wheel so that it looks different from the original. Or may be add a different tread. But it still is the wheel!

I’ve been assigned (well, technically, the fact is that I’m not sure.) to a project that involves development of a Purchase Management Software, which basically is inventory management at the core. Now, all I know is that the project is going to be done in .Net. But I do not care which language it is going to be done in. For me, it is and always will be JUST another wheel. Doesn’t matter if you do it in .Net, Java, C++ , PHP or anything. Don’t get me wrong, developing an inventory management software does teach you a few things. It is a learning ground to know more about databases, UI design, programming techniques like OOP vs. modular etc… If the project is big enough, it helps you learn about working as a team; and thus, better coding practices, communication skills, and a whole lot of other qualities that are required by a good software engineer.  But  these products are ordinary. There’s nothing new to see in these products. They are just robust (if the developers are good) software,  that makes inventory management jobs easier.

This isn’t me. I am more attracted to simple yet interesting programs. I want to innovate. I do programming because I like it. I’m interested in developing tools that the people I know would find useful. I want to make software that would make people say “AWESOME!”. I want to make software that inspire people.  I want to make software that people don’t even recognize as software, but rather, as a part of life. I want to make software that would become a foundation for new technology. I don’t want to do something that would have me dislike the things that I like. But everything is easier said than done.

At the end of the day, I can’t just blatantly dismiss inventory management systems, POS systems, purchase management systems or whatever. For all I know, it may be the thing that I get paid for. And my good friend once said that we won’t know what is going to happen until we try. So, I’m opening up to new experiences. And only time can accurately predict if I will like what I am going to do. But I’m pretty sure that once I am done with it, I will try to move on as quickly as I can. Now it’s only just a waiting game.

Seriously Crazy.

Python, XMPP, Google Talk

XMPP Logo

XMPP Logo

Yesterday, my friend Hemanth and I were talking and he came to mention how easy it was to use Python and that a lot of things just require few lines of code. He also mentioned about the large amount of Python packages and modules available. Me, well, I am a cynic when it comes to Python. I’ve made my hands dirty using Python before and I didn’t like it. It is not that Python isn’t easy or “awesome”, but my old programming mind cannot imagine a code without curly braces! I love those curly braces that are used to specify the start and end of a block of statements. And even though one part of my mind tells me to move on and accept Python with two hands, I just can’t do it. But I thought it was cool when Hemanth mentioned about a script he had with him that can automate replies to GTalk.  I wanted something like that. And so I started digging up information about how to do this.

The first thing that I did, like any sensible person would do, was to Google! And voila! There were so many hits. GTalk, like many other, uses the Jabber/XMPP protocol. I went on a googling spree for some time, getting information about XMPP and Python packages or modules that provide a library for the protocol. I stumbled on a few. Some of my options included using the Google Apps SDK, JabberPy or XMPPPY. I settled for XMPPPY and quickly moved on to install the python-xmpp package on my Ubuntu machine!

I am not going to explain things that have already been explained pretty well in other places. So here are two links that would help you understand this article a bit more.

The XMPP Protocol

The XMPPPY Library

When it comes to Python, I’m a “noob”. So, even after installing the package, I had little idea on what I should do next. Sarath Lakshman of LinuxForU.com helped me through the article he wrote: Use XMPP to Create Your Own Google Talk Client. It was exactly the thing that I needed.  So taking the  information from the article and a lot of googling, I managed to implement a few things that I liked. So here it goes.

The first thing is how to connect using a username and password. For Google Talk, the username is your email id and the password is, well, the password of your Google account. The following code initialises the account and sends initial presence.

user = "username@gmail.com"
password="googlepass"

jid = xmpp.JID(user) 
connection = xmpp.Client(server,debug=[]) 
connection.connect() 

result = connection.auth(jid.getNode(), password, "Some-Client-Name") 
connection.sendInitPresence() 

while connection.Process(1): 
    pass

The connection.Process(1) is an infinite loops which processes responses. The code at this moment does not do much.

Quoted from LinuxForU : Switch the debugging on: change theconnection = xmpp.Client(server,debug=[]) line to connection = xmpp.Client(server) by removing the debug=[] parameter. Now when you run this script, you can see the XML stream.

Now let’s find out how to register a call back function so that we can reply when a message arrives.  The following code does this on line 10.

user = "username@gmail.com"
password="googlepass"

jid = xmpp.JID(user) 
connection = xmpp.Client(server,debug=[]) 
connection.connect() 

result = connection.auth(jid.getNode(), password, "Some-Client-Name") 
connection.sendInitPresence() 
connection.RegisterHandler('message', message_handler) 

while connection.Process(1): 
    pass

This code says to call the function named message_handler when a message stanza is received. The above code, if run, will result in an error since we have not defined any function of the name message_handler. So we define message_handler function.

def message_handler(conn_object,message_node):
    print message_node.getBody()
    message=raw_input("Enter reply : ")
    conn_object.send( xmpp.Message( message_node.getFrom() ,message))

The function accepts two arguments, the connection object and the received message node. We first print the message received. The getBody() method is defined for the Message object in XMPP.  We get a reply from the user and send the reply using the connection object. You could just define a static message and send it without requiring a user input. For eg., you can set up an away message. Simple! More information on XMPP Message Objects

Now since we have added a handler for message, why not add one for the Presence stanza. The Presence stanza informs about the change in availability/status of a user. We can add another handler like in the following code.

connection.RegisterHandler('presence', presence_handler)

We now define the presence_handler function.

def presence_handler(conn_object,presence_node):
    print presence_node.getAttr("from")
    print presence_node.getShow()

The getAttr() is a method of simplexml.Node object which is inherited by the presence object. The getShow() method returns the status (“away”,”chat”,”dnd”,”none”) of the user. More information about XMPP Presence Objects

Handlers can be attached to other stanzas like the IQ stanza and other stanzas defined in the XMPP protocol. Throw in a nice UI and some threads and you get a Google Talk client! That was easy. Well, of course, there is work to be done when it comes to doing such a project, but Python does make it easier, combined with the nice XMPPPY library.

In the end, I haven’t started loving Python, but I do find it useful. And though I would have to evolve  my mind to accept the Python principles, I sure hope that someday we become friends! Till then, I’ll keep experimenting doing silly programs, understanding Python and it’s awesomeness!

Seriously Crazy

When talking to oneself isn’t enough.

Yes, there comes a time, when you start to get bored talking to yourself in your dull old room. And when that happens, there is a  sudden urge to communicate the thoughts that you’ve thought all these years with everyone around. May be, and just may be, you hope someone will notice. You think about changing the world. You believe that your ideas are revolutionary and the world needs it.

Well, I’m passing through such a time in life. And even though, I don’t have many original ideas that I want to communicate, there are tons of other things that I do want to talk about. As I am writing this, the only intended audience I have in mind is my alter-ego and I. And so, this blog is susceptible to somehow end up being like a diary, but for my sake and yours, I hope that does not happen.

I am a programmer. I’m not a good programmer, but I am one. I try to jump in to other activities like designing or writing but when the smoke clears, I’m just another average programmer. And whenever I think about this fact, my plans for the future and everything that I’ve dreamed of becoming just evaporates. But suddenly, someone inside (probably the alter-ego) knocks me hard and tells me to do something about it. But the problem is that I’ve always been short on ideas. I have never had a good original idea light up in the brain. The only thing I’ve made till today that was made out of my needs  was a encryption program, which i made because I wanted to hide files (ehm..) from my brother. That was 6 years ago.

Fast forward to today, I’m still dealing with programming but my work involves going through someone else’s code, trying to understand what he has tried to do, and fixing bugs and implementing new requirements over this same code, which later ends up as one big MESS. I am pretty sure that when the time for maintenance of the code comes, and if some poor guy had to go over this code, he’d either rip his hair off, or get a shotgun and come over to my house. We can guess what happens next! *POW* But I’m hoping the future me is genius enough to know this and will have found a way around this. Like Kevlar, or a clone! Or may be, the people would just dump this software in a year.

I’ve decided not to give up though. There are plenty things to do for everyone and I’m sure I can find things that would keep me interested. And when the million dollar idea hits, I’ll be ready to pounce on it! That’s it for today.

Seriously Crazy