Categories
Linux tips

Ubuntu select and paste with Mouse Keys

On Linux I like to make use of the select and paste feature i.e. selecting text copies it and the middle mouse button pastes it. When a laptop touchpad has no buttons a middle mouse click can be simulated with a three-finger tap, but this is awkward.

Here is my workaround (for keyboards with a numeric keypad only):

  1. From the Accessibility menu turn on Mouse Keys.
  2. Ensure the Number Lock is off.
  3. Select text.
  4. Paste text by pressing 5 on the numeric keypad.

Furthermore, in a terminal and some other applications SHIFT + INSERT will paste text which has been previously selected.

I am using Ubuntu 20.04.1 and GNOME 3.36.8

Categories
WordPress

WordPress debugging

To turn on debugging add the following to wp-config.php

// Turn debugging on
define('WP_DEBUG', true);

// Tell WordPress to log everything to /wp-content/debug.log
define('WP_DEBUG_LOG', true);

// Display error messages
define('WP_DEBUG_DISPLAY', true);

Write to /wp-content/debug.log

error_log('logging message here...');
Categories
Backing up

Backup mysql database via socks tunnel

The following bash script will open a socks tunnel with a remote host and use a local mysqldump cli tool to backup a mysql database.

#!/bin/sh
DT=$(date '+%Y-%m-%dT%H:%M:%S')
SUFFIX=
FILENAME=$DT$SUFFIX
BACKUPSPATH=
USER=
IP=
PORT=
DBUSER=
DBPASS=
DBNAME=
echo "Opening socks tunnel to $IP"
echo "Writing $FILENAME"
ssh -f -L $PORT:127.0.0.1:$PORT $USER@$IP sleep 10; \
mysqldump -u $DBUSER -h 127.0.0.1 -p$DBPASS -P $PORT --routines $DBNAME > $BACKUPSPATH/$FILENAME
Categories
Developer notes

Dockerized phpmyadmin

Phpmyadmin is available as a Docker image. The mysql server connection parameters are provided when the container is instantiated.

docker run -d --name pma_local \
--network=docker_network \
-e PMA_HOST=db \
-e PMA_PORT=3306 \
-e PMA_USER=root \
-e PMA_PASSWORD=password \
-p 8080:80 phpmyadmin/phpmyadmin
  • --network The docker network the phpmyadmin container will join.
  • PMA_HOST, PMA_PORT Name and port of the database server host on the docker network.

Browse to phpmyadmin at http://localhost:8080

Categories
Uncategorised

Import Barclays Bank statement

Create a table for the bank statement entries

CREATE TABLE `bank_statement_entries` (
  `id` int(11) NOT NULL,
  `cheque_id` varchar(50) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `amount` decimal(13,4) DEFAULT NULL,
  `subcategory` varchar(50) DEFAULT NULL,
  `memo` varchar(100) DEFAULT NULL,
  `my_notes` text
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

SQL script for importing batch of csv statement entries into table `bank_statement_entries`

DELIMITER $$

/* remove any tables created by a previous run */
DROP TABLE IF EXISTS `bank_statement_entries_raw`$$
DROP TABLE IF EXISTS `bank_statement_entries_batch`$$

/* make an empty copy of the master table to put the batch of statements into */
/* but get rid of the id column */
CREATE TABLE `bank_statement_entries_batch` LIKE `bank_statement_entries`$$
ALTER TABLE `bank_statement_entries_batch` DROP `id`$$

/* prepare a table ready for the raw csv import */
CREATE TABLE `bank_statement_entries_raw` (
  `Number` varchar(50) DEFAULT NULL,
  `Date` varchar(100) DEFAULT NULL,
  `Account` varchar(100) DEFAULT NULL,
  `Amount` decimal(13,4) DEFAULT NULL,
  `Subcategory` varchar(50) DEFAULT NULL,
  `Memo` varchar(100) DEFAULT NULL,
  `Count` int NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (Count)
)$$

/* upload the local csv file */
LOAD DATA LOCAL INFILE '/home/chris/2018-07-31_to_2018-09-03.csv'                        
INTO TABLE `bank_statement_entries_raw`
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS$$

/* populate the batch table */
/* do any transformations here */
INSERT INTO bank_statement_entries_batch (
  cheque_id,
  date,
  amount,
  subcategory,
  memo) 
SELECT 
   `Number`
	,DATE_FORMAT(STR_TO_DATE(Date, '%d/%m/%Y'), '%Y-%m-%d')
	,Amount
	,Subcategory
	,Memo
FROM `bank_statement_entries_raw`
ORDER BY `Count` DESC$$

/* now insert the newly prepared batch of statements in to the master table */
INSERT INTO `bank_statement_entries` (
  cheque_id,
  date,
  amount,
  subcategory,
  memo,
  my_notes
)
SELECT 
  cheque_id,
  date,
  amount,
  subcategory,
  memo,
  my_notes
FROM `bank_statement_entries_batch`$$

DELIMITER ;