Monthly Archives: September 2014

Using linkbucks API / posting data using cURL in PHP



  • Register to linkbucks if you don’t have any account there (it’s free and you probably should use email other than gmail and hotmail if you want quick confirmation from linkbucks)
  • Find your username and API password from your profile page: . If your API password is empty, just click “Reset API Password” link to show it.

This is our little PHP function that help us to POST data to certain URL:

//function to POST data using cURL in PHP
function curl_post($url, $data, $ip="", $ref="", $ua="") {
    //initiate cURL
    //set referer only if stated by user
    if ($ref!="") {
        curl_setopt($ch, CURLOPT_REFERER, $ref);
    //set IP interface if needed (for multi-IP server)
    if ($ip!="") {
        curl_setopt($ch, CURLOPT_INTERFACE, $ip);
    //set user agent if stated by user
    if ($ua!="") {
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    return $response;

How to use it to call linkbucks API:

    'user'=>'chmdznr',  //my username
    'apiPassword'=>'d55ae4eaf97b445f',  //my API password
    "originalLink"=>"",  //the URL that need to be shorted
    "adType"=>2,  //paid links
    "contentType"=>1,   //not an adult content
    "domain"=>""  //target domain, a lot of possibility here, the default is: 

//call linkbucks API

$returned_data=curl_post($url, json_encode($data_kirim));

//simple error checking
if (!empty($parsed_data->link)) {
    echo "This is your short URL : ".$parsed_data->link;
} else {
    echo "Something wrong! ".$parsed_data->errorDescription;

The curl_post function is quite generic, you can use it to send data to remote URL using POST method like this:


$returned_data=curl_post($target_url, http_build_query($login_data));

You should notice that the data array need to be converted using http_build_query first (in linkbucks’ case, it doesn’t need to be converted first).
You can also add more advanced feature in the function such as handling the timeout and cookie.

Quite fast library for computing power of matrix using php

Still about Matrix, since lately I handle a lot of web-based projects that involving Matrix computations, maybe someday you’ll need this.
I’m in need of this kind of library when creating web-based ANP (Analytic Network Process) problem solver where you have to power the weighted supermatrix with some high integer number to gain the limit supermatrix.

Here’s the codes inside the library, you can save it to whatever php file:

(I’m sorry I don’t post the full source code on this post, WordPress always messed up the code because it contains ‘<‘ and ‘>’)

How to use it?
As simple as this:

// the matrix to be computed have to be a square matrix and is a PHP array()
$m_power=mat_pow($the_matrix, 512); // here we calculate the power of matrix $the_matrix to 512

Comparison to MATLAB
We’ll compare MATLAB result and our library result for the correctness and calculation speed.
The matrix will be taken from a CSV file and will be 15×15 in size. We will power this matrix to 512.
This is the MALTAB code used:

time_needed=tElapsed*1000 % time needed in miliseconds

This is the partial screenshot of the MATLAB’s code result

power of matrix using MATLAB

power of matrix using MATLAB result

And finally our PHP code:
You can see it here:
I won’t take the result screenshot as you can try it on

If you run the MATLAB code and the PHP code, you’ll see that our PHP code yield the same result as the MATLAB code but it run much faster than the MATLAB (both already timed in miliseconds)! I absolutely don’t know why powering matrix using PHP is faster than using MATLAB but I’m happy with the result. 😀

[Example] Solving math linear equations with 4 unknown variables

We’ll put some use of Matrix library for CodeIgniter that we already implemented to solve a linear equation.
Let’s say we have linear equations with 4 unknown variables like this:
$latex \begin{array}{rcl}
2a+3b+c+6d &=& 4 \\
4a-2b+0.5c+d &=&2 \\
6a+b-d&=&-1 \\
2a+2b-c+3d&=&4 \end{array}$

That linear equation can be written in Matrix notation like this:
$latex \left[ \begin{matrix} 2&3&1&6\\ 4&-2&0.5&1 \\ 6&1&0&-1\\ 2&2&-1&3 \end{matrix} \right] \left[ \begin{matrix} a\\b\\c\\d \end{matrix} \right] = \left[ \begin{matrix} 4\\2\\-1\\4 \end{matrix} \right] $

And can be solved by this matrix equation:
$latex \left[ \begin{matrix} a\\b\\c\\d \end{matrix} \right] = \left[ \begin{matrix} 2&3&1&6\\ 4&-2&0.5&1 \\ 6&1&0&-1\\ 2&2&-1&3 \end{matrix} \right]^{-1} \left[ \begin{matrix} 4\\2\\-1\\4 \end{matrix} \right] $

And this is how we solve it on php/CodeIgniter:

// load the phpmath library

//building the 'left' matrix
    array(4, -2, 0.5, 1),
// left matrix class
$mLeft=new Matrix($left);

//building the 'right' matrix
// right matrix class
$mRight=new Matrix($right);

// calculate inverse of left matrix

// find the equation solution by multiplying the inverse of left matrix and the right matrix

// $solution is the value of a,b,c and d variables. Let's dump it as an array!

Quite simple isn’t it?!

PS.: I’m glad I can use my Latex knowledge in this post 😛

Matrix operation library for CodeIgniter

This tips is useful if you someday handling web-based project that involving Matrix handling and you want to implement it using CodeIgniter. We’ll use PHPMath library for this.

  • Download the latest version of phpmath library from here:
  • Open the archive (build02.tar.gz) and see the content, you’ll see “build02” folder, go inside, you’ll see more folders there:
phpmath archive content

phpmath archive content

  • Because we only need the matrix handling and operation library, we just need the “JAMA” folder inside.
  • Extract this “JAMA” folder into your CodeIgniter’s application/third_party/ library, rename it to more meaningful folder, I prefer “phpmath”. Your third_party library will be look like this:
phpmath inside third_party folder

phpmath inside third_party folder

  • Go inside “phpmath” folder, you’ll see more folders there. We don’t need “docs”, “examples” and “tests” folder, we can delete them, your phpmath folder will be like this:
phpmath after deleting unnecessary folders

phpmath after deleting unnecessary folders

And you are done! (In this tips: not like mPDF and PHPExcel library, we don’t need to create a new file/class in the application/libraries folder)

How to use it?

Quite simple, check and test these code samples inside your controller:

// load the phpmath library

// define new matrix
     array(9, 10),
     array(11, 12)
     array(13, 14),
     array(15, 16)
// build the Matrix class
$mA=new Matrix($raw_matrix_a);
$mB=new Matrix($raw_matrix_b);
$mC=new Matrix($raw_matrix_c);
$mD=new Matrix($raw_matrix_d);

//get the matrix element
//set value
$mA->set(1,1, 0);
//get matrix dimension

$mE=$mD->plus($mC); //must have same dimension
$mE=$mD->inverse(); // must be square matrix

Play DASH video and DASH audio at the same time using VLC

VLC playing DASH video and DASH audio at the same time

As you may know, you can download youtube video using The advantage of over is that vrank allow you to download the video in their original format supplied by youtube. The one we will discuss is about DASH video and DASH audio formats. They are high quality video and audio formats but it has drawback: when you download a video in DASH video format you can’t hear any sound AND when you download in DASH audio format, you can’t see any video (obviously!).

DASH video and DASH audio formats option in

DASH video and DASH audio formats option in

Why? Well, the simple answer is: google/youtube separate the video into two stream: video and audio. So, when you are streaming a youtube video (using browser) in high quality format (720p and up), you actually download/stream from two different files.

Now, how can you play these two files (DASH video and DASH audio) at the same time? We will use VLC to do this!

  • Let’s assume you already downloaded the two files (DASH audio and video)
  • Open VLC
  • Access Menu: Media –> Open Multiple Files…
VLC: Media --> Open Multiple Files...

VLC: Media –> Open Multiple Files…

  • A new empty “Open Media” window will be opened, click on that “Add” button then browse and select your first file (could be DASH video or DASH audio file, not in particular order)
VLC: Open Media window

VLC: Open Media window

  • Check/click/activate “Show more options” checkbox
VLC: show more options checkbox

VLC: show more options checkbox

  • Check/click/activate “Play another media synchronously …” then click on “Browse…” button
VLC: play other media synchronously

VLC: play other media synchronously

  • A new empty “Open Media” window will be opened. Click “Add“, browse to your second files (either DASH audio or DASH video depended on your first opened file). Then click “Select” button (the button will become active/clickable after you choose your second file), this second “Open Media” window will be automatically closed.
VLS: a new empty "Open Media" window

VLS: a new empty “Open Media” window

  • Now, you’ll have the two files chosen and listed on the first “Open Media” window. You may click “Play” button.
VLC: two files is selected

VLC: two files is selected

VLC will play those two files synchronously, you may check it via VLC menu: Tools –> Codec Information, there will be two stream played together.

VLC playing DASH video and DASH audio at the same time

VLC playing DASH video and DASH audio at the same time