Sunday, 29 July 2012

CSS Link tag not working?

Today while doing some changes in html file and included an external css file using link tag, I came to know that external css is working fine with chrome and safari but not in IE 9.0 and Mozilla browser. I just got confused why it’s working in one browser and not in another. 

Searched over internet for some time and came to know that we shouldn’t give secure urls in link tag. In this case it would work abnormally or you can say it may work or not. I tried and found the solution but didn’t find the actual reason for this type of behave from well known browsers(IE and Mozilla). If anybody find that please let me know.

/*Code not working with https */

/*Code working with http */

Thanks!!!!!!!!! Enjoy Programming :)

Sunday, 15 July 2012

Use rsync command over ssh to to take backup of files.

Today we are going to discuss over "how to use rsync command over ssh to take backup of files". Before that let's know little bit about rsync itself.

rsync : 

rsync is a little Linux utility that synchronizes filesystems from one place to another by only copying diffs (deltas) of files that have changed. rsync optionally compresses the files ont-the-fly before transfer (to save transfer time) and may be used in conjunction with rsh or ssh to perform remote file transfers. rsync may be used as a backup or mirroring utility.

The advantage of using rsync over other archive and copy utilities such as tar, dump and rcp are:

(1) rsync can use ssh as a secure channel to transfer files over the network.

(2) It provides an ability to retain ownership and permission of files being transferred.

(3) It enables files and directories to be synchronized (deleted files are deleted from the last replication), and 

(4) transfers only "delta" files that are changed from last replication making transfer much faster. 

If rysnc is used without the ssh, it uses the TCP port 873. 

To more about rsync command you can follow these links

You can run rsync command as follow :

Example :

rsync -iavz --log-file=/usr/dirtyhandsphp/backups/`date +%d%b%Y`_rsync.log -e ssh /var/www/manual /usr/dirtyhandsphp/backups/backup_`date +%d%b%Y`

--log-file  :  saves a copy of the rsync result to a logs_date-stamped file.
-a  : archive mode
-v  : verbose mode
-z  : Compress files before transfer

It would copy manual folder and it's files from /var/www/ to /usr/dirtyhandsphp/backups/backup_`date +%d%b%Y`. Files would get copied in compressed mode and a logfile with nominature `date +%d%b%Y`_rsync.log would be created in /usr/dirtyhandsphp/backups/ directory.

Note : If you are running this command from backend and not going with logs file option then there is no need of using verbose (-v) mode.

How to check if rsync ran successfully or not :  

rsync command returns an exit code after execution. You can check exit codes list here : 

If it returns no code it means it ran successfully without any problem so code is 0. Otherwise it would return a particular code. If you are writing a shell script which would be exected automatically at a particular time from back-end and want to put some logic on success or failure of the command. You can do as following :


rsync -iavz --log-file=/usr/dirtyhandsphp/backups/`date +%d%b%Y`_rsync.log -e ssh /var/www/manual /usr/dirtyhandsphp/backups/backup_`date +%d%b%Y`

 if [ "$?" = "0" ] ; then
        #echo "Backup Completed
        #echo "Backup Failed"

Thanks!!!!!!!!! Enjoy Programming :)

Sunday, 8 July 2012

How to draw Dynamic Line or Timeseries Chart in Java using jfreechart library?

Today we are going to write a code to draw a dynamic timeseries-cum-line chart in java.  The only difference between simple and dynamic chart is that a dynamic event is used to create a new series and update the graph. In out example we are using timer which automatically calls a funtion after every 1/4 th second and graph is updated with random data. Let's try with the code :

Note : I had tried my best to provide complete documentation along with code. If at any time anyone have any doubt or question please post in comments section.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;
import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

 * An example to show how we can create a dynamic chart.
public class DynamicLineAndTimeSeriesChart extends ApplicationFrame implements ActionListener {

    /** The time series data. */
    private TimeSeries series;

    /** The most recent value added. */
    private double lastValue = 100.0;
    /** Timer to refresh graph after every 1/4th of a second */
    private Timer timer = new Timer(250, this);
     * Constructs a new dynamic chart application.
     * @param title  the frame title.
    public DynamicLineAndTimeSeriesChart(final String title) {

        this.series = new TimeSeries("Random Data", Millisecond.class);
        final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
        final JFreeChart chart = createChart(dataset);
        //Sets background color of chart
        //Created JPanel to show graph on screen
        final JPanel content = new JPanel(new BorderLayout());
        //Created Chartpanel for chart area
        final ChartPanel chartPanel = new ChartPanel(chart);
        //Added chartpanel to main panel
        //Sets the size of whole window (JPanel)
        chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
        //Puts the whole content on a Frame


     * Creates a sample chart.
     * @param dataset  the dataset.
     * @return A sample chart.
    private JFreeChart createChart(final XYDataset dataset) {
        final JFreeChart result = ChartFactory.createTimeSeriesChart(
            "Dynamic Line And TimeSeries Chart",
        final XYPlot plot = result.getXYPlot();
        plot.setBackgroundPaint(new Color(0xffffe0));
        ValueAxis xaxis = plot.getDomainAxis();
        //Domain axis would show data of 60 seconds for a time
        xaxis.setFixedAutoRange(60000.0);  // 60 seconds
        ValueAxis yaxis = plot.getRangeAxis();
        yaxis.setRange(0.0, 300.0);
        return result;
     * Generates an random entry for a particular call made by time for every 1/4th of a second.
     * @param e  the action event.
    public void actionPerformed(final ActionEvent e) {
        final double factor = 0.9 + 0.2*Math.random();
        this.lastValue = this.lastValue * factor;
        final Millisecond now = new Millisecond();
        this.series.add(new Millisecond(), this.lastValue);
        System.out.println("Current Time in Milliseconds = " + now.toString()+", Current Value : "+this.lastValue);

     * Starting point for the dynamic graph application.
     * @param args  ignored.
    public static void main(final String[] args) {

        final DynamicLineAndTimeSeriesChart demo = new DynamicLineAndTimeSeriesChart("Dynamic Line And TimeSeries Chart");




Thanks!!!!!!!!!!! Enjoy Programming :)


Odoo 10: Close wizard and open standard form

Hi, Today we are going to learn how to open standard form after saving data in wizard. Let's say I have created an wizard to fill bas...