Development notes

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

Jump to

Quick reference

Set up Joplin

## Install

Install node 12+

Then:
```
NPM_CONFIG_PREFIX=~/.joplin-bin npm install -g joplin

sudo ln -s ~/.joplin-bin/bin/joplin /usr/bin/joplin
```


## Configure

```
joplin help config
joplin config sync.target 7 # dropbox
joplin sync # then follow instructions
```

Quick reference

.

Mac: \r
Unix: \n
Windows: \r\n
vi s/,/,\r/
$CRLF = "\015\012";
perl -le'$q = "\047"; print $q' # single quote

unset PERL5LIB; unset PERL_LOCAL_LIB_ROOT; unset PERL_MB_OPT; unset PERL_MM_OPT; eval $(perl -Mlocal::lib=./local)

perl -MDevel::Cover=+ignore,.*,-select,^lib,-select,^t,-silent,on t/path/to/test.t

python -m SimpleHTTPServer 8080
python3 -m http.server 8080

warn "mojo response = ".$t->tx->res->to_string;
...->or(sub { diag("Result = ".$t->tx->res->to_string) });

use Data::Printer { class => { internals => 0, inherited => 'public' } };

my $r=\@_; $l->debug("entering ".( caller(0) )[3])." with ". sub { $l->dump(args => $r) }); # log calls to subroutines

patch -p0 < file.patch

DBIC_TRACE_PROFILE=console DBIC_TRACE=1
TEST_METHOD=foo

$Data::Dumper::Maxdepth = 1;

$DB::single = 1;

echo -ne "\033]0;"some title"\007" # set putty title

shopt -s checkwinsize; reset # fix terminal display issue

# bash strict mode
set -euo pipefail
IFS=$'\n\t'
# debug mode
set -vx

(s)printf:
printf '<%+d>', 12; # prints "<+12>"
printf '<%6s>', 12; # prints "< 12>"
printf '<%-6s>', 12; # prints "<12 >"

eval $(dircolors|sed 's/di=01;34/di=01;36/'); # light blue directories

if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root"
exit 1
fi

| python -m json.tool # sorts keys
| json_pp # doesn't sort keys (perl JSON module)

Search and replace over two lines:
sed ':a;N;$!ba;s/\n second line: / second line: /g'


Bash quotes: '\'' & '"'"'

print "debug = ".Dumper({%{{$_->get_columns}}{qw/id shipment_id/}}) foreach $shipment_rs->items; # DBIC quick peek

print $result->{_column_data} # DBIC quicker peek

require Carp; Carp::cluck "got here";

telnet host port

openssl s_client -debug -connect host:port

www.tablesgenerator.com

How to really loop over filenames with spaces in

 Don't parse the output of "ls".

Instead:

for file in *

do

  ...

done


(source)

Automating mouse movement and clicks on Linux

Windows has AutoHotkey (AHK), and Linux has xdotool.

But xdotool 3.20160805.1 doesn't work on Wayland at all. It silently fails. Turns out xdotool only works on X11, which is no longer the default for Ubuntu.

In 2024, using Ubuntu 22, this version of xdotool is the latest one available by running `apt install xdotool`.

To find out if you're using Wayland:

$ loginctl show-session 2 -p Type
Type=wayland
$ echo $XDG_SESSION_TYPE
wayland

To switch to X11, edit/etc/gdm3/custom.conf, uncomment the line WaylandEnable=false, and reboot.

Now xdotool will work perfectly.

xdotool README does mention some alternatives:

  • ydotool (available in apt) -- last updated January 2023, also didn't work for me on Wayland or X11
  • dotool -- updated more recently, but not packaged for Ubuntu, and building from source requires Go, which is quite heavy so it's easier to just switch to X11 for xdotool.

Ubuntu Linux setup basics

For username "foo":

$ adduser foo

$ passwd foo

$ sudo usermod -aG sudo foo

mkdir -p /home/foo/.ssh

$ cat the_public_key.pem >> /home/foo/.ssh/authorized_keys

chown -R foo:foo /home/foo/.ssh

$ chmod 700 /home/foo/.ssh

$ chmod 600 /home/foo/.ssh/authorized_keys
Disable default account:
$ usermod -s /usr/sbin/nologin default_username

Notes:
  • Not useradd.
  • Even when logging in with just SSH key, user must have a password. It will only be used for sudo commands.