ankit gupta


Know thy language's operators

Whenever I pick a manual for a new language I often skip the first few chapters that introduce operators, conditional, etc. This is because for the most part these constructs behave the same way for most of the languages that implement them.

More …

Ruby in 2022 ?

Some time ago StackOverflow released the results of the 2021 Developer Survey. One of the things that I was interested in was how the Ruby community is doing (at least the one on StackOverflow).

More …

Separating presentation concerns

When building applications that present information to the user — either via CLI or GUI — we have to write code that formats information so that it is easy to read. Presenter pattern is a simple pattern that separates the “presentation” and business concerns.

More …

Memoization

Memoization is an idiom in Ruby that allows developers to avoid performing expensive computations again and again. For example, suppose you have a method price on an Item class that will be called multiple times, but you do not expect the price to change everytime that you call that method during a session or a request, you can memoize the price.

More …

Using next and break to return values

You are likely already familiar with using the next and break keywords in Ruby. You might have already used them in your programs for control flow in loops. Here is a quick refresher

More …

Does your organization really need microservices?

It is important that you understand the value proposition of microservices before you can decide if you really want to migrate from your current architecture to a microservices architecture. It is also important to keep in mind that "Monoliths" and "Microservices" are not your only choices. Microservices and monoliths are two ends of a spectrum. There are several alternatives in between. More …

Why you should deploy to production more often?

Frequent deployments allow the developers to get early feedback and correct their course. There is some research that suggestshows a positive correlation between high-performing teams and deployment frequency. In this post, I talk about why frequent deployments are important and how you can increase your deployment frequency. More …

How to set Capistrano to share SQLite database across releases?

Rails applications that expect heavy traffic require a scalable database such as Postgres or MySql. However, SQLite might be sufficient for low-traffic applications or apps in the initial development phase, where you do not want to spend the resources and time required to set up and configure a database such as Postgres or MySQL.

More …

Is Chromebook for you? — the goods and bads of a Chromebook

My Lenovo laptop broke a few months back. I sent it for repairs and needed something cheap and lightweight in the meantime. I always wanted to use a Chromebook for fun but never considered it suitable for my needs as I develop primarily in Java. However, this time I was working on some projects where I was doing front-end web development and visualizations and a Chromebook would would have worked for me. I could still ssh into my Linux box to do some Java development (although I won’t recommend it). I finally bought a  Acer Chromebook 13 (CB5-311) and I have been using it regularly for over a month now. I have some good and bad things to say about Chromebooks and a little something about the whole idea of “moving to cloud”.

More …

Visualizing semantic role labels using heat maps in Excel

While doing text analytics on a large document collection, the analyst is often looking for relationships between entities like person, organization, location etc. The existing approaches to finding related entities automatically are quite primitive. They are generally some variant of finding relationship by co-citation of entities and bibliographic coupling of documents. According to this scheme, two entities are considered “related” if they are mentioned in the same document. Conversely, two documents are considered related, if they have common entities mentioned in them. A major problem with this scheme of “relatedness” is that the nature of relationship (semantics) between two entities is unknown until the documents mentioning the entities together are not read by the analyst.

More …

How to use Swing widgets in an Eclipse RCP application?

Eclipse RCP is a great platform for developing nice GUI applications with Java. It provides a wonderful framework to build application with its very useful publish-subscribe event model and annotation based dependency injection. It feels almost like magic when you switch from developing hard-coded Swing applications to Eclipse.

More …

Don't teach them calculus before they can add !!

Lately, there has been quite a discussion online about changing ways to teach computer programming. Programming is being realized as a very useful tool for practitioners in almost every domain. Yet, the way it is being taught continues become more and more convoluted. As a result, more and more students are frightened of the word “ programming”. We have finally managed to make a beast out of something that is amazingly simple in reality. We have also managed to kill the fun and joy that programming has to offer.

More …

Fun with Blender

WoodOnCloth_reducedBlender is a great free and open-source tool for creating 3D computer graphics. In my knowledge it is the only open-source tool that gives a real competition to its commercial counterparts. I have come across it several times and always wanted to learn it. But, I kept procrastinating. Finally, I got some free time last week and got hands on a very nice video tutorial on YouTube. The tutorial is easy to follow and I was able to learn the Blender interface and was able to replicate the tutorials to produce some really nice graphics that I am really proud of. Here are couple of images that I have created so far.

More …

What can you do with Java annotations? – Part 1

Java 5.0 introduced annotations among many things. Annotations are a way of adding metadata to Java elements such as classes, methods, variables, parameters and packages. An annotation in its simplest form looks something like this:

More …

What does brushing and linking mean in information visualization?

Visualization systems generally consist of several independent visualizations, each allowing exploration of a different aspect of data. Over years, researchers have developed several interaction techniques to allow users to explore data. Two of these several techniques are Brushing and Linking.

More …

How to run a loom project from sublime?

Loom is a game engine that provides live update functionality which makes testing code very easy. It is slowly gaining popularity at least among the newbie game developers and students (ones like me) as it is free and provides normal developers to take a shot a game development. without too much investment.

More …

Processing: My first impressions

Long I have not known about an interesting environment for working on graphics and animation. It is called Processing. I have long been using Java for all my desktop application needs (with occasional also some animation/custom component coding in Swing). So, I know the pains of developing even a simple visualization, animation or even a worthy UI using Java/Swing.

Recently I started working for a visualization group as an RA/Lead Developer. At work, it is often a requirement to prototype some visualization real fast and hence I was introduced to Processing. And to put it in words, it was like “I was given a power that I could not wield”, and this was not because Processing was ugly or complicated. Rather, it is because it is very different from what I have been doing so far with Swing. In this post, I will try to discuss my first reactions to Processing, which do not include any code samples (that is for later).

More …

How to get the calling class name from the static method of the superclass in Java?

While coding Java for one of my projects, I came across a  weird requirement. I had a super class that had a static method and I wanted to know the name of the sub classes of my super class that called the method. Let me explain that by example.

I have a class Super that contains a static method superStaticMethod() that prints the name of the class.

package example;

/** Super.java **/
public class Super {

	/** prints the name of the calling class **/
	public static void aStaticMethod() {
		System.err.println("Super static method called from " + getClassName());
	}

	private static String getClassName() {
		return Super.class.getName();
	}

}
Now I have another class `Sub` that extends the `Super` class.
package example;

/** Sub.java **/
public class Sub extends Super {
	// nothing here.
}

Now, whether I call Super.aStaticMethod() or Sub.aStaticMethod(), I will get the same output :

> Super static method called from example.Super

This is precisely because Super class has no idea of which class actually called the method. Had this been a simple instance method, it was simple. I can just use this.class.getName(). But achieving the same effect is tricky because there is no instance involved when calling the static method and calling Sub.aStaticMethod() is same as calling Super.aStaticMethod().

However, after battling with reflection, I found some way which I would like to share. Here is how its done. The trick is that you hide inside the Super class a spy that can tell you who called the method. This spy will actually be a nested static class that will reveal the details of the calling class.

What you need to do is modify the Super class to this:

package example2;

public class Super {

	public static void aStaticMethod() {
		System.err.println("Super static method called from "
				+ new Spy().revealTheCallingClass());
	}

	/** This class helps get the class name */
	static class Spy extends SecurityManager {

		public String revealTheCallingClass() {
			Class[] classes = getClassContext();
			for (Class cls : classes) {
				// check if the class is a sub class and its the Super class
				// itself.
				if (Super.class.isAssignableFrom(cls) && cls != Super.class) {
					return cls.getName();
				}
			}

			return null;
		}
	}

}

Now if you modify the class for Sub to
package example2;

public class Sub extends Super{

  public static void useSuperClassName(){
    aStaticMethod();
  }
}

Calling Sub.useSuperClassName() will print example2.Sub. Note however that calling Sub.aStaticMethod() will still print null or the name of the class in which it is called (if that class is a subclass of Super) which is something that I will try to rectify in future, if possible.

More …

Animating the console!

There are times when I love to use command-line/terminal (whatever you want to call it). And when I do I like to do something fun with it, and not just putting text to read. This post contains two examples of some fun code that you might wanna use to make something nice of your command-line application.

More …

Competition, Collaboration and Software.

If you happen to be a guy who has spent some time in online forums for software developers, you might be aware of the flame wars that go on between different software such as vim and emacs or netbeans and eclipse, or between different operating systems. I happen to be the guy who just hates these kind of discussions. The problem with these flame wars is that they start as simple comparisons or discussions and evolve into pure blasphemy.

More …
Subscribe!
Subscribe to know when new posts appear!