Following are the characters of the OOP:
1. Encapsulation: capturing and keeping data safely and securely from outside interfaces.
2. Inheritance: class can be derived from a base class, and contains all the feature of the base class but it still has some of its own features.
3. Polymorphism: The ability of objects of different types to respond to functions of the same name.
4. Abstraction: representing the data at a very conceptual level without any details.

Reading sam and bam files with SAM Tools

SAM Tools is very flexible framework, that provide various utilities for manipulating alignments in the SAM format, including sorting, merging, indexing and generating alignments. This tool also allows to convert between different formats ex. .bam. It can be used from terminal or as a library. There are bindings to many popular languages: c++, python, java, perl ect.


Create android application by using standard web technologies such as HTML5, CSS3, and JavaScript

The goal is to build applications for mobile devices using well known standard web technologies like JavaScript, HTML5, and CSS3, instead of device-specific languages such as Java or Objective-C.

How do I implement a custom "paging" script for a variable number of items?

A very common problem in web programming is to implement paging. Paging is required whenever there is an undefined amount of items (usually queried from a database) with a maximum amount of items to be displayed on one page. If there is more than one page, there must be a possibility to navigate through these pages while each page displays the desired amount of items. An example will demonstrate the problem: State: - You have a category containing 23 products to be displayed in the category overview of your webshop - A single page should display a maximum of 8 pages for design and usability reasons Now we have to calculate the number of pages, the number of products to display per page and display everything to the user. This case will result in 3 pages: Page 1 will display the items 1-8, Page 2 will display the pages 9-16 and Page 3 will display the items 17-23. Please show a general algorithm for this problem.

Photoupload in a Ruby on Rails application using paperclip

Implementing a custom solution for photo upload functionality can be very painful.

There is a very good ruby on rails gem which provides this functionality called paperclip.

Actually paperclip can handle all file uploads not only photos. But the following description focuses on the photos because it is the most common one.

Paperclip requires at least Ruby version 1.9.2 and Rails version 3.0.

It is mandatory to have an installation of ImageMagick before using paperclip. Keep in mind that you need a local installation as well as an installation on your production server.

ImageMagick can be downloaded here:

Paperclip is a ruby gem. Therefore it is really easy to install it.
The following line has to be added to the gemfile of the Ruby on Rails project:
gem "paperclip", "~> 3.0"

Note: Make sure to upgrade to newer versions of paperclip once they are available by changing the version number in the gemfile.

After adding the paperclip to the gemfile, run bundle install to download the gem and add it to the Ruby on Rails application.

After installation you have to adjust your model (e.g. user):

class User < ActiveRecord::Base
attr_accessible :profilpic
has_attached_file :profilpic, :styles => { :thumbnail => "100x100>"}

This adds a profilpicture attribute to the user model and a custom size of 100x100 pixels.

Next step is to change the database schema to store the new attributes by running the command rails generate paperclip user profilpic

In a ruby on rails form view it is now possible to show on photoupload input:

<%= form_for @user, :url => users_path, :html => { :multipart => true } do |form| %>
<%= form.file_field :profilpic %>
<% end %>

Paperclip handles all the uploading and processing of the image.

Also the photo can be showed in a view:

<%= image_tag @user.profilpic.url %>


Photoupload in a Ruby on Rails application

A lot of Ruby on Rails web applications have to use photos (e.g. for user profiles) In the best case these photos can be already stored in several sizes or otherwise processed before being stored to different possible location. Also these photos have to be attache to a ruby on rails model like an user or an article.

Creating a web audio player with GWT

Google Web Toolkit (GWT) is a set of tools that allows for creating JavaScript applications in Java. For a web application I was working on with GWT, I had to create an audiovisualization unit. For that purpose it was necessary to implement an audio player that would play/pause/resume/stop a sound file by request.

Implementation of drag and drop in JavaScript

Such functionality can be implemented in JavaScript by addition and removal of events. The element that should support drag and drop needs an onmousedown event that calls the function trackElement.
trackElement doesn't do much except for adding two more elements when the mouse button is pressed on the element in question.

The moveElement function is then called each time the user moves his mouse. It updates the position of the element to the position of the mouse (in relation to the element's size). The event is added to the whole window because the user can move the mouse faster than the browser renders, making it possible to outrun the movement of the element.

Finally, stopTracking is called when the user releases the mouse button. It merely removes the events that track the mouse movement and wait for the release of the button.


var trackedObject;

function trackElement(event) {
trackedObject =;
window.addEventListener("mousemove", moveElement, false);
trackedObject.addEventListener("mouseup", stopTracking, false);

function moveElement(event) { = event.clientY - parseInt( / 2; = event.clientX - parseInt( / 2;

function stopTracking(event) {
window.removeEventListener("mousemove", moveElement, false);
trackedObject.removeEventListener("mouseup", stopTracking, false);


Twitter your project status with Maven.

Create a simple hello world Java Maven Project (this is already available as an maven-archetype) and configure it in a way so that every time you make a installation (via the cli command: mvn clean install) a new status update with the message "New Project Built Available" shows up on your twitter account.

Get Class object from generic type T

To achieve to get the Class object from a generic Type a pretty complicated looking command has to be used:

Class clazz = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];

now you have the Class object and can access the annotations with

(([SomeAnnotation]) clazz.getAnnotation([SomeAnnotation].class));



Subscribe to programming