A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

What "Wide character in print" means in Perl (hint: UTF8)

 It means there is a glitch in the matrix - agents are coming!

(further reading)

Hack your own MySQL to log in as root

$> sudo service mysql stop

$> mysqld --skip-grant-tables

$> mysql

mysql> FLUSH PRIVILEGES;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

mysql> SELECT host, user, plugin FROM mysql.user;

(source)

Note-taking apps for desktop, web and mobile

November 2021

Joplin

Tomboy

  • Tomboy appears very linux-centric, although it has clients for Windows and Mac too.
  • It has an Android app, TomDroid.
  • It has a WebDAV plugin for publishing to the web
  • No web actual app

Evernote

  • Proprietary software
  • Charges actual money
  • Irritating business practices
  • Free version only allows two devices, which isn't enough

Org mode

Colornote

  • Works brilliantly on Android
  • Super fast for short notes
  • No web app

Others

Delete all files except one on linux

Glob

  • shopt -s extglob
  • rm -v !("filename")
  • rm -v !("filename1"|"filename2")
  • rm -v !(*.zip|*.odt)
  • shopt -u extglob
Find
  • find /directory/ -type f -not -name 'PATTERN' -delete
  • find /directory/ -type f -not -name 'PATTERN' -print0 | xargs -0 -I {} rm {}
  • find /directory/ -type f -not -name 'PATTERN' -print0 | xargs -0 -I {} rm [options] {}
  • find . -type f -not \(-name '*gz' -or -name '*odt' -or -name '*.jpg' \) -delete
Glob ignore
  • cd test
  • GLOBIGNORE=*.odt:*.iso:*.txt
  • rm -v *
  • unset GLOBIGNORE

All the homebrew packages I've installed on Mac OSX

I've used `brew install ....` many times, but now I'm regretting it because:

  • `brew update` takes so incredibly long to run, and downloads lots of unnecessary git history
  • `/usr/local/Cellar` is 3.8Gb big and I'm short on disk space
List of brew installed apps, in date order:
  • redis@4.0
  • watch
  • tree
  • dnsmasq
  • libunistring
  • libxmlsec1
  • xmlsec1
  • ack
  • putty
  • cmatrix
  • the_silver_searcher
  • ag
  • youtube-dl
  • elasticsearch@6.7
  • vbindiff
  • libpng
  • ilmbase
  • oniguruma
  • jq
  • telnet
  • gifsicle
  • fontconfig
  • tidy-html5
  • minio
  • gcc@4.9
  • autoenv # bugged: breaks "cd -"
  • direnv
  • maven@3.6
  • htop-osx
  • htop
  • xvid
  • npm
  • node@14
  • lsd
  • id3v2
  • nghttp2
  • gnutls
  • sphinx-doc
  • protobuf@3.17
  • markdown
  • postgres@13
  • ruby
  • httrack
  • chafa
  • wget
  • python@3.7
  • python2
  • coreutils
  • ctags-exuberant
  • ctags

Improving Perl's Test2 documentation and using the metacpan docker image

#fixallthethings #tooling #fail on Mac OSX 13.6 High Sierra

Folding@Home FAHClient on Mac OSX

Mac [23:49  ~$] pkgutil --file-info /usr/local/bin/FAHClient
volume: /
path: /usr/local/bin/FAHClient
pkgid: org.foldingathome.fahclient.pkg
pkg-version: 7.5.1
install-time: 1585049394
uid: 0
gid: 0
mode: 755



Mac [23:50  ~$] pkgutil --files org.foldingathome.fahclient.pkg
Applications
Applications/Folding@home
Applications/Folding@home/Web Control.url
Library
Library/LaunchDaemons
Library/LaunchDaemons/org.foldingathome.fahclient.plist
usr
usr/local
usr/local/bin
usr/local/bin/FAHClient
usr/local/bin/FAHCoreWrapper

How to install libxmlsec1 via Alien::LibXMLSec on Mac OSX

  1. Make sure openssl is installed
  2. Download Alien::LibXMLSec (it's not on CPAN)
  3. Unzip it & change to dir
  4. perl Makefile.PL
  5. PKG_CONFIG_PATH=/usr/local/Cellar/openssl@1.1/1.1.1k/lib/pkgconfig make
  6. make
  7. make install
Note: To get the Makefile.PL to run (i.e. step 3½), you may also need to:
  • git clone Alien::Build from its git repo
  • do a `dzil build` on that
  • then set the PERL5LIB to point to the built instance of Alien::Build
  • ...and also make sure its deps are in PERL5LIB.

How to install DBD::Pg Perl module on Mac OSX

Make sure `pg_config` is in your path, and that's it! DBD::Pg will build normally.

How to use dbdeployer to easily deploy multiple versions of MySQL for testing

Download dbdeployer, it is awesome.

Caveat: For best results, you should have a recent version of your operating system installed.

dbdeployer cheat sheet

export PATH=/path/to/dbdeployer:$PATH

dbdeployer downloads tree --flavour mysql --OS linux

dbdeployer downloads get-unpack [filename here]

dbdeployer deploy single 8.0.22

dbdeployer sandboxes

dbdeployer use msb_8_0_22

dbdeployer sandboxes --full-info

Note: Your databases will be installed into e.g. ~/opt/mysql
And a special set of controls will be put in ~/sandboxes

Working with dbdeployer

~/sandboxes/msb_8_0_22/my sql -h 127.0.0.1 --port 8022 ...etc

~/sandboxes/msb_8_0_22/metadata socket


Compiling DBD::mysql for Perl on Mac OSX

I will tell you how:



Idea: Automated testing of database schema design

When writing or maintaining a MySQL database schema, there are a number quality checks that could conceivably be automated:

  • Run the test suite and print out all the SQL statements it runs (e.g. for Perl set DBIC_TRACE=1). Now check that every column mentioned in a `where` clause has an index on it.
  • Indexes are defined by: `KEY` or `UNIQUE` next to them
  • Indexes are probably most important on large data tables, so identify those manually.

Mojolicious version 9 cheat sheet

Mojo 9 changes:

s/over/requires/

s/route/any/

s/via/methods/


Parse a Perl stack trace for ease of understanding

Problem:

A Perl stack track is difficult to parse with my inferior human brain; I want to align each line horizontally so that discrepancies jump out at me.

Solution:

This isn't the whole solution, but it goes some way towards it.

perl script.pl | grep -v ^eval | perl -plne'$len=300-length($_); $space=" "x$len; s/called at /${space}called at /'


Type GBP symbol without numeric keypad

Full size keyboard numpad method

If you have a numeric keypad to the right of you keyboard, you can type Alt+0163 to get a UK pound sterling symbol on a US-keyboard.

Modern laptop numpad method

Some laptops use a Fn (function) key and overlay the numpad on the main keyboard - so on a Dell Latitude I can hold Alt+Fn and type MJOL (which corresponds to 0163) to get a £ symbol.

...but some modern laptops don't have a numeric keypad at all. For those situations, see below.

Keyboard language switch

Install a UK keyboard alongside the US keyboard in control panel, and then type Win+Space to switch between them. Probably Windows 10 only.

Shift-3 usually types a # (hashtag) when set to US keyboard, and a £ (pound sterling) when set to UK keyboard.

Windows 10 character map (May 2019 update)

Type Win+. (dot) and you'll get a character map with all the symbols you'll ever need! 😊

It even remembers the ones you've used recently for quick access. (❁´◡`❁)

For faster keyboard navigation you can press [Tab] to cycle through the controls and [Enter] to select.

Old Windows method

Open the character map application from the start menu. You can search for it in the latest Windows, or it may be hidden in the Accessories folder for older versions.


Perl one-liner to decode JSON

 cat file.json | sed 's/\/\/.\+//' | perl -MData::Dumper::Concise -MJSON -n0777 -E '$r = decode_json($_); say Dumper($r)'

Debugging Perl data structures

Use Data::Tersify like this:

    print Dumper( tersify($complicated_data_structure) );


Quick guide: How to set up MySQL and PostgreSQL databases for Perl development

# The following means mysql is not running:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)


MySQL

INSTALL

sudo apt install -y libmysqlclient-dev mysql-client mysql-server

START

$ sudo service mysql start

SETUP

CREATE USER zaphod;

ALTER USER 'zaphod'@'%' IDENTIFIED BY 'some_pass';

GRANT ALL PRIVILEGES ON *.* TO 'zaphod'@'%'; -- makes zaphod an admin

FLUSH PRIVILEGES;

ACCESS

$ mysql -u zaphod -D some_db -p

ADMIN ACCESS

$ sudo mysql


PostgreSQL

INSTALL

sudo apt install -y postgresql libpq-dev

START

$ sudo service postgresql start

SETUP

create user zaphod;

\password zaphod

create database some_db;

grant all privileges on database some_db to zaphod;

ACCESS

$ psql -U zaphod -h localhost -d some_db

# specifying the host forces md5 (password) authentication. Otherwise default is "peer"

ADMIN ACCESS

$ sudo su postgres

$ psql