Category Archives: Development

Convert MySQL to MySQLi

Here is a summary:

mysql_connect( ‘host’, ‘username’, ‘password’, true)->mysqli_connect( ‘host’, ‘username’, ‘password’);
mysql_affected_rows -> mysqli_affected_rows($link)
mysql_close -> mysqli_close($link)
mysql_data_seek -> mysqli_data_seek( $result, $offset)
mysql_errno -> mysqli_errno( $link)
mysql_error -> mysqli_error( $link)
mysql_fetch_array -> mysqli_fetch_array( $result, $type)
mysql_fetch_assoc -> mysqli_fetch_assoc( $result)
mysql_fetch_lengths -> mysqli_fetch_lengths( $result )
mysql_fetch_object -> mysqli_fetch_object( $result, $class, $params)
mysql_fetch_row -> mysqli_fetch_row( $result)
mysql_field_seek -> mysqli_field_seek( $result, $number)
mysql_free_result -> mysqli_free_result(result)
mysql_get_client_info -> mysqli_get_client_info( $link)
mysql_get_host_info -> mysqli_get_host_info( $link)
mysql_get_proto_info -> mysqli_get_proto_info( $link)
mysql_get_server_info -> mysqli_get_server_info( $link)
mysql_info -> mysqli_info( $link)
mysql_insert_id -> mysqli_insert_id( $link)
mysql_num_rows -> ย mysqli_num_rows( $result)
mysql_ping -> mysqli_ping( $link)
mysql_query -> mysqli_query( $link, $query)
mysql_real_escape_string -> mysqli_real_escape_string( $link)
mysql_select_db – > mysqli_select_db( $link, $database)
mysql_set_charset -> mysqli_set_charset( $link, $charset)
mysql_stat -> mysqli_stat( $link)
mysql_thread_id -> mysqli_thread_id( $link)



Great reference:


qdpm/softaculous – Internal Server Error

Whoaaa, that was a nasty bug ๐Ÿ˜ฎ

Use: Debian 8.8 & Apache 2.4 & php 7.0:

  1. Install qdpm via softaculous (or manually, it doesn’t matter)
  2. Navigate to admin page.

and … BOOM: Internal Server Error.

Messages totally misleading. Directory permissions are okay as is the default .htaccess file. Bug is much deeper.

Continue reading qdpm/softaculous – Internal Server Error

Measuring elapsed time


#include <windows.h> 
using namespace std;

int main() {
    LARGE_INTEGER f;      // ticks per second
    LARGE_INTEGER t1, t2; // ticks
    double dt;

    // ... do stuff
    dt = (t2.QuadPart-t1.QuadPart)*1000.0/f.QuadPart;
    cout << elapsedTime << " ms.\n";

    return 0;


#include <sys/time.h>
using namespace std;

int main() {
    struct timeval t1, t2;
    double dt;
    gettimeofday(&t1, NULL);
    // ... do stuff   
    gettimeofday(&t2, NULL);

    // sec to ms
    dt = (t2.tv_sec - t1.tv_sec) * 1000.0; 
    // us to ms
    dt += (t2.tv_usec - t1.tv_usec) / 1000.0;   
    cout << dt << " ms.\n";

    return 0;


$ time ./myprogram

Bash (in script)

# ... do stuff
dt=$(( end - start ))
echo "stuff took $dt seconds to complete"



My Favorite android apps (free)

Since HTTP links change frequently, there are no direct links included in the list below.

All apps will be easily found if searched on google play or google lucky.

Here is the list (all of them free):

Basic Setup

  1. TokikoFree
  2. QuickDial Free
  3. Google Keep
  4. Google Authenticator
  5. First Aid
  6. B1 archiver

Very Useful Utilities

  1. CamScanner
  2. Flash light Ad Free
  3. Pi Scientific Calculator
  4. Ultimate Stopwatch


  1. WiFi Ruler
  2. Wifi Analyzer
  3. Advanced Spectrum Analyzer
  4. Spectroid


  1. Shazam
  2. SoundHound
  3. Backgrounds

System tools

  1. Advanced Task killer
  2. Permissions Explorer
  3. Sensors Multitool
  4. IP tools


  1. Viber
  2. Viber Contact Photos
  3. Forky
  4. Athens Book



Google docs – send a doc monthly via email

Here is a small script you can attach to a document on Google docs.

Whenever run, it will attach the file and send it to you via e-mail.

function monthlyBackup() {
 var formattedMonth = Utilities.formatDate(new Date(), "GMT", "MM");
 var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd' 'HH:mm:ss");
 var name = SpreadsheetApp.getActiveSpreadsheet().getName() + " backup " + formattedDate;
 var ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
 var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
 //var email = Session.getUser().getEmail();
 var email = "XXX@XXX.XXX";
 var subject = SpreadsheetApp.getActiveSpreadsheet().getName() + " backup at " + formattedDate;
 var body = "This is automated backup from google docs :)";
 var requestData = { "method": "GET", "headers":{"Authorization":"Bearer "+ScriptApp.getOAuthToken()} };
 var url = ""+ ssID + "/export?format=ods&id="+ssID;
 var result = UrlFetchApp.fetch(url , requestData); 
 var contents = result.getContent();
 var attachedFilename = sheetName + " " + formattedMonth + ".ods";
 MailApp.sendEmail(email, subject ,body, {attachments:[{fileName:attachedFilename, content:contents, mimeType:"application//x-vnd.oasis.opendocument.spreadsheet"}]}); 

For more MIME types read this article:

If you want to add a menu item you can also the following code:

function onOpen() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var menuEntries = [ {name: "Send Email", functionName: "monthlyBackup"}];
 ss.addMenu("Scripts", menuEntries);



Pointer arithmetic to void* (uintptr_t)

The link below is a very important one regarding pointer arithmetic, a subject that frequently is being taught incorrectly in many universities:

The best way for general arithmetic on pointers for most architectures is to use the uintptr_tย  data type whenever available.

Cast the pointer to uintptr_t and make any arithmetic operation you want. Then cast the uintptr_t back to the type of the pointer you want:

void calculateModulo(char *address) { 
    uintptr_t x = (uintptr_t)address; 
    x = x % 4;
    char * resultingaddress = (char*) x;


Upgrade to gcc 6.3+ in Ubuntu

To upgrade gcc to gcc6 use the following commands:

sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-6 -y


To set the new gcc as default use the following:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5

Once you have executed the previous command, g++ may not be available.

So you can execute the following to create a link:

sudo ln -s /usr/bin/g++-5 /usr/bin/g++