Giving old tech a second chance

A bit of re-soldering and cleanup and this old Swedish-branded, Taiwanese-produced Esselte AV-system tape recorder/player will have a second life as a portable speaker system. Unfortunately, someone had tried to fix this box before me, had reassembled the cassette mechanism incorrectly and few springs are missing so I could not make the tape part work.

ESSELTE AV-system cassette tape recorder/player
ESSELTE AV-system cassette tape recorder/player. Model: JCC-420C

After a friend gave this box away as a useless piece of garbage, I decided to research it. After some frustrating and fruitless scanning of Google results, I found someone in Sweden selling a similar system for 900 Swedish krona (about 96 €).

Sysadmins these days

How can a person working as a server admin look at following PHP lines and in all seriousness decide that it’s suspicious?

if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) {

              $return_val = $this->result;

            } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) {

            if ( $this->use_mysqli ) {

             $this->rows_affected = mysqli_affected_rows( $this->dbh );

                } else {

              $this->rows_affected = mysql_affected_rows( $this->dbh );


Yes, it’s impossible to knows every PHP function, but not bothering to RTFM and not being able to “decipherer” a fairly simple regular expression, shows complete lack of competence.
I’d stay away from any company employing this tech monkey who asks for help on Twitter. The second noun in his Twitter moniker explains more than the first. Hi there, @monkeypigs.

His allegations would not bother me if not for subsequent spreading of FUD on Twitter and forums. That was a prick move and not acknowledging the mistake is irresponsible at best. I didn’t deny responsibility for my actions. Now’s your turn to show some responsibility and retract your failed allegations, Garry.

Final verdict: People should not make any decisions if they don’t understand what they are talking about.

Entitlement to vitriol & name calling

No need to point out that this post is passive-aggressive. It’s a calculated decision. It’s written for someone who really digs this communication form.

Apparently, being exposed to hatred entitles people to spew venom and do name calling. I did not expect that. Then again, I’ve barely scratched the surface trying to understand culture and ethical norms of Brits.


Please count how many times you’ve called me a “twatt” and such in the forum post, tweets and blog posts. Now divide that numbers by a number of times I’ve slung slang at you. Oh, wait! That would be a division by zero.

That is the main reason I will not be around any more. Not because I feel guilty but because of the vitriol coming from someone I didn’t expect it.

Oh, and you should really give the plugin code to a security expert for thorough inspection. Who knows what that regex does. Well, unless exact same code is in WordPress core, where it was copied from to support mysqli in previous WordPress versions.

Someone in the community should have an earlier version without the alleged hack or the original code containing the alleged hack. You know, I could have removed it before you downloaded it yesterday.

Can I take off the tin foil hat now?

Stay safe,

Paris – the lost & found film

While cleaning my home before Christmas I found an undeveloped film and I had no idea how old it was or what was on it. It’s been at least five years since the last time I shot on film. So I gave the film to photo shop and ordered scans. I had to wait a while because they don’t get many films nowadays and turning on the machine is too expensive for single film.

Two weeks ago I received a text about my order but I delayed picking it up. The other day I finally picked it up and to my surprise the film contained pictures from Summer 2007 when I and two other guys went on a Eurotrip during which two of us stayed in Paris for four days.

Just to be clear, I have not used any effects or filters apart from adjusting contrast. There are (d)effects because the film had deteriorated lying around for seven years in changing temperatures and humidity.

Live each day as if it’s your last

There is this saying:

Live each day as if it’s your last

I never liked it because it allows for wide interpretation.

I believe, everyone should strive to live every day so that people have something nice to say and remember when you are gone. They shouldn’t have to come up with general phrases like “He was a nice person” and similar.

I’m a Star

About four years ago, after a party, good friend of mine, who also happens to be one of the most popular DJs in Latvia, introduced me to Andy, You’re a Star by the Killers from their 2004 album Hot Fuss. Somehow he felt that it was related to me then. I still like to listen to it sometimes, although it’s not in my regular song rotation.

Thank you, Toms. Whatever you meant when you did it.

Well, today is my name day (yes we celebrate those in Latvia) and I sent a tweet to the radio station where the friend is doing morning show, asking to play first song that came to his mind in relation to my name. I already knew what it would be and, sure enough, it was this one.

After the song was over, I decided to look up the actual meaning of following lyrics:

In a car with a girl, promise me she’s not your world
Cause Andy, you’re a star
In nobody’s eyes but mine
Andy, you’re a star
— The Killers

Apparently the Andy mentioned in lyrics was one of those high school bullies, according to this:

A guy named Andy Messersmith went to school with Brandon Flowers. They went to Juab High School in Nephi, Utah, and Andy was the popular sports star, and he tortured Brandon and made his time there miserable. So Brandon wrote this song sarcastically.


Hopefully, the lyrics can be attributed to me without sarcasm and perceived in a positive connotation.
Oh, by the way, my real name in Latvian is Andis but I choose to introduce myself as Andy to English speakers as it is easier to remember and I don’t mind being a star.

Alan Turing – The Codebreaker

An obligatory TL;DR

Alan Turing was a genius who defined the basic principles of how computers operate and he helped to end World War II by working on deciphering of Enigma messages. He was a homosexual.

The actual post

In the light of upcoming flick The Imitation Game, I re-watched an earlier TV documentary about Alan Turing – Codebreaker. This time it touched me more than the first. What follows are my thoughts and expansion on the main facts.

When Alan Turing took his own life, he didn’t leave a note. However, he left a legacy with far reaching effects and it has to be appreciated.

UK could have become the major player in computer technologies if they hadn’t treated the genius as badly as they did. Especially during his last years. Many people  nowadays should be thankful for having jobs and opportunities that would simply not be there if not for a man who started the revolution of computing machines. Although, society has come a long way since then in regard to treating people with different sexuality. Who knows – first personal computers could have been created by the Brits as early as 1960s if it wasn’t for the draconian laws of that time that were made even worse by cold war paranoia.

This could and should be used as a perfectly valid argument to make arguing homophobes shut up if he or she had ever used a computer or even works in the industry. And don’t get me started about those on-line comments by homophobic trolls.

If you are homophobic and you’re not reading this on a piece of paper, just think about the hypocrisy. Even the screen you are reading these words would not be possible without the basic principle of using ones and zeroes in computers, and it was invented by a gay person.

I’d like to finish this piece with a quote;

Science is a differential equation. Religion is a boundary condition.

— Alan Mathison Turing

Post image: Decoding Alan Turing by Charis Tsevis

Zip files with PHP and upload to Dropbox

Important note: Dropbox API v1 is deprecated and will be disabled on June 28, 2017.
I’ll update this post as soon as I have time.

I needed a quick and dirty cheap backup solution for ever growing directory of MySQL backups.

Some were already backed up on Dropbox. So, I decided to throw together a PHP script which could upload those sql files without having to rely on Dropbox client. Then use cron to launch the script after daily MySQL dump. Few web searches later I found DropboxUploader on GitHub but I didn’t like its approach. Official API seems more elegant as it uses OAuth 2 authentication.


First of all, take a look at introduction on using Dropbox API with PHP, then download Dropbox SDK for PHP.

Register an app on Dropbox App Console to get API key and secret. Paste values into config.json.


Include Dropbox API autolaoder and define dbx alias for \Dropbox namespace:

# Include the Dropbox SDK libraries
require_once __DIR__."/dropbox-sdk/lib/Dropbox/autoload.php";
use \Dropbox as dbx;

I didn’t bother with the authentication part because I will use the “app” only for this script. I just generated access token in App Console and hardcoded it in my script.

$accessToken = 'NotARealTokenXQAAAAAAAAABmKadnX7wFdbUyIllvKphLHSXPqBNotARealToken';

createZip function

To make things easier, I wrapped the compression code in a function.

 * Add array of $files to $output_file archive and deletes the
 * files after successful archiving
 * @param $files array Array of files to zip
 * @param $output_file string Archive path
 * @return string|boolean Path of zip file or FALSE if anything failed
function createZip($files, $output_file){

	$zip = new ZipArchive();

	if ($zip->open($output_file, ZipArchive::CREATE)!==TRUE) {
		exit("cannot open '$output_file'".PHP_EOL);
	$to_delete = array();
	foreach($files as $file){
		if(!file_exists($file) || !is_readable($file)){
		if($zip->addFile($file, basename($file))){
			$to_delete[] = $file;
	$status = $zip->status;
	$success = $zip->close();

	// Delete files after ZipArchive::close() because ZipArchive locks files
	foreach($to_delete as $file){

	return $status == 0 && $success ? $output_file : FALSE;

Load Dropbox client and set access token

$appInfo = dbx\AppInfo::loadFromJsonFile(__DIR__."/config.json");
$dbxClient = new dbx\Client($accessToken, "MySQLbumps-BACKUP/1.0");

And the main part

Zipping and uploading

// define some required paths
define('TEMP_DIR', sys_get_temp_dir());
// Local backup location. Change path as needed
define('BACKUPS_DIR', '/var/backup/mysql/');

// Find latest file and upload so that there is at least one fresh backup
$latest = glob(BACKUPS_DIR.'*_'.date('Y-m-d').'*.sql');
$latest_file = reset($latest);

if($latest_file && file_exists($latest_file)){
	echo "Found latest backup: '".basename($latest_file)."'".PHP_EOL;
	$temp_zip = TEMP_DIR.'';
	// delete old zip file if it exists otherwise the file will be added to that zip
	$upload_file = createZip(array($latest_file), $temp_zip);
	$f = fopen($temp_zip, "rb");
	$result = $dbxClient->uploadFile('/MySQL backups/', dbx\WriteMode::force(), $f);
		echo "Uploaded ".basename($temp_zip).PHP_EOL;

// Check if there are any files from past month
$date_part = date('Y-m', strtotime('last month'));
$search = BACKUPS_DIR.'*_'.$date_part.'*.sql';
$files = glob($search);
	echo "Nothing to do: no files match '$search'".PHP_EOL;

$zip_file = 'Backup_'.$date_part.'.zip';
echo("Creating $zip_file file for MySQL dumps from last month".PHP_EOL);
$upload_file = createZip($files, BACKUPS_DIR.$zip_file);
if(!$upload_file || !file_exists($upload_file)){
	$msg = 'Could not create zip archive';

echo("Uploading $zip_file to Dropbox\n");
$f = fopen($upload_file, "rb");
$result = $dbxClient->uploadFile('/MySQL backups/'.$zip_file, dbx\WriteMode::force(), $f);

I have set the script to run right after nightly MySQL dump. Now I can sleep in peace knowing that I’ll have all backups from previous months and one from last night if anything goes wrong.

Have any suggestions? Add them in comments sections.