29. 7. 2019

Polly.js - Record, replay, and stub HTTP interactions.

Record, replay, and stub HTTP interactions.

Polly.JS is a standalone, framework-agnostic JavaScript library that enables recording, replaying, and stubbing of HTTP interactions. By tapping into multiple request APIs across both Node & the browser, Polly.JS is able to mock requests and responses with little to no configuration while giving you the ability to take full control of each request with a simple, powerful, and intuitive API.

29. 6. 2019

Free IP Geolocation API

Geolocation API

24. 6. 2019

Exiftool tips & tricks

Organize images

Organize images by years/months

exiftool -d "%Y/%m/%Y-%m-%d %H.%M.%S%%-c.%%le" "-filename<CreateDate" -r ./Photos

Download RAW files from SD card to current folder:

exiftool -d "%Y/%m/%Y-%m-%d %H.%M.%S%%-c.%%le" "-filename<CreateDate" --ext raf -r /Volumes/SD

Move all Olympus images to directory Olympus:

exiftool -r '-directory=Olympus' -if '$make eq "OLYMPUS CORPORATION"' .

Rename files to datestamp:

Filename looks like 2014-01-01 12:00:00.jpg and will append -NUM if DateTimeOriginal is the same for multiple files

exiftool '-FileName<DateTimeOriginal' -d "%Y-%m-%d %H.%M.%S%%-c.%%e" .  

Date & time

Find images in a directory that don't have a DateTimeOriginal:

exiftool -filename -filemodifydate -createdate -r -if '(not $datetimeoriginal) and $filetype eq "JPEG"' .

Update any photo that doesn't have DateTimeOriginal to have it based on file modify date:

exiftool '-datetimeoriginal<filemodifydate' -if '(not $datetimeoriginal or ($datetimeoriginal eq "0000:00:00 00:00:00")) and ($filetype eq "JPEG")' .

Set date by filename:

exiftool "-alldates<filename" $@

All metadata

Remove all metadata of a image file:

exiftool -all= -overwrite_original photo.jpg

Remove all metadata of all *.jpg files in current directory:

exiftool -all= -overwrite_original -ext *.jpg

GPS

Strip all metadata except for location (GPS):

exiftool -all= -tagsfromfile @ -gps:all *.jpg

Remove all GPS metadata of *.jpg files in current directory:

exiftool -gps:all= *.jpg

Create KML from geotagged photos:

DESKTOP=$HOME/Desktop
cat $DESKTOP/kml-start.fmt > out.kml
exiftool -n -r -q -p $DESKTOP/kml-placemark.fmt . >> out.kml
cat $DESKTOP/kml-end.fmt >> out.kml

Create CSV of Geo Information:

exiftool -csv -filename -imagesize -gps:GPSLatitude -gps:GPSLongitude ./ > long.csv

Extra

Check Shutter Count:

exiftool -ImageCount [filename]

JSON

Outputs a grouped collection of records as JSON in a directory:

exiftool -json -g /path > collectionprofile.json
1. 3. 2019

Read .env file in bash

Let's have example .env file:

example=value
example2=value

then you can read this file like this:

#!/usr/bin/env bash

set -o allexport
[[ -f .env ]] && source .env
set +o allexport

Warning: All existing variables are overridden by .env content.

28. 12. 2018

Install Netatalk 3.x on Raspberry PI

Compile Netatalk from source

Install required Packages

sudo apt install build-essential \
libevent-dev libssl-dev libgcrypt-dev libkrb5-dev libpam0g-dev \
libwrap0-dev libdb-dev libtdb-dev libmariadbclient-dev \
avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev \
libcrack2-dev systemtap-sdt-dev libdbus-1-dev \
libdbus-glib-1-dev libglib2.0-dev libio-socket-inet6-perl \
tracker libtracker-sparql-1.0-dev libtracker-miner-1.0-dev

Remove old version of netatalk:

sudo apt remove netatalk

then download and extract latest version

wget http://prdownloads.sourceforge.net/netatalk/netatalk-3.1.12.tar.bz2 -qO - | tar -xj
cd netatalk-3.1.12/

Do configure!

./configure \
        --with-init-style=debian-systemd \
        --without-libevent \
        --without-tdb \
        --with-cracklib \
        --enable-krbV-uam \
        --with-pam-confdir=/etc/pam.d \
        --with-dbus-daemon=/usr/bin/dbus-daemon \
        --with-dbus-sysconf-dir=/etc/dbus-1/system.d \
        --with-tracker-pkgconfig-version=1.0
make
sudo make install
sudo reboot

Check features and paths, using netatalk -V and afpd -V.

edit /usr/local/etc/afp.conf

[Global]
; mimic model = RackMac

[Homes]
basedir regex = /home

;[My AFP Volume]
;path = /path/to/volume

;[My Time Machine Volume]
;path = /path/to/backup
;time machine = yes
sudo systemctl enable avahi-daemon
sudo systemctl enable netatalk
sudo systemctl start avahi-daemon
sudo systemctl start netatalk
27. 12. 2018

Raspberry PI, Bonjour service, SSH and AFP

Raspbian Stretch Lite (without desktop)

  1. Download Raspbian Stretch Lite
  2. Install Raspbian with etcher to SD card
  3. Boot from SD card...

Basic configuration and Wifi connection

sudo raspi-config
  1. Change User Password :-) (default user pi with password raspberry)
  2. Change Localisation Options
  3. Enable SSH in Interfacing Options
  4. Configure WiFi in Network Options and change Hostname (in my case to pi)

If you have Wifi with hidden SSID, you will need change /etc/wpa_supplicant/wpa_supplicant.conf file and add scan_ssid=1:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CZ

network={
    ssid="HiddenWifiSSID"
    scan_ssid=1
    psk="and password :)"
}

Reboot (sudo reboot) and then check with iwgetid if you are connected to your Wifi!

Install AFP and Bonjour service

Install netatalk thats provide AppleTalk Filing Protocol (AFP) interface.

sudo apt install netatalk

Install avahi

sudo apt install avahi-daemon
sudo apt install avahi-utils
sudo update-rc.d avahi-daemon defaults

Config AFPD with /etc/avahi/services/afpd.service

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
   <name replace-wildcards="yes">%h</name>
   <service>
        <type>_afpovertcp._tcp</type>
        <port>548</port>
   </service>
   <service>
        <type>_device-info._tcp</type>
        <port>0</port>
        <txt-record>model=RackMac</txt-record>
    </service>
</service-group>

PS: RackMac is define icon that will be shown in Finder (there is plenty other options e.g. Windows, Macintosh, TimeCapsule and so on)

Config SSH with /etc/avahi/services/ssh.service

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
     <name replace-wildcards="yes">%h SSH</name>
     <service>
          <type>_ssh._tcp</type>
          <port>22</port>
     </service>
</service-group>

Configure avahi daemon

Then in /etc/avahi/avahi-daemon.conf change two parametters host-name and publish-workstation:

[server]
host-name=pi # this row
# ...

[publish]
publish-workstation=yes # this row

# ...

Now Awvvaaaahhhhiii

Enable afp and avahi

sudo systemctl enable netatalk
sudo systemctl enable avahi-daemon

and start them

sudo service avahi-daemon start
sudo service netatalk start

now check if everything works well with

avahi-browse -a | grep $(hostname)
23. 12. 2018

Install nodejs on Raspberry PI

First download latest version of nodejs:

wget -qO- http://nodejs.org/dist/latest/node-v12.4.0-linux-armv7l.tar.xz | tar xvz -C ./nodejs
cd nodejs

Compile from sources:

sudo cp -R bin/* /usr/bin/
sudo cp -R lib/* /usr/lib/
sudo apt update && sudo apt upgrade
sudo apt install build-essential
13. 12. 2018

Download website mirror with wget

wget --mirror \
     --convert-links \
     --adjust-extension \
     --page-requisites \
     --no-parent \
     --no-check-certificate http://example.com