9. 2. 2020

Modern databases list

MongoDB

MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era. No database makes you more productive.

Couchbase

Couchbase is open source the NoSQL database, distributed, document-oriented engagement database. It exposes a fast key-value store with managed cache for sub-millisecond data operations, purpose-built indexers for fast queries and a powerful query engine for executing SQL-like queries

Amazon DynamoDB

Amazon DynamoDB is a key-value and document database that delivers single-digit millisecond performance at any scale. It's a fully managed, multiregion, multimaster, durable database with built-in security, backup and restore, and in-memory caching for internet-scale applications.

Firebase

Apache Cassandra

Unbounded

PostgreSQL

MariaDB

FaunaDB

FaunaDB is a global serverless database that gives you ubiquitous, low latency access to app data, without sacrificing data correctness and scale. Database built for serverless, featuring native GraphQL

#database #list

24. 1. 2020

Docker cleanup guide

Docker doesn't remove unused objects such as containers, images, volumes, and networks unless you explicitly tell it to do so. How To Remove them?

Removing All Unused Objects

Remove stopped containers, all dangling images, and all unused networks:

docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] 

You can also include all unused volumes, then add --volumes:

docker system prune --volumes

Docker Containers

docker container ls -a

Remove selected container

docker container rm [CONTAINER ID]

Remove all stopped containers

To remove all stopped containers use:

docker container prune

You can also list what will be removed:

docker container ls -a --filter status=exited --filter status=created 

Stop and remove all containers

docker container stop $(docker container ls -aq)
docker container rm $(docker container ls -aq)

Docker Images

You can list them:

docker image ls

Remove selected image

docker image rm [IMAGE ID]

Remove dangling images

A dangling image is an image that is not tagged and is not used by any container. You can remove them by:

docker image prune

Remove all unused images

To remove all images which are not referenced by any existing container, not just the dangling ones, use the prune command with the -a flag:

docker image prune -a

Docker Networks

You can list them with:

docker network ls

Remove selected network

docker network rm [NETWORK ID]

Remove all unused networks

Use the docker network prune command to remove all unused networks.

Remove all networks that are created more than 12 hours ago:

docker network prune -a --filter "until=12h"

Docker Volumes

docker volume ls

Remove selected Volume

docker volume rm [VOLUME NAME]

Remove all unused volumes

docker volume prune

#Docker

22. 12. 2019

Muffiny

Promíchat a přidat mouk. Podle potřeby - hustoty těsta, dolít mléko.

2 velká oloupaná jablka na kostky, přimíchat k těstu, plnit košíčky.

Před pečením posypat směsí lžíce cukru krystal + lžičky skořice.

180°C, cca 25 minut

#Recepty #Pečení

6. 12. 2019

Create image slideshow with FFMPEG

Following will take all *.jpg images from current folder and create mp4 image slideshow. Images can have different sizes, ffmpeg will rescale or pad them.

ffmpeg -framerate 1/3 \
       -pattern_type glob -i '*.jpg' \
       -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1" \
       -c:v libx264 -crf 14 -r 25 -pix_fmt yuv422p \
       output.mp4

With background music:

ffmpeg -framerate 1/3 \
       -pattern_type glob -i '*.jpg' \
       -i audiofile.mp3 \
       -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1" \
       -c:v libx264 -crf 14 -r 25 -pix_fmt yuv422p \
       -shortest \
       output.mp4

#bash #ffmpeg

27. 11. 2019

Convert MYSQL HEX to string with PHP

Hexadecimal literal values are written using X'string' or 0xstring notation, where string contains hexadecimal digits (0..9, A..F).

SELECT HEX('EXAMPLE'), X'4558414D504C45';
+----------------+-------------------+
| HEX('EXAMPLE') | X'4558414D504C45' |
+----------------+-------------------+
| 4558414D504C45 | EXAMPLE           |
+----------------+-------------------+

You can also transform this value HEX value also with PHP instead of SELECT *, HEX(column) as column_name ... SQL.

<?php
function hexToString($hex) {
    $string = '';
    for ($i = 0; $i < strlen($hex); $i++) {
        $string .= dechex(ord($hex[$i]));
    }
    return $string;
}

Inserting string to the table will be easy just "INSERT INTO table (column) VALUES HEX(?)" or with Hexadecimal Literal string starting with 0x or X'string'.

#PHP #mysql

24. 10. 2019

Install Arduino on Raspberry PI

  1. Download https://www.arduino.cc/en/Main/software (Linux ARM 64 bit)
  2. Untar sudo tar xvJf ~/Downloads/arduino-1.8.9-linux64.tar.xz -C /opt
  3. Install sudo -E /opt/arduino-1.8.9/install.sh

Now, you have to add the Debian 10 login user to the dialout, tty, uucp and plugdev group. Otherwise, you won’t be able to upload your Arduino code to the Arduino microcontroller.

sudo usermod -aG dialout $(whoami)
sudo usermod -aG tty $(whoami)
sudo usermod -aG uucp $(whoami)
sudo usermod -aG plugdev $(whoami)
sudo reboot

#Raspberry #iot

15. 10. 2019

Subreddit Image Downloader

Subreddit downoader is a bash script which:

#!/usr/bin/env bash

###############################################################################
# Config
###############################################################################

# default subreddit=catpictures :)
subreddit=${1-catpictures} && json=${subreddit}

# default dir=<subreddit name>
dir=`realpath ${2-${subreddit}}` && mkdir -p ${dir}

# default page=1
pages=${3-1} 

###############################################################################
# Downloading images
###############################################################################

printf "Download all subreddit \e[1;31m/r/${subreddit}\e[m images to \e[1;31m${dir}\e[m\n"

for i in $(seq ${pages});
do

    # download subreddit json file
    curl -sS "https://www.reddit.com/r/${subreddit}.json?limit=100&after=${after}" -A 'random' | json_pp -json_opt utf8,pretty > ${dir}/${json}.json

    printf "\e[1;35mProcessing data from ${dir}/${json}.json\e[m\n"

    images=$(cat ${dir}/${json}.json | jq -r ".data.children[].data.preview.images[0].source.url" | egrep '\.jpg|\.png|\.gif' )

    # download all images from file
    for img in ${images}
    do
        # getting filename from URL
        file=${img##*/} && file=${file%\?*}

        # Download only new images
        if [[ ! -f "${dir}/${file}" ]]; then
            printf "\e[1;90m- ${file}\e[m\n"
            curl -sS -A 'random' "${img//&amp;/&}" -o ${dir}/${file} &
        fi
    done;

    # go to next page
    after=$(cat ${dir}/${json}.json | jq -r ".data.after") && json=${after}

    if [[ ${after} == "" ]]; then
        break # not have any after pages
    fi

done;

###############################################################################
# Cleanup
###############################################################################

rm ${dir}/*.json

wait #wait for all background jobs to terminate

Usage

./subreddit-download.sh <subreddit name> <directory> <pages>

Download all images from catpictures subreddit:

./subreddit-download.sh catpictures ./catpictures 5

Requirements

Source code: https://github.com/OzzyCzech/subreddit-image-downloader

#bash #redddit #curl

11. 10. 2019

Fix casks with depends_on that reference pre-Mavericks

If you get an error of the type **Error: Cask 'xxx' definition is invalid: invalid 'depends_on macos' value: ":mountain_lion", where hex-fiend-beta can be any cask name, and :mountain_lion any macOS release name, run the following command:

/usr/bin/find "$(brew --prefix)/Caskroom/"*'/.metadata' -type f -name '*.rb' -print0 \
| /usr/bin/xargs -0 /usr/bin/perl -i -pe 's/depends_on macos: \[.*?\]//gsm;s/depends_on macos: .*//g'

#macOS #brew #Catalina