Author Archives: manuel

change wordpress url in database

if you need to move wordpress to a new url then the following sql script will be handy (update the urls in it of course):

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

Install OSM Nominatim in Ubuntu LTS 18.04 for private reverse geocoding

I recentely found out about OpenStreetMap Nominatim and its reverse geocoding feature. And same as OSM it can be installed on a local server. I followed the installation steps documented in online manual and everything runs very smoothly.

#!/bin/bash
# steps for 18.04 LTS with latest updates
# run as root

export USERNAME=nominatim
export USERHOME=/srv/nominatim
export NOMATIM_VERSION=3.4.1
export NOMINATIM_SOURCE_DIR=$USERHOME/Nominatim-${NOMATIM_VERSION}
export BUILD_LOCAL=$USERHOME/build/settings/local.php
export BUILD_UTILS=$USERHOME/build/utils
export PG_CONF=/etc/postgresql/10/main

# installation
apt update
apt dist-upgrade -y
apt-get install -y build-essential cmake g++ libboost-dev libboost-system-dev \
                   libboost-filesystem-dev libexpat1-dev zlib1g-dev libxml2-dev \
                   libbz2-dev libpq-dev libproj-dev \
                   postgresql-server-dev-10 postgresql-10-postgis-2.4 \
                   postgresql-contrib-10 postgresql-10-postgis-scripts \
                   apache2 php php-pgsql libapache2-mod-php \
                   php-intl git python3-pip
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# user
useradd -d ${USERHOME} -s /bin/bash -m ${USERNAME}

# apache
tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
<Directory "/srv/nominatim/build/website">
  Options FollowSymLinks MultiViews
  AddType text/html   .php
  DirectoryIndex search.php
  Require all granted
</Directory>
Alias /nominatim /srv/nominatim/build/website
EOFAPACHECONF
a2enconf nominatim
systemctl restart apache2

# nomatim
sudo -u $USERNAME -H sh -c "cd $USERHOME && wget https://nominatim.org/release/Nominatim-${NOMATIM_VERSION}.tar.bz2 && tar xf Nominatim-${NOMATIM_VERSION}.tar.bz2 && mkdir build && cd build && cmake $USERHOME/${NOMINATIM_SOURCE_DIR} && make"

tee $BUILD_LOCAL << EOFLOCAL
<?php
 @define('CONST_Website_BaseURL', '/nominatim/');
 @define('CONST_Osm2pgsql_Flatnode_File', '${USERHOME}/flatnode.file');
EOFLOCAL

# postgre
sudo -u postgres createuser -s $USERNAME
sudo -u postgres createuser www-data
cp postgresql_preimport.conf postgresql_postimport.conf ${PG_CONF}
mv ${PG_CONF}/postgresql.conf ${PG_CONF}/postgresql.conf.orig
ln -s ${PG_CONF}/postgresql_preimport.conf ${PG_CONF}/postgresql.conf
systemctl restart postgresql

#  wikipedia data
#cd $NOMINATIM_SOURCE_DIR/data
#wget https://www.nominatim.org/data/wikipedia_article.sql.bin
#wget https://www.nominatim.org/data/wikipedia_redirect.sql.bin
#wget https://www.nominatim.org/data/gb_postcode_data.sql.gz
#wget https://www.nominatim.org/data/us_postcode_data.sql.gz

# streetmap data
export MAP_DATA_DIR=$USERHOME/mapdata
mkdir $MAP_DATA_DIR
cd $MAP_DATA_DIR
wget https://download.geofabrik.de/europe/austria-latest.osm.pbf

# fix permissions after getting all data
chmod -R a+x $USERHOME
chown -R ${USERNAME}:${USERNAME} $USERHOME

# install map data
sudo -u $USERNAME -H sh -c "$BUILD_UTILS/setup.php --osm-file $MAP_DATA_DIR/austria-latest.osm.pbf --all" 2>&1 | tee $USERHOME/setup-austria.log

# update process
sudo -u $USERNAME -H sh -c "pip3 install --user osmium"
echo " // update process" >> $BUILD_LOCAL
echo " @define('CONST_Pyosmium_Binary', '/srv/nominatim/.local/bin/pyosmium-get-changes');" >> $BUILD_LOCAL
echo " @define('CONST_Replication_Url', 'https://download.geofabrik.de/europe/austria-updates');" >> $BUILD_LOCAL
echo " @define('CONST_Replication_Update_Interval', '86400');" >> $BUILD_LOCAL
echo " @define('CONST_Replication_Recheck_Interval', '900');" >> $BUILD_LOCAL
sudo -u $USERNAME -H sh -c "$BUILD_UTILS/update.php --init-updates"

# enable fsync of postgre
rm ${PG_CONF}/postgresql.conf
ln -s ${PG_CONF}/postgresql_postimport.conf ${PG_CONF}/postgresql.conf
service postgresql restart

The mentioned files are also included here:

After installing it i was able to call the reverse geocoding API like this (replace the ip with the one of your server):

curl -X GET 'http://192.168.0.247/nominatim/reverse.php?lat=48&lon=15&osm_type=N&format=json&zoom=3'

{"place_id":3655636,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":16239,"lat":"47.2000338","lon":"13.199959","display_name":"Österreich","address":{"country":"Österreich","country_code":"at"},"boundingbox":["46.3722761","49.0205305","9.5307487","17.160776"]}

add systray to elemtary os

Elementary OS 5 comes with a very limited systray functionality that needs to be fixed. For this you need to install wingpanel-indicator-ayatana that can be installed via a PPA and change autostart config of the indicator app.

Install wingpanel-indicator-ayatana

sudo add-apt-repository ppa:yunnxx/elementary
sudo apt update
sudo apt install indicator-application wingpanel-indicator-ayatana

Change autostart config

Open the config file with

sudo vim /etc/xdg/autostart/indicator-application.desktop

and change the line

OnlyShowIn=Unity;GNOME;

to

OnlyShowIn=Unity;GNOME;Pantheon;

Then reboot your machine and you should have a systray that displays your application icons too.

Nvidia GeForce GTX 2070 Super under Linux

I installed a Nvidia GeForce GTX 2070 Super (https://geizhals.at/msi-geforce-rtx-2070-super-gaming-x-trio-v372-257r-a2091022.html) in my system removing a GTX 980. The system has a dual boot with Win10 and elementary OS 5. Both system were using the nvidia native driver. There was no extra effort neither in Windows nor elementary OS. Windows took about a minute to switch to the correct driver after starting with 1024×768. Elementary OS wasn’t interested at all in the change. Conclusion: Using a GeForce GTX 2070 Super works like a charme under Windows and Linux. At least for me and my system configuration. So please don’t blame me if you are running into troubles.

You can find that article on amazon under https://amzn.to/2A3l8Bh.

How to use Epson POS printer TM-T20II under linux

Getting an epson pos printer up and running under linux is very easy:

# add current user to lp group (requires relogin to work properly)
sudo usermod -a -G lp $USER

# for TM-T20II add udev rule (optional in my case):
echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0e15", MODE="0664", GROUP="lp"' > sudo tee -a /etc/udev/rules.d/99-escpos.rules
sudo service udev restart

# install pip and pipenv
sudo apt install python3-pip libopenjp2-7
pip3 install --user pipenv

# install download python-escpos and submodules
git clone https://github.com/python-escpos/python-escpos.git
cd python-escpos
git submodule update --init --recursive

# install including deps
pipenv install -e .

Now you should be ready to use the installation. From your installation repository run a pipenv shell by using “pipenv shell” or simply run “pipenv run python your-script_.py” to run a script directly.

Here is an example script:

from escpos.printer import Usb

# see https://github.com/python-escpos/python-escpos/blob/development/src/escpos/escpos.py

""" Seiko Epson Corp. Receipt Printer (EPSON TM-T20II) """
p = Usb(0x04b8, 0x0e15, 0, profile="TM-T88II")

p.set(bold=True, underline=1, align='center', custom_size=True, width=2, height=2)
p.textln("Hello world")
p.ln(count=1)
p.set()
p.textln("this is a test")

p.set(align='center')
p.image("examples/graphics/climacons/rain.png")
p.qr("Dies ist ein Test", size=8)
p.set()

p.barcode('1324354657687', 'EAN13', width=3)
p.barcode('123456', 'CODE39', width=3)

p.block_text("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.", font='a', columns=None)

p.cut()

redis-server on ubuntu 18.04

After installing redis on my machine I received the following error message:

redis-server.service: Can’t open PID file /var/run/redis/redis-server.pid (yet?) after start: No such file or directory

This message comes because redis refuses to start with disabled ipv6. To get it running you have to remove “::1” from “bind 127.0.0.1 ::1” in /etc/redis/redis.conf. Then redis starts as expected.

Add charles certificate to JVM

This is an example how to do that on a Mac:

sudo keytool -import -noprompt -alias charles-$(date +%Y%m%d%H%M%S) -file "Downloads/charles-ssl-proxying-certificate.pem" -keystore "/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home/lib/security/cacerts" -storepass changeit