vendredi 24 janvier 2014

Example syntax for Secure Copy (scp)


Example syntax for Secure Copy (scp)

What is Secure Copy?

scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

Examples


Copy the file "foobar.txt" from a remote host to the local host

    $ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host

    $ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory "foo" from the local host to a remote host's directory "bar"

    $ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

lundi 20 janvier 2014

How to Install Oracle Java JDK 6/7/8 on Ubuntu 13.04 / 12.10 / 12.04



In this article I will show you how to install the Oracle Java (JDK) 8, Oracle Java (JDK + JRE) 7 or Oracle Java (JDK) 6 on Ubuntu 13.04, Ubuntu 12.10 and Ubuntu 12.04.
The Oracla Java has been removed from the official Ubuntu repositories due to some Java licence issues.
Before you install it, remove OpenJDK, if you have it installed
$ sudo apt-get purge openjdk*

To install Java 8/7/6, do this:
In order not to get issues with the add-apt-repository command, install the following package:

$ sudo apt-get install software-properties-common

Add the PPA:
$ sudo add-apt-repository ppa:webupd8team/java

Update the repo index:
$ sudo apt-get update

install Java 8:
$ sudo apt-get install oracle-java8-installer

Or, install Java 7:
$ sudo apt-get install oracle-java7-installer

Or, install Java 6:
$ sudo apt-get install oracle-java6-installer

mercredi 11 décembre 2013

How to add git remote repository on server

first you connect ssh to your server, then you can set up an empty repository for them by running git init with the --bare option, which initializes the repository without a working directory:

$ cd /var/www/GIT_REPOSITORY
$ mkdir newRemoteProject
$ cd newRemoteProject
$ git --bare init


then you should change the permission into this new remote repository
$chmod -R 777 /var/www/GIT_REPOSITORY/newRemoteProject

Then,all team can push the first version of their project into that repository by adding it as a remote and pushing up a branch. Note that someone must shell onto the machine and create a bare repository every time you want to add a project.

# on Johns computer
$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin http://Server_Adresse/GIT_REPOSITORY/newRemoteProject
$ git push origin master

Note : the path to the remote repository is under /www because i have used gitweb with git over http.

samedi 7 décembre 2013

How to disable JavaScript Validation from Eclipse Project ?



  1. Right click your project
  2. Select Properties -> JavaScript -> Include Path
  3. Select Source tab. ( It looks identical to Java Build Path Source tab )
  4. Expand JavaScript source folder
  5. Highlight Excluded pattern
  6. Click Edit button
  7. Click Add button next to Exclusion patterns box.
  8. You may either type Ant-style wildcard pattern, or click Browse button to mention the JavaScript source by name.
The information about JavaScript source inclusion/exclusion is saved into .settings/.jsdtscope file. Do not forget to add it to your SCM.
Here is how configuration looks with jquery files removed from validation


lundi 2 décembre 2013

Tuckey URL Rewrite


How can we make the web application URL cleaner and prettier instead of showing plenty of URL parameters? Is there a way  for a simple easy solution to do that without configuring the application server like Tomcat? after spending a long time of research and test, i found a tool named  Tuckey URL Rewrite that do exactly what i want.
My needs are the following, i have a java wicket web application with Tomcat 7 as webapp server and want to resolve two problems :

  1. First i would make pretty friend profile link as facebook or Google+, for example applicationName/Firstname.lastname 
  2. Second, i want to implicitly add a dynamic parameter depending on the requested domain name for example :  SuchCustomer.domineName.com should be implicitly transformed to SuchCustomer.domineName.com?CustomertName=SuchCustomer

STEP ONE :

install Tuckey URL Rewrite by adding Maven dependency :
<dependency>
    <groupId>org.tuckey</groupId>
    <artifactId>urlrewritefilter</artifactId>
    <version>4.0.3</version>
</dependency>

STEP TWO :

To WEB-INF/web.xml add :
<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

STEP THREE :

Add urlrewrite.xml in WEB-INF (src/main/webapp/WEB-INF/ for Maven users)  , this file will contain all our rules. so to meet my needs, i write  this two rules:
<rule>
<note>Clean Friend profile URL</note>
<from>^/([a-z0-9]+)\.([a-z0-9]{1,10})$</from>
<to>/FriendProfile?friendLoginID=$1</to>
</rule>

<rule>
<name>Add parameter to URL</name>
<condition name="host" operator="equal">SuchCustomer.DomainName.com</condition>
<from>^/$</from>
<to>?CustomerName=SuchCustomer</to>
</rule>    

 For more information about this tool, take a look at the official documentation.

mercredi 27 novembre 2013

Event based communication between wicket components


when we have a page structured with multiple panels, we need some times to update a component into a one panel following an event into another different panel in the same page, so how can we fix this type of scenario?
Starting from version 1.5 Wicket offers an event-based infrastructure for inter-component
communication. The infrastructure is based on two simple interfaces (both in package org.
apache.wicket.event) : IEventSource and IEventSink.

FIRST sending an event:

The first interface must be implemented by those entities that want to broadcast en event while the
second interface must be implemented by those entities that want to receive a broadcast event.
The following entities already implement both these two interfaces (i.e. they can be either sender or
receiver): Component, Session, RequestCycle and Application.
IEventSource exposes a single method named send which takes in input three parameters:
  1. sink: an implementation of IEventSink that will be the receiver of the event.
  2. broadcast: a Broadcast enum which defines the broadcast method used to dispatch the event to the sink and to other entities such as sink children, sink containers, session object,application object and the current request cycle. It has four possible values:
    1. BREADTH: The event is sent first to the specified sink and then to all its children components following a breadth-first order.
    2. DEPTH: The event is sent to the specified sink only after it has been dispatched to all its children components following a depth-first order.
    3. BUBBLE: The event is sent first to the specified sink and then to its parent containers.
    4. EXACT: The event is sent only to the specified sink.
  3. payload: a generic object representing the data sent with the event.
Each broadcast mode has its own traversal order for Session, RequestCycle and Application.
The below example shows an event sending. This method can be used from any other component: First you need to create one class to encapsulate the notification and the AjaxRequestTarget and pass them using the events infrastructure.
 
private class Notification {
    private String message;
    private AjaxRequestTarget target;
    ... constructor, getters, setters...
}
 
 send(getSession(), Broadcast.BREADTH, new Notification(message, target));

NEXT Receiving the event : 

Interface IEventSink exposes callback method onEvent(IEvent<?> event) which is triggered
when a sink receives an event. The interface IEvent represents the received event and provides getter
methods to retrieve the event broadcast type, the source of the event and its payload. Typically the
received event is used checking the type of its payload object :
 
@Override
public void onEvent(IEvent event) {
    if (event.getPayload() instanceof Notification) {
        Notification notification = (Notification) event.getPayload();
        ... do whatever you want before updating the panel ...
        // Update the panel 
        notification.getTarget().add(this);
    }
}
 You find in this link a project named InterComponetsEventsExample provides a concrete example of sending an event to a component (named 'container in the middle') using all the available broadcast methods:

dimanche 20 octobre 2013

How to load huge amount of data with Hibernate?


loading huge amount of data like more than one million of row can make a big problem, OutOfMemory Java error for example, so what can we do on such situation? with my little experience i can suggest two solutions, the first is the use of Criteria class and the second one is the ScrollableResults class.

  1. Criteria class : 
    with Creteria we can make pagination solution, this means that we split the result into differents pages to make it  easy to load and process, see the code below  :
    Criteria criteria = session.createCriteria(HistoryRecord.class);
    Criteria criteria = session.createCriteria(HistoryRecord.class).addOrder(Order.asc("CreatedDate") );
    criteria.setMaxResults(10);
    criteria.setFirstResult(20);
    criteria.list();
    

    these code let us take only 10 objects from index 20, even we have one million persisted objects into data base,we can avoid OutofMemory error. these code is not completed because it is static solution that take only object between 20 and 30 index. To be able to progressively load pages, setFirstResult() parametre should be dynamic because it represent the first index of the page, also this code should be called on demand.
  2. ScrollableResults class if you need to read each object separatly from a huge amout of data base objects instead of a complet page, you can use ScrollableResults class that make a iterator allows moving around within the results. See the below code : 
    
    Query query = session.createQuery(HistoryRecord.class);
    ScrollableResults results = query.scroll();
    while (results.next()) {
    HistoryRecord obj = (HistoryRecord) results.get()
    // make some instructions ...
    }
    results.close();