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.
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.
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: http://www.imagemagick.org
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>"}
end
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 %>
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.
Code:
var trackedObject;
function trackElement(event) {
trackedObject = event.target;
window.addEventListener("mousemove", moveElement, false);
trackedObject.addEventListener("mouseup", stopTracking, false);
}
function moveElement(event) {
trackedObject.style.top = event.clientY - parseInt(trackedObject.style.height) / 2;
trackedObject.style.left = event.clientX - parseInt(trackedObject.style.width) / 2;
}
function stopTracking(event) {
window.removeEventListener("mousemove", moveElement, false);
trackedObject.removeEventListener("mouseup", stopTracking, false);
}
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));