Import Remote Database Directly over SSH

Developing, maintaining and debugging web-applications often involves copying a remote database to a local or another remote machine. This post lists a number of methods that I find useful. It acts as a reference for myself which I happily update and improve based on comments and experience. My favourite method:  stream the database dump directly to the target machine.

I assume a MySQL or MariaDB database on a Unix or Mac OS machine but by adjusting the appropriate commands most of these methods apply to other databases as well.

Continue reading Import Remote Database Directly over SSH

Configuring MySQL with .my.cnf file

Connecting to a MySQL server often involves providing hostnames, usernames and passwords. Use a .my.cnf configuration file to provide defaults that simplify working with a MySQL server. 

Providing a default password reduces security. Take effort to make sure that the password cannot be read by other users on the system. If the server runs locally, use credentials that are only allowed to connect locally.

Continue reading Configuring MySQL with .my.cnf file

Using Key-based SSH Authentication

If you use Git or remote terminal session a lot, consider using key-based authentication. Key-based authentication is generally considered more secure than password-based authentication. 

In key-based authentication, two key-files are used. One is the public key and may be distributed to other parties that should be able to authenticate you and your information. The other is the private encryption key and should be kept secure.

Continue reading Using Key-based SSH Authentication

Developing for AVR with JetBrains CLion on Mac OS

Previously I used Atmel Studio 7 to do AVR development. This integrated development environment is unsurpassed in terms of ease of use and features for AVR development. However, it is Windows only. I grew tired of the hassle with virtual machines and dual boot setups as my working device as a Mac running Mac OS 10.12. I already used some JetBrains products for C/C++ and PHP development so I wanted to try to get the whole AVR toolchain working on Mac OS in combination with JetBrains CLion.

To serve as a suitable alternative to Atmel Studio I need both compilation, uploading and debugging to integrate nicely with CLion. Furthermore, I wanted to be able to use the Atmel Software Framework to have access to an enormous resource of services, drivers and examples.

Continue reading Developing for AVR with JetBrains CLion on Mac OS

Random values from PHP array one-liner

PHP provides the array_rand( $arr, $num )  function which returns an integer or array containing the keys of the array.

To obtain an array of values the following one-liner can be used:

This picks $num random keys from $arr (array_rand), flips keys with values (array_flip), intersects the picked keys with those of $arr (array_intersect_keys) and returns the corresponding elements of $arr.

Getting random values from an array.

Continue reading Random values from PHP array one-liner

Laravel 5 Cron expression validation

A Cron expression validator is created in Laravel 5.3. Laravel provides a versatile and extendable Validation class. Introducing new validations is done by registering a validation function with the extend method on the Validation facade. A Cron expression validator is created by utilising a cron-expression parser.

The cron-expression parser used here is the fantastic cron-expression Composer package by Michael Dowling.

Continue reading Laravel 5 Cron expression validation

Restore, Clone or Backup your Homebrew Setup

Homebrew is a popular package manager for MacOS. It provides easy access to thousands of programs and applications. It is developed and maintained by an open-source community on Github. Use Homebrew bundle to backup and restore your Homebrew configuration. 

If you haven’t installed it yet, go take a look quick on brew.sh or just install it by running the following command in the MacOS terminal.

The installation should succeed without problems. Installing some nice tools is also easy:

To install a better alternative to the standard process viewer top.

Continue reading Restore, Clone or Backup your Homebrew Setup

Fix Magento 1.9.3 ‘Notice: Undefined index: session_expire_timestamp in … on line 461’

Some days ago the Magento security update SUPEE-8788 was released. This update fixes a number of critical vulnerabilities. To fix an existing shop one could either apply the SUPEE-patch or upgrade the shop to Magento 1.9.3. However, after updating I experienced a little issue when trying to reach the shop again. 

A PHP Exception popped up:

Even after flushing the cache this problem appears. The undefined index and path of the file that raises the exception gives away that this problem might have to with Magento’s session handling. I started with deleting any existing session cookies in my browser. This made the error message disappear. Be aware that this is not an appropriate solution to this error!

Continue reading Fix Magento 1.9.3 ‘Notice: Undefined index: session_expire_timestamp in … on line 461’