Tuesday, 29 July 2014

Solution : Can't quit Packagekit - adding software package in OpenSuse 4

Problem

We can't run 2 updaters at the same time so if packagekit is running then you can't run Yast update or zypper.

So, it will through confirm message to stop packageKit process.
PackageKit is blocking software management.
This happens when the updater applet or another software management
application is running.
Ask PackageKit to quit?

if you click on 'Yes', it will try to stop the process of packageKit. If it is still busy, it will again arise the popup with this message.
 PackageKit is still running (probably busy).
Ask PackageKit to quit again?

Again click 'yes'. If it won't stop the process, follow the below method to kill the processes.

Solution
 
Kill the process using following commands.
sudo killall -KILL packagekitd
Make sure you are in super user mode. Just run this command in Command line Interface (CLI).

It will kill all currently running packageKit processes.

Have any doubt? Feel free to comment here....


Monday, 28 July 2014

Resize jqGrid based on number of rows 0

To resize grid based on number of rows, Just we need to say this in configuration settings of jqGrid.

Yes. we need to set like this below.

$("#mygrid").jqGrid({
    ...,
    ...,
    ...,
    height:'auto',
    ...,
    ...
});
 
simply set height property to auto.

How it actually works?

This height configuration for the body of the grid. Our grid table is actually placed within the body of the grid. We can get that body of the grid by this selector ".ui-jqgrid-bdiv".

So, If we not set height property in jqGrid configuration, It will take the default height to 150px. If we send one record to jqGrid, it will show like this below,


If we set height property to auto in jqGrid configuration settings, and we are sending only one record to grid. It will showing the grid like below,


So, If we sending more than 20 records, and we set our grid limit to 20 per page. So, Grid showing correctly showing 20 records in first page. See the below image.


Have any doubt? Feel free to comment here!!!


Sunday, 27 July 2014

Convert CSV to Two dimensional array (2D Array) - PHP 2

When you get the data from CSV file, It will return return array of each row. To work with this, we need to convert it as 2D array. So, this following code snippet will help you to covert CSV array to 2D array. In this we used PHP's array_combine function.

FUNCTION DEFENITION
function get2DArrayFromCsv($file, $delimiter) {
    if (($handle = fopen($file, "r+")) !== FALSE) {
        $i = 0;
        $data2DArray = array();
        while (($lineArray = fgetcsv($handle, 0, $delimiter)) !== FALSE) {
            for ($j = 0; $j < count($lineArray); $j++) {
                $data2DArray[$i][$j] = $lineArray[$j];
            }
            $i++;
        }
        fclose($handle);
    }
    return $data2DArray;
}

HOW IT WORKS

* Just used incremental variable $i to mention number of row in 2D array.
* Once finished the iteration for a row, then increment $i for the next row.
* See how array_combine works.

PARAMETERS 

$file - File path
$delimiter - delimiter used in this CSV

FUNCTION USAGE
get2DArrayFromCsv($file_path, ',');
Recommended Article : Convert CSV to JSON with header row as key - PHP

Have any doubt? Feel free to comment here!!!


Monday, 21 July 2014

Add border-bottom / border-top to table row using CSS 0


We can do it with table's border-collapse property.
Collapse

In which both the space and the borders between table cells collapse. So, there is only one border and no space between cells.

Just change the table border-collapse style into collapse using this following css
table {
    border-collapse: collapse;
}
Now the each cells are independent. So, you can apply border-bottom or border-top style for each td like bellow CSS.

To Set border-bottom,
.border_bottom {
    border-bottom: 1px solid #000;
}
To Set border-top,
.border_top {
    border-top: 1px solid #000;
}
LIVE DEMO
Have any doubt? Feel free to comment here!!!

Saturday, 19 July 2014

24 jQuery UI themes 0

Here we listed 24 jQuery UI themes... Click on the names to get raw code of themes.
 Click...! Download...!! Enjoy... !!!


Thursday, 17 July 2014

Uncaught TypeError: Cannot read property 'integer' of undefined - jqGrid 0

This sounds "Language supporting file is missing".

* One get the error message typically if one don't included required language file grid.locale-xx.js (for example grid.locale-en.js).

* You can Include it before jquery.jqGrid.min.js or jquery.jqGrid.src.js. See the example of the usage of jqGrid in Documentation

* If you don't have that file, Click Here to download.

Have any doubt? Feel free to comment here!!!

Related post : jqGrid "reloadGrid" using Local Data (JSON Object)



Wednesday, 16 July 2014

Convert CSV to JSON with header row as key - PHP 1

When you get the data from CSV file, It will return return array of each row. If we want this array in JSON as header row as key and cell value as value, We can use PHP's array_combine function.

So, We can use this following function to achieve this task.

FUNCTION DEFENITION
function getJsonFromCsv($file,$delimiter) { 
    if (($handle = fopen($file, 'r')) === false) {
        die('Error opening file');
    }

    $headers = fgetcsv($handle, 4000, $delimiter);
    $csv2json = array();

    while ($row = fgetcsv($handle, 4000, $delimiter)) {
      $csv2json[] = array_combine($headers, $row);
    }

    fclose($handle);
    return json_encode($csv2json); 
}
HOW IT WORKS

* Just read the first line separately and merge it into every row.
* The above function opens a file handle, reads the first line into $headers
* Then reads the remaining lines.
* It combines each line with the $headers.
* See how array_combine works.

PARAMETERS 

$file - File path
$delimiter - delimiter used in this CSV

FUNCTION USAGE
getJsonFromCsv($file_path, ',');
Recommended Article : Convert CSV to Two dimensional array (2D Array) - PHP

Have any doubt? Feel free to comment here!!!


Saturday, 12 July 2014

Strict Standards: Non-static method DOMDocument::load() should not be called statically - PHP 0

In PHP recently I faced this issue. When I tried to use my xml file using php's document load() function.

Problem
$dom = DOMDocument::load('myXml.xml');
It works perfectly. But I throws error
Strict Standards: Non-static method DOMDocument::load() should not be called statically
Solution
The reason why it's happening is because I called a load() method in the DOMDocument class in which is not static.

 Instead of calling it with :: We need to call it with ->

I found PHP document about the usage of DOMDocument load() method.
$doc = new DOMDocument();
$doc->load('myXml.xml');
Now the error is gone...!!!

Have any doubt feel free to comment here!


Thursday, 3 July 2014

Get all the dates between two dates - Javascript 7

We can do this using Javascript's Date() object. You can use this following function to get between two dates. It will return array. Here we are using isDate() and isValidRange() functions to make sure is the given string is Date and end date is not greater then start date. If the given string is not date, then it will return "error occured!!!... Please Enter Valid Dates" in browser console and it will return empty array.

Parameters:

Start - Starting Date
end - Ending Date
Note: you should pass Date object as parameters.
If you are using jQuery Date picker, you can get selected date object like below,
var start = $("#from").datepicker("getDate"),
    end = $("#to").datepicker("getDate");
you can get selected date object using 'getDate' parameter in datepicker.

usage and Example :

If you are using datepicker, you can use this code,
var start = $("#from").datepicker("getDate"),
    end = $("#to").datepicker("getDate");

var between = getDates(start, end);

If you are going to use your own date string, you should make it as date object. Then only you can use in it. You can use this piece of code,
var start = new Date('2014-07-13'),
    end = new Date('2014-07-17');

var between = getDates(start, end);

Live Demo

Have any doubt, feel free to comment here!