I have downloaded movie in a .mkv file format, and when I try to play it on my Ubuntu, I just can heard the sound but the movie didn't played. After a couple of minutes google it, I found a way to make it clear.
First, add this repo,

sudo apt-add-repository ppa:strukturag/libde265
sudo apt-get update 

Install the corresponding GStreamer plugin directly,
sudo apt-get install gstreamer0.10-libde265 
For GStreamer 1.0 applications,
sudo apt-get install gstreamer1.0-libde265 
There is also a VLC plugin available,
sudo apt-get install vlc-plugin-libde265 
Try it and enjoy your .mkv file. If you have any problem don't hestitate to let me know and help you.
Read More
Hi guys, at this time I will share how to integrate Android SDK and Eclipse IDE in Ubuntu.
First thing first, you must have Oracle Java JDK or OpenJDK (free and open source :D) installed on your system before installing Android SDK. Don't forget to connect your PC or Notebook to Internet to download and install what we need, prepare your coffee and let's start :D
1. Prepare your Development Environment
  • If you don't have installed OpenJDK and JRE on your system yet, you must install it first, you can download the binary from here or you can install it using apt like this:
 sudo apt-get install openjdk-7-jdk && openjdk-7-jre
  • If you are running a 64-bit distribution of Android SDK on your development machine, you need to install the ia32-libs
sudo apt-get install ia32-libs
  • Open terminal and type
javac -version (check java compiler version)
java -version  (check java version)

2. Download and Configure Eclipse Integrated Development Environment (IDE)

  • You can install it using apt-get or you can download it from here. If you are using apt-get, just type into terminal
sudo apt-get install eclipse (this will download and install eclipse)
  • If you have downloaded it from Eclipse site you must select the correct bit version for your corresponding system architecture, if you are on 32-bit Ubuntu then select 32-bit Eclipse IDE and if you are on 64-bit Ubuntu then select 64-bit Eclipse IDE but I won't explain how to use and configure 64-bit Eclipse IDE because I am on 32-bit Ubuntu :). Install it from Ubuntu repository is recommended.
  • I assume you have download and installed it, then we will go to the next step

3. Download, Install and Configure the Android SDK


  • Download Android SDK, select the Linux tarball (android-sdk_r22-linux.tgz) and save it anywhere you want, assume we have it on /home/user/Downloads directory, open up terminal and type:
cd /home/user/Downloads (this will change into Downloads directory)
sudo cp -r android-sdk_r22.tgz /opt (this will copy downloaded android-sdk to /opt directory)
cd /opt (this will change you into the Android working directory)
sudo tar xvzf android-sdk_r22-linux.tgz (this will extract android-sdk_r22-linux.tgz)
sudo -s chmod -R 755 /opt/android-sdk-linux (this will make Android working directory writeable and executable for all users on the systems)

  • Now you have Android SDK located at /opt/android-sdk-linux on your Ubuntu, our next step to add Android SDK to the system wide PATH on Ubuntu, type in terminal
sudo nano /etc/profile or sudo gedit /etc/profile
add the following lines below to the end of the system PATH file
export PATH = ${PATH}:/opt/android-sdk-linux/tools
export PATH = ${PATH}:/opt/android-sdk-linux/platform-tools
save it (if using nano ctrl + o then ctrl + x to close it)
  • Reload your system PATH /etc/profile by type in terminal:
. /etc/profile
4. Install the Android Development Tool (ADT) Plugin for Eclipse IDE
  • Start Eclipse, then select Help => Install New Software. Click Add in the top-right corner. In the Add Repository dialog, enter "ADT Plugin" this just title and you can change it whatever name you want, and URL with the following URL location
https://dl-ssl.google.com/android/eclipse/
  • Then click OK
  • In the Available Software dialog, select Developer Tools and click Next. In the next window you will see a list of the tools to be downloaded then click Next. Accept all license agreements, then click Finish. (If you get a security warning saying that the authenticity or validity of the software can't be established, ignore this and click OK
  • When the installation complete, restart Eclipse. After you've successfully download the ADT, the next step is to modify your ADT preferences in Eclipse to point to the Android SDK directory which we described it before. 
  • Select Window => Preferences... to open the Preferences Panel.
  • Select Android from the left panel. You may see a dialog asking whether you want to send usage statistics to Google. If so, make your choice and click Proceed.
  • Click Browse in the main panel and locate your Android SDK directory which should be /opt/android-sdk-linux.
  • Click Apply, then OK.
5. Add Android platforms and other components to your SDK

  • To create Android Project you must have at least one Android platform and the associated platform tools, you can choose whatever you want from Android SDK Manager. 
  • To launch Android SDK Manager type in terminal:
/opt/android-sdk-linux/tools/android

  • This will open graphical user interface of Android SDK Manager then you can choose Android 2.3.3 and Android 4.2 to be downloaded.
6. Create your Android Virtual Device (AVD)
  • Open terminal and type:
/opt/android-sdk-linux/tools/android avd
  • This will open AVD Manager then create your Android Virtual Device


Congratulations, you should now have the Android SDK setup to work with Eclipse IDE and you can begin developing Android Applications.

Happy Coding :)
Read More
If you are newbie in Linux, you will confuse when you want to install Linux application and it's format file is .tar.gz or .tar.bz2 (tarball). But now you don't need to worry because this post will give you the answer :).

Standard format to extract this tarball file is:

tar xvf filename.tar


If the tarball has also been gzipped (compressed), you can use the following command:

tar xvfz filename.tar.gz

If you only want certain directories from the tarball, do this:

tar xvzf filename.tar.gz */dir.you.want/*

If you have a .tar.bz2 file, then you need bzip2 installed (/usr/ports/archivers/bzip2), and you issue this command:

tar yxf filename.tar.bz2
Read More
If you are using Netbeans IDE under Ubuntu 13.04, you will dissapointed with it's look and fell. The fonts are big and it looks weird, especially for me :). But don't worry, you will get your Netbeans looks more eye catchy :).

Let's start, open your terminal, then type in:

nano /home/user/netbeans-7.3/etc/netbeans.conf

Then add the following line into netbeans option:

-J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=lcd --laf Metal

Or you can change --laf Metal to --laf GTK

Enjoy your new look of Netbeans IDE and HAPPY CODING :)
Read More
Sometime as a PHP Developer, I usually get task to create report in excel. Of course I use PHPExcel to generate excel document. To use PHPExcel library, I must do this step below:

   1. Include PHPExcel library
   2. Create Object of PHPExcel
   3. Set Active Sheet
   4. Set style of column and row
   5. Set value by column and row
   6. Set filename and save

If we just need 1 column and 1 row with a less data we can do it fast and simple. For example we need to create 1 excel file with 5 rows data, result from mysql query, there are:
No    Name        City
1    Dono        Yogyakarta
2    Rina        Wonosobo
3    Danu        Purworejo
4    Riki        Jakarta
5    Agnes        Bogor


First, we need to set each column style (A, B and C column because we just need No, Name, and City for header):
$this->sheet->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); (to set center alignment);
$this->sheet->getColumnDimension('A1')->setWidth(5); (to set column size);
$this->sheet->setCellValueByColumnAndRow('A', 1, 'No');
Do the same thing to B and C column. Of course we can set others style that has described in PHPExcel Documentation.

If we done with the header section, then we need to set style and value of each data, we can use for loop:
$lastRow = 2;
foreach ($resultData AS $key => $value) {
    $no = $key+1;
    $this->sheet->setCellValueByColumnAndRow('A', $lastRow, $no);
    $this->sheet->setCellValueByColumnAndRow('B', $lastRow, $value['name']);
    $this->sheet->setCellValueByColumnAndRow('C', $lastRow, $value['city']);
    $lastRow++;
}
We also set its style, if needed. After set the style and value, we need to set filename and then download it:
$this->obj_PHPExcel->SetFileName('Data'.$datetime . '.xls');
$this->obj_PHPExcel->Save();
exit;

All clear, but if we have too many data to export, we need more time to set style and value of each column and row with above way. And I have create functions to make it more easy, these functions describes below:
    /**
     * Use to set title of excel sheet (title location is above header)
     * @author Kartika Yudha Pratama <kartikayudhapratama@gmail.com>
     * @param int $row : row index
     * @param array $arrTitle : title (title1, title2, ...)
     * @param int $column : column name -> using getColumnString($number)
     */
    function title($row, $arrTitle, $column) {
        if (!empty($arrTitle)) {
            for ($i = 0; $i < count($arrTitle); $i++) {


                $this->sheet->mergeCells('A' . $row . ':' . $column . $row)->setCellValue('A' . $row, $arrTitle[$i]);
                //echo "<pre>"; echo print_r($arrTitle[$i]);exit();
                $this->sheet->getStyle('A' . $row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $this->sheet->getStyle('A' . $row)->applyFromArray($this->fontBold);

                $row++;
            }
            $this->index = $row;
        }
    }

    /**
     * This function used to create footer of excel sheet
     * @author Kartika Yudha Pratama <kartikayudhapratama@gmail.com>
     * @param int $row : row index
     * @param array $arrTitle : title (title1, title2, ...)
     * @param int $column : column name -> using getColumnString($number)
     */
    function footer($last, $arrTitle, $column) {
        if (!empty($arrTitle)) {
            for ($i = 0; $i < count($arrTitle); $i++) {
                $this->sheet->mergeCells('D' . $last . ':' . $column . $last)->setCellValue('D' . $last, $arrTitle[$i]);
                $this->sheet->getStyle('D' . $last)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                $this->sheet->getStyle('D' . $last)->applyFromArray($this->fontBold);
                $row++;
            }
            $this->index = $row;
        }
    }

    /**
     * This function used to create header table
     * @author Kartika Yudha Pratama <kartikayudhapratama@gmail.com>
     * @param array $cols
     * @param int $last_col : column index
     * @param int $last_row : row index
     */
    private function setHeader($cols, $last_col, $last_row) {
        foreach ($cols as $col) {
            $this->sheet->setCellValueByColumnAndRow($last_col, $last_row, $col['header']);
            if ($col['size'])
                $this->sheet->getColumnDimension(getColumnString($last_col))->setWidth($col['size']);
            else
                $this->sheet->getColumnDimension(getColumnString($last_col))->setWidth()->setAutoSize(true);
            $this->sheet->getStyleByColumnAndRow($last_col, $last_row)->getAlignment()->setWrapText(true)->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $this->sheet->getStyle('A' . $last_row . ':' . (getColumnString(count($cols) - 1)) . $last_row)->applyFromArray($this->border);
            $this->sheet->getStyle('A' . $last_row . ':' . (getColumnString(count($cols) - 1)) . $last_row)->applyFromArray($this->fontBold);
            $last_col++;
        }
        $this->index = $last_row;
    }

    /**
     * This function used to initialize $cols variable ($cols used to write data into column)
     * @author Kartika Yudha Pratama <kartikayudhapratama@gmail.com>
     * @param string $arrData : field
     * @param array $arrAlign : column align
     * @param array $arrSize : column width
     * @param array $arrHeader : header table
     * @return array
     */
    private function setCols($arrData, $arrAlign, $arrSize, $arrHeader) {
        $cols = array();
        if (!empty($arrData)) {
            for ($i = 0; $i < count($arrData); $i++) {
                $cols[$i] = array(
                    'header' => $arrHeader[$i],
                    'data' => $arrData[$i],
                    'size' => $arrSize[$i],
                    'align' => $arrAlign[$i]
                );
            }
        } else if (!empty($arrHeader)) {
            for ($i = 0; $i < count($arrHeader); $i++) {
                $cols[$i] = array(
                    'header' => $arrHeader[$i],
                    'align' => 'center',
                    'size' => $arrSize[$i]
                );
            }
        }
        return $cols;
    }

    # make excel function
    /**
     * This function used to write data into excel table
     * @author Kartika Yudha Pratama <kartikayudhapratama@gmail.com>
     * @param array $data : The data from query that use to write to excel table
     * @param array $cols : array that define header, data, align and size
     * @param boolean $total : if report need total row at the bottom of table
     */
    private function makeExcel($data, $cols, $total , $firstRow) {
        $last_row = 1 ;
        $first_row = $last_row;
        $last_col = 0;
        $columnName = getColumnString(count($cols) - 1);
        $title = array($this->title1, $this->label_jalur_global);
        $this->title($last_row , $title, $columnName);
        $last_row = $this->index + 1 + $firstRow;
        $this->setHeader($cols, $last_col, $last_row);

        if (!empty($data)) {
            // foreach($mergeHorizontal as $key => $merge){
            //     $this->sheet->mergeCells(getColumnString($merge[$key]['first_column']) . $merge[$key]['first_row'] . ':' . $merge[$key]['last_column'] . $merge[$key]['last_row']);
            // }
            $no = 1;
            foreach ($data as $rows) {
                $last_row++;
                $first_row = $last_row;
                $rows['no'] = $no;
                $last_col = 0;
                $this->writeDataCol($last_col, $last_row, $rows, $cols);
                $no++;
                $this->sheet->getStyle('A' . $first_row . ':' . (getColumnString(count($cols) - 1)) . ($last_row))->applyFromArray($this->border);
            }
            $last_row++;
            if ($total) {
                $this->total((count($cols) - 1), $last_row, $last_row, $cols, $data);
            }
        } else {
            $last_row = $this->index + 1;
            $this->sheet->mergeCells('A' . $last_row . ':' . $columnName . $last_row)->setCellValue('A' . $last_row, '-- TIDAK ADA DATA --');
            $this->sheet->getStyle('A' . $last_row)->getAlignment()->setWrapText(true)->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $this->sheet->getStyle('A' . $last_row)->applyFromArray($this->fontBold);
            $this->sheet->getStyle('A' . $last_row . ':' . $columnName . $last_row)->applyFromArray($this->border);
        }
    }

    /**
     * This function used to write data to table column
     * @author Kartika Yudha Pratama <kartikayudhapratama@gmail.com>
     * @param int $last_col : column index
     * @param int $row : row index
     * @param array $rows : data
     * @param array $cols
     */
    function writeDataCol($last_col, $row, $rows, $cols, $idLap = '') {
        foreach ($cols as $col) {
            $string = $rows[$col['data']];
            if ($string[0] == '0') {
        # if first carachter of string is 0, than set format cell to String
                $this->sheet->setCellValueExplicit(getColumnString($last_col) . $row, $string, PHPExcel_Cell_DataType::TYPE_STRING);
            } else {
                $this->sheet->setCellValueByColumnAndRow($last_col, $row, $string);
            }
            if (isset($col['align'])) {
        # set column alignment of cells
                switch ($col['align']) {
                    case 'center':
                        $align = PHPExcel_Style_Alignment::HORIZONTAL_CENTER;
                        break;
                    case 'left':
                        $align = PHPExcel_Style_Alignment::HORIZONTAL_LEFT;
                        break;
                    case 'right':
                        $align = PHPExcel_Style_Alignment::HORIZONTAL_RIGHT;
                        break;
                    case 'justify':
                        $align = PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY;
                        break;
                }
                $this->sheet->getStyle(getColumnString($last_col) . $row)->getAlignment()->setHorizontal($align);
            }
            if (isset($col['size'])) {
        # set column size
                $this->sheet->getColumnDimension(getColumnString($last_col))->setWidth($col['size']);
            } else {
        # set to auto size
                $this->sheet->getColumnDimension(getColumnString($last_col))->setWidth()->setAutoSize(true);
            }
            if (isset($col['wrap']) AND $col['wrap'] === true) {
        # set to wrap text
                $this->sheet->getStyleByColumnAndRow($last_col, $row)->getAlignment()->setWrapText(true);
            }
            $last_col++;
            $this->last_col = $last_col;
        }
    }

    /**
     * This function set TOTAL row, if needed. This row will be add at the end of table data row
     * @param int $start : The first index column that will be merged
     * @param int $first_row : The first index row after header table
     * @param int $last_row : The last index row
     * @param array $cols
     * @param array $data
     */
    private function total($start, $first_row, $last_row, $cols, $data) {
        # The first data that will be sum
        $data_pertama = $last_row - (count($data));
        # The last column
        $last_col_name = (getColumnString(count($cols) - 1));
        if ($start > 0) {
            $this->sheet->mergeCells('A' . $last_row . ':' . getColumnString($start - 1) . $last_row);
        }
        $this->sheet->setCellValue('A' . $last_row, 'TOTAL');
        for ($i = $start; $i < count($cols); $i++) {

            $this->sheet->setCellValue(getColumnString($i) . $last_row, '=SUM(' . getColumnString($i) . $data_pertama . ':' . getColumnString($i) . ($last_row - 1) . ')');
        }
        $this->sheet->getStyle('A' . $first_row . ':' . $last_col_name . ($last_row))->applyFromArray($this->border);
        $this->sheet->getStyle('A' . $last_row . ':' . $last_col_name . ($last_row))->applyFromArray($this->fontBold);
        $this->sheet->getStyle('A' . $last_row . ':' . $last_col_name . ($last_row))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    }

    /**
     * This function used to export to excel file (2003 -> .xls)
     * @author Kartika Yudha Pratama <kartikayudhapratama@gmail.com>
     * @param String $name : nama untuk file excel nya
     */
    private function printExcel($name) {
        $this->obj_PHPExcel->SetFileName($name . '.xls');
        $this->obj_PHPExcel->Save();
        exit;
    }

And here is example how to do with the functions:
The data result should be like this (multidimensional array) :
Array {
    [0] =>
        [name] => Dino
        [address] => Papringan
        [city] => Yogyakarta
        [gender] => Male
        [phone] => 085227052001
    [1] =>
        [name] => Rina
        [address] => Grogol
        [city] => Jakarta
        [gender] => Female
        [phone] => 088774567123
}
    private function report() {
        $arrHeader = array('No', 'Name', 'Address', 'City', 'Gender', 'Phone Number');
        $arrData = array('no', 'name', 'address', 'city', 'gender', 'phone');
        $arrSize = array(5, 35, 35, 30, 10, 15);
        $arrAlign = array('center', 'left', 'left', 'left', 'left', 'center');
        $cols = $this->setCols($arrData, $arrAlign, $arrSize, $arrHeader);
        $data = $this->obj_recap->getRecapData();
        $this->makeExcel($data, $cols, false);
        $this->printExcel('Recap Data' . '_' . $this->date);
    }

If we must create many reports in a single php file, this function is usefull for me, just copy functions above in a single php file, then include it in php file that use to create excel file. But this code still can improved, but I don't have much time to improve it anymore :D, if you have your own idea to share please don't hesitate to write comment below.

Sharing is carring :D
Read More
Bash scripting is one of the easiest types of scripting to learn. It run under Linux and its very usefull. Bash is the language that you will learn to love as much of everyday Ubuntu life is done/can be done using terminal. You can make your own custom bash script through both GUI (Graphical User Interface) and CLI (Command Line Interface), but I prefer using CLI than GUI because using CLI you can changing file permissions of a folder and all its sub folders is more easily.

To make your own custom bash script, define where you wanna put the custom bash script directory (I use /home/user/bash_custom).
Then run terminal by type ctrl + T and type, 
sudo nano /etc/profile
Add path of the custom bash script at the end of line, in order to execute the script from everywhere at the console,
export PATH=${PATH}:/home/user/bash_custom
Reload your system PATH in /etc/profile by type in terminal,
. /etc/profile
Create .sh file in bash_custom directory,
nano /home/user/bash_custom/youdl.sh
This script used to download youtube video with custom parameter and now integrate with axel downloader, of course I will share the script to you (make sure that you have youtube-dl installed before), copy and paste the following code to .sh file that have been created,

#!/bin/sh
CONNECTIONS=4 # Specify how many connections axel should use
# Get URL and Title of video using youtube-dl
url=`youtube-dl --get-url --max-quality avi  $1`
echo "Got URL"
title=`youtube-dl --get-title $1`
echo "Got Title :"$title
# Download using axel
axel --alternate --num-connections=$CONNECTIONS --output="$title.mp4" "$url"
Save it by type ctrl + O then type ctrl + X to exit.
Once finished, you can type in terminal
youdl.sh youtube_link_video title
Replace youtube_link_video with youtube video you want to download, and replace title with your custom title.

That's how this custom bash script work, just create other custom bash script, and do above steps.
Read More
Begin from a task given by my boss to create a standalone application using PHP running on windows operating system. Got confused thinking about how to bundling web server + PHP + MySQL into an .exe file (Windows Executable File). Finally, I can do this, helped by my coworker and I will share to you all.

First thing first, you need to collect the tools:
  1. PHP Application that you want to bundle
  2. Portable Web Server, I use xampplite 1.7.3 as my web server because my PHP Application using PHP 5.3. There are other portable web server that you can use, server2go but I will tell it how to do with it later.
  3. Winrar.
If you have collected all, then do the following step:
  1. Backup your database application.
  2. Extract xampplite 1.7.3 to C:\. Why I choose C root directory, because this is normally installation folder location for windows operating system and this folder absolutely exist.
  3. Copy your PHP Application to htdocs in xampplite 1.7.3 extracted folder.
  4. Make sure that no one web server / mysql server running, then you can run apache and mysql by double clicking apache_start.bat and mysql_start.bat or you can run xampplite control panel to start apache and mysql. 
  5. Access your phpmyadmin by type localhost/phpmyadmin using your favourite browser.
  6. Create new database and then restore your backed up database via phpmyadmin. 
          If you got this following error, when try to access phpmyadmin,
    error #1273 unknown collation utf8mb4_general_ci 
    Open database_interface.lib.php located in C:\xampplite\phpMyAdmin\libraries, then comment at this line:
    error #1273 unknown collation utf8mb4_general_ci

    Then run your phpmyadmin again. If you have restored the database, setting your application then try to running your application via browser by type: localhost/myapplication. If everything's gonna be okay, then we can start to the next step.
    Before bundle this application, we need to create batch file that will be executed after installation process was done. Create new file, filename.bat then open it with your favourite text editor, and add this codes,
call apache_start.bat 
call mysql_start.bat
if exist {"C:\Program Files\Mozilla Firefox\firefox.exe"} {
    "C:\Program Files\Mozilla Firefox\firefox.exe" localhost/myapplication
}
    Above code is used to run apache_start.bat, mysql_start.bat and run your web application using firefox (x86-windows 32 bit).

    Now we have to create an .exe file to run your web application. You just need Winrar to do that. Select all folder under xampplite, right click then choose add to archive,
     Fill archive name with application name, check create SFX archive and create soli, then move to Advanced tab, shown below,
    I suggest to fill this path to extract, same as the extracted xampplite folder (C:\xampplite\), and don't change it, because if you change it, you could change many files under xampplite folder with your custom folder. Run after extraction is used to execute batch file (that has created before) after extraction was completed. You can try to custom in this advanced SFX options, like installer title, installer icon, license and many more. If you have done to custom your installer, then just click OK and wait the process, and when it done, just try to install it to other computer (make sure there is not web server running).

    Conclusion
    This method usefull enough to create web application into an .exe file. This is actually not create an application (like desktop application) but just compress portable web server that include your application and databases and then it could be portable.


    If you have a question don't hestitate to comment below.
Read More
If you are using tinyMCE on your website, and you found NS_ERROR_UNEXPECTED (if you are using firebug, it shown at console) when you try to submit a form that contain tinyMCE or you can submit a form but the content of tinyMCE won't be posted, don't worry I will share how to solve this error.

This error happen because tinyMCE input box is not textarea but a div and it will not post when you submit a form where textarea placed. What you need to do are add theses following code on submit event,
tinyMCE.triggerSave();
So the complete code be like this,
$("#btnSave").click(function() {
      tinyMCE.triggerSave();
     $("#frmPost").submit();
     return false;
})

That command is used to load tinyMCE input to a hidden textarea and of course this will be posted when you submit a form that contain tinyMCE.


Read More