Thursday, January 14, 2016

Setting Up A Proxy For The Atom Text Editor

Atom is an excellent open source text editor that I have switched to recently. Atom requires a network connection to update itself, install packages etc. This usually just works out-of-the-box.

However, if you are behind a proxy server, the proxy settings for Atom can be specified as below. Run the commands below at the OS's command line.

Specify The Proxy Server In Atom

Verify The Proxy Server Specified In Atom

Saturday, January 19, 2013

A Super Quick Start To Git

Git is a distributed version control system. This post is helpful to someone who would like to get quickly started with Git. Once up and running with the commands below, the reader is encouraged to follow-up with the comprehensive documentation on Git available from many excellent online sources. This will help to grasp the core concepts of Git, which are essential for regular use.

Note that this post only covers operations on a local repository. Distributed operations like cloning, pulling, pushing etc. will be covered in a future post.

Quick Git Concepts

  • Git is fully-functional and self-contained with just a local repository. Committing, branching, merging etc. can all be performed locally with no requirement for a central server.
  • Branching and merging are light-weight and extremely fast (local) operations.
  • The (hidden) .git directory within the root of working directory is fully self-contained. Git maintains the entire repository that includes information of all of the branches, commits etc. in this single directory.

Initial Setup

Git embeds the user name and e-mail address in every commit. This configuration is required before we can commit to the repository.

Create A New Repository

Initialises a new Git repository in the current directory. A single .git directory is created in the current directory where Git maintains the repository information.

Add Files To The Staging Area

Add specified files to the staging area. Wildcards can be used (e.g. *.java). Note that staged files need to be explicitly committed to the repository.

Adds any modified files previously committed and also any new files to the staging area.

Check The Current Status Of The Repository

Returns the current status of the repository. This is helpful to see the status of files that are in the staging area but not yet committed.

Commit Staged Files Into The Repository

Branching And Merging

Branching and merging are extremely light-weight operations in Git. In fact, it is even possible, if required to branch and merge several times a day. The root in Git is known as the Master branch. An important point to note is that only a single branch can be checked-out in the working directory at a given moment.

List All Of The Branches In The Repository

Create And Switch To A New Branch

Switch To An Existing Branch

Merging Branches

Merges the specified branch into the current branch.

Deleting A Branch

Note that you cannot delete the branch that is currently checked-out.

Tuesday, March 15, 2011

Messaging With WebSphere MQ Using Spring JMS

Spring JMS provides a simple API to work with JMS implementations. This post describes how to use Spring JMS to communicate with IBM WebSphere MQ. The code has been tested with WebSphere MQ version 7.0.1. Maven is used as the build tool. It is also used to resolve the WebSphere MQ and other dependencies. Only relevant code snippets are listed below - for the complete source, please refer to the link at the bottom of this post.

To start off we need to obtain the WebSphere MQ JARs. These JARs are proprietary - hence they will not resolve through a public Maven repository like Maven Central. These JARs need to be obtained from the WebSphere MQ installation directory and manually deployed to our local Maven repository. The config below defines the WebSphere MQ dependencies in our Maven POM file.

Spring's JMSTemplate class is the key to simplifying access to the conventional JMS API. It abstracts the common and repetitive boiler-plate code by handling the creation and closing of connections and sessions, sending and receiving of messages and handling of exceptions. JMSTemplate and a few other beans need to be defined in our Spring config.

MQQueueConnectionFactory defines the connection to the Queue Manager. Next we define SingleConnectionFactory102, DynamicDestinationResolver and finally JmsTemplate102. The 102 suffix implies that our underlying JMS implementation version is 1.0.2. Now that our configuration is complete, we can send and receive JMS messages.

To send a JMS message, we use the send(String destinationName, MessageCreator creator) method of JMSTemplate.

To receive a message, we use the receive(String destinationName) method.

As we can see, Spring's JMSTemplate really simplifies and speeds-up connecting to a JMS provider like WebSphere MQ.

Sample Source Code
A fully functional example Maven application accompanies this post. It provides the complete source code mentioned in this post. It can be downloaded at GitHub using the link below.

Monday, January 19, 2009

Live and Die with jQuery

jQuery is a JavaScript library that makes web programming simple and highly productive. With the new 1.3 release, jQuery now supports live and die events. To understand live and die events, we must recollect how things were done before the 1.3 release. To bind events to elements we used jQuery's bind method.

$("input:type=button").bind("click", function() {
    alert($(this).val());
});

The code above binds the click event to all buttons on the page. However, there is one major drawback to using the bind method. Any buttons dynamically added to the page in the future must be individually bound with the click event. Hence, bind only works on the set of elements currently in the DOM.

live overcomes this drawback and binds to elements currently present and also ones added in the future. The syntax for live is similar to bind. The code below binds the click event to all buttons currently on the page and even ones added in the future.

$("input:type=button").live("click", function() {
   alert($(this).val());
});

die is the opposite of live. To unbind all events previously bound with live we use the die method.

$("input:type=button").die("click");

Wednesday, April 09, 2008

Advanced Filtering in GMail

GMail provides filters and labels that are an effective way to organize and access the huge number of emails that we receive everyday.

Recently I came across another feature of GMail that takes filtering of email to a whole new level. Every GMail address can be suffixed with a + followed by some text. E.g. john@gmail.com can be aliased as john+family@gmail.com, john+facebook@gmail.com or john+cv@gmail.com. All of the aliased mail gets sent to the primary account (john@gmail.com). This opens up whole new possibilities for powerful filtering.

Take for example the email address you provide on your CV or at a job search website. At times when you are actively looking for a new job, these emails are highly important. During other times, you might not want your Inbox to be cluttered with job notifications. This can be easily handled using GMail email aliases. Simply provide john+cv@gmail.com (or john+123@gmail.com if you wish to be discrete) when signing up at a job search website and on your CV. Next setup a GMail filter that looks for emails sent to john+cv@gmail.com and either flags them for your attention or at other times automatically deletes them!

Email rules and filters have existed for a long time but GMail aliases take this to a whole new level. The possibilities (of email suffixes) are indeed endless!

Thursday, March 20, 2008

Apache Ivy

Almost all Java projects, apart from the most trivial ones have dependencies. These dependencies could either be on other projects or third-party libraries. Managing these dependencies can be extremely time-consuming and distracting from the primary focus of the project. Apache Ivy is a tool for managing library dependencies. Ivy neatly fills the gap by providing an easily configurable and automated dependency management system. Further, Ivy supports transitive dependencies management. Hence all we need to do is declare our main dependencies and Ivy automatically fetches all the sub dependencies along with the main dependencies from a public location such as the Maven 2 repository.

Installation

Ivy is designed to work with Ant, wherein Ant is used to run the build tasks and Ivy is used to resolve, retrieve and manage the dependencies. The simplest way to get started is to copy the Ivy jar file to the Ant lib (ANT_HOME/lib) directory.

Configure ivy.xml

The ivy.xml configuration file is the main file that is used to describe our dependencies. Below is an example of a configuration file that states two main dependencies, Hibernate and the C3P0 library.
<ivy-module version="2.0">
    <info organisation="techvj" module="ivy-test" />
    <dependencies>
        <dependency org="org.hibernate" name="hibernate" rev="3.2.6.ga" />
        <dependency org="c3p0" name="c3p0" rev="0.9.1.2" />
    </dependencies>
</ivy-module>

Integrate With Ant

The final step is to integrate the Ivy dependency resolution process with our Ant build process. Following is an example of a build.xml file with the retrieve task defined:
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="hello-ivy" default="retrieve">
    ...
    <target name="retrieve" description="">
        <ivy:retrieve />
    </target>
</project>

On running the above Ant build, Ivy retrieves the Hibernate and C3P0 libraries and all of their dependencies to the local machine. The retrieved libraries are stored in a cache and not downloaded again on successive invocations. Apache Ivy is a great tool in a Java developer's toolbox for managing library dependencies.

Wednesday, March 19, 2008

Wicked Shell for Eclipse

An Eclipse plug-in that I have begun to regularly use is Wicked Shell. Wicked Shell provides direct access to the operating system's shell (Cmd, Bash, SH etc.). In fact it is not an actual shell, it only acts as a window to the underlying shell using a SWT text widget to transfer commands and display output. The result is having an Eclipse view that behaves as a shell.

As with any Eclipse view that is regularly accessed, I would suggest setting up a shortcut key binding for Wicked Shell. On my installation I chose Alt+Shift+Q, S as the combination did not conflict with other pre-set bindings.