Category Archives: Software

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:

https://www.phpclasses.org/blog/package/9199/post/3-Smoothly-Migrate-your-PHP-Code-using-the-Old-MySQL-extension-to-MySQLi.html#convert

Advertisements

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

SCP

Examples

Copy the file “foobar.txt” from a remote host to the local host

$ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file “foobar.txt” from the local host to a remote host

$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory “foo” from the local host to a remote host’s directory “bar”

Continue reading SCP

Measuring elapsed time

Windows

#include <windows.h> 
...   
using namespace std;

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

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

    return 0;
}

Linux

#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;
}

Bash

$ time ./myprogram

Bash (in script)

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

 

References:

https://stackoverflow.com/questions/14682824/measuring-elapsed-time-in-linux-for-a-c-program

https://stackoverflow.com/questions/2150291/how-do-i-measure-a-time-interval-in-c

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

Wifi

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

Multimedia

  1. Shazam
  2. SoundHound
  3. Backgrounds

System tools

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

Consumer

  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 = "https://docs.google.com/spreadsheets/d/"+ 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:

https://developers.google.com/drive/v3/web/integrate-open

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);
};

 

References:

http://igoogledrive.blogspot.gr/2012/08/send-google-spreadsheet-sheet-to-email.html

https://webapps.stackexchange.com/questions/60445/send-an-email-with-attachment-using-google-apps-script

https://developers.google.com/drive/v3/web/integrate-open

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:

https://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c

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;
    ....
}