Saturday, December 13, 2014

My Bash Script Editor - The Rights and Wrongs of how I went at it!

I have been working on developing a "Bash Script Editor" and I have been at it for weeks dedicating at least an hour a day. While I was working on it, I realized that I was doing it all wrong and now I'm in this dilemma of whether I should keep working on it till I get atleast a beta version or I should just leave it undone and concentrate on more important things.

Snapshot of my Bash Script Editor

While I was working on ETL scripts at my work, I was using Notepad++ as my editor. It worked absolutely fine except I was totally new with the scripts to know where the functions referred in the scripts were actually called from. Having been working with powerful IDEs in the past, a simple editor to manage such a huge project seemed impossible to me and that was it. Thats what triggered me to build a more powerful editor just for Bash scripts.

The idea first seemed fine to me expect when I realized how big of a task it was and I was the only one really eager to do it. So, here I am sharing my experience so that I or anybody reading not to do/repeat such things with a list of -the rights and wrongs with my approach.

What did I do right?

1. The concept seemed valid and I was eager to do it.

What did I do wrong?

1. I didn't sketch a plan of how I was going to do it. A simple list to features to add, scope of functionalities to look into or may be a rough class diagram to build upon would have eased things up abit. I remember I was hesitant to do it because I thought I should just get right at it and get it done quickly. That simple hesitation went on destroying my whole effort in the end.

2. I was working on it alone. A small team of 3-4 people collaboratively working on modules would have been brilliant. With a team, the work would have been more organized, faster and optimized.

3. If I wanted to do it so eagerly, I should have first searched for any relevant open sourced projects that I could contribute with the feature. It is always a good habit to do it, only I didn't do that.

4. If I didn't want to make it big and just wanted to do it for experience and fun, then I should have done something that I could learn from. Throwing random line of codes and scratching your head to think of a solution just to make up for dirty codes done earlier is a very unhealthy habit and something that every programmer should avoid.

5. Stop before its too late. If you realize, even in slightest, that you are doing it wrong and you are only making things complicated by just adding random features, you should probably pause and look at what you've done. This would have saved a lot of my precious time.

6.  Always start with a solid base to work upon. Defining abstract classes and building your way up with it is always a good habit. A good base will always keep things organized.

So, there you go. Before you go and laugh at me or maybe judge me as a programmer, please note that I was doing it all during my office hours. I didn't have enough breathing space to look at what I was doing, all I wanted to do was to complete the task in hand when I had free time. Despite knowing it all, deep down inside, my major regret is that I started the work anyway completely underestimating the difficulty of the task.

Here's the link to the project : Bash-Script Editor (try not to laugh too hard :P)

Friday, November 14, 2014

Perlin Noise [Implementation in Java]

I had previously talked in detail about Perlin Noise and its properties, here. Now in this blog post I will write about the implementation. My implementation is based on an excellent writeup which I found in this link (

Short Description

Fig: Perlin Noise(left), Noise(right)

Perlin noise is a function for generating coherent(smooth) noise over a space. I've have come across multiple implementations of Perlin Noise function and most of them are based on smoothing of multiple noise functions to generate a coherent noise. The one I am discussing in this blog post is alittle different and more or less conforms with the original implementation that Ken Perlin came up with.


Perlin Noise (2D) function is a function that takes two points (x and y) and returns a noise value (say z). x, y and z are all floating point numbers.

The Grid

The concept of accepting floating point numbers can be explained from the concept of Grid. The space, which the noise function operates on, is assumed to be composed of grids. Grid, in terms of x and y, are the whole numbers. So, any decimal (fractions) are points lying inside a grid cell.

In the figure, (x0,y0), (x1,y1), (x0,y1), (x1,y0) represents grid points and (x,y) lies inside a grid.

Pseudorandom Gradient

Pseudorandom Gradient function takes the grid coordinates and generates pseudorandom gradient of length 1 as:

g(xgrid, ygrid) = (gx, gy)

These gradients can be visualized as:

Calculating grid influences

Next, We need to calculate a vector directing from grip points to the point (x,y).

vec00 = (x-x0,y-y0);
vec01 = (x-x0,y-y1);
vec10 = (x-x1,y-y0);
vec11 = (x-x1,y-y1);

The influence can be calculated by performing dot operation on the gradient and the vector as:

s = g(x0, y0) · vec00;
t = g(x1, y0) · vec10;
u = g(x0, y1) · vec01;
v = g(x1, y1) · vec11;


A smoothing function, characterized by the curver 3p2 - 2p3, is used to get a weight Sx at (x-x0) in the curve as:

Sx = smoothParam(x-x0);

and also at (y-y0) as:

Sy = smoothParam(y-y0);

where smoothParam(p) = 3p2 - 2p3 , then parameter representing weighted average of s and t is obtained by constructing a linear function mapping 0 to s and 1 to t, and evaluating it at our x dimension weight Sx. We call this ax.

        ax = s + Sx*(t - s);

We also calculate bx using u and v as:

        bx = u + Sx*(v - u);

Then the final result z can be obtained as:

z = ax + Sy*(bx - ax);


I have implemented this algorithm in Java, and I have uploaded the project in github. You can view it from the link here.

Monday, October 27, 2014

Triplet Extraction from Sentence [Implementation]

Many sentiment analysis tasks require extraction of sentence triplets, ie. Subject - Verb - Object, from a sentence. While there are many approaches to the problem, I recently stumbled upon a fairly easy-to-implement algorithm in a research paper (

Wednesday, August 13, 2014

Morphological Analyzer for Nepali Text

Morphology is the part of linguistics that deals with the study of words, their internal structure and syntactically their meanings. A Morphological Analysis is the process of providing grammatical information of a word by detecting its morphemes. A morphological analysis generally consists of following information:
Word segmentation
Part-of-speech tagging

These are the very basics of linguistics which lays ground to many other applications. There are various different tools and resources available for morphology analysis of popular languages such as English, but morphological analysis of Nepali texts had been in a shadow for long. Fortunately, the need of these analysis has slowly been recognized.

Monday, May 19, 2014

Saturday, May 3, 2014

Farty Bird :D

Finally my month-long exam is over and I can finally concerntrate on one or two projects in hand and I will certainly be blogging about it.

The Farty Bird :D
So what's with the "Farty Bird" you may ask? Well, my 11-yr old brother wanted me to make him a game, which he wished to call the "Farty Bird" and he also promised to help me during the development process, the offer I couldn't reject.

Monday, February 24, 2014

Monday, February 17, 2014

Friday, January 31, 2014

Saturday, January 11, 2014