2021-07-06

AWS - Amazon Web Services - notes

AWS - Amazon Web Services - notes

My unsorted notes about AWS


AWS general xroad

Home

Console

* console FFT Frankfurt

CLI

Sign in

Trainings all

Trainings and Certifications blog post

aws.training site


10 miutes tutorials crossroad

10 min tut xroad

WordPress, ServerLess, React, Linux VM, MySQL, Static S3, PostgreSQL


Popular AWS - services crossroads

Free Tier, Elastic Beanstalk, DynamoDB, RDS (Relational Database Service), CloudFront, Glacier


LightSail

 - servers and services management console

 -  easily setup your service

LightSail tutorials home

LightSail home page


EC2

- Elastic Compute Cloud

EC2 pricing

EC2 get started - LAMP, Elastic, WordPress, etc

* WordPress 10 min tut


S3

- Simple Storage Service

S3 home

S3 get started



Lambda

 - serverless computing

Lambda home

Lambda - get started - crossroad

Lambda - resources

Lambda - build basic web app

* Lambda - ServerLess web app tutorial

* ServerLess with Lambda, API GateWay, Amplify, DynamoDB, Cognito


2021-03-07

PostgreSQL intro

PostgreSQL :



psql CLI :

psql option dbname username

i.e. :


export PGPASSWORD=pg-pass

psql -h pg-host -U postgres


psql -c '\x' -c 'SELECT * FROM current_catalog;'


echo '\x \\ SELECT * FROM current_catalog;' | psql


psql <<EOF

\x

SELECT * FROM current_catalog ;

EOF


src: psql CLI doc



CLI FILES :

PasswordLess login:

Linux : ~/.pgpass - pg pass

Win :   %APPDATA%\postgresql\pgpass.conf

format: hostname:port:database:username:password

env :   set PGPASSFILE=C:\Program Files\someapp\pgpass.conf

note :  if env PGPASSWORD is set, ~/.pgpass is ignored

nopass: sleeplessbeastie

bash :  chmod u-x,go-rwx ~/.pgpass



CLI SWITCHES :

-c command

-d dbname

-h host

-U user

-W --password

-f command-input-file

-l == list all available databases

\x = toggle expanded table formatting mode

-o output-file.txt



CLI commands :

\l - Display database

\list

\c - Connect to database

\conninfo

\dn - List schemas

\dt - List tables inside public schemas

\dt schema1. - List tables inside particular schemas. For eg: 'schema1'.

stackexchange



Create table :

CREATE TABLE accounts (

user_id serial PRIMARY KEY,

username VARCHAR ( 50 ) UNIQUE NOT NULL,

password VARCHAR ( 50 ) NOT NULL,

email VARCHAR ( 255 ) UNIQUE NOT NULL,

created_on TIMESTAMP NOT NULL,

        last_login TIMESTAMP 

);

\d = list tables

\d accounts = describe table accounts

DROP TABLE accounts ;

CREATE SCHEMA myschema ;

CREATE TABLE myschema.mytable ... ;

DROP SCHEMA myschema ;

SELECT CURRENT_TIMESTAMP;

src: tutorialspoint

src: postgresqltutorial - M;N table relation



Show current info - session, user, schema, database :

SELECT current_database();

SELECT * FROM current_catalog;

SELECT current_catalog;


SHOW DateStyle;

SHOW search_path ;

SET search_path TO myschema ;


SELECT * FROM pg_stat_activity;

SELECT * 

FROM pg_stat_activity 

WHERE datname = 'dbname' 

 and state = 'active';

src: stackoverflow - stackoverflow



Postgres with Docker :

:: Start Postgres

docker run --rm --name mars-postgres -e POSTGRES_PASSWORD=pg-pass -d postgres

:: Create bridge

docker network create -d bridge mars_bridge_postgres

:: Connect already existing container to network

docker network connect mars_bridge_postgres mars-postgres


:: Disconnect container from network
docker network disconnect mars_bridge_postgres mars-postgres

:: Stop Postgres
docker container stop mars-postgres

:: Remove Docker network
docker network rm mars_bridge_postgres


:: CLI
@echo Pass is pg-pass
@rem PGPASSWORD=pg-pass
@rem docker run -it --rm --network mars_bridge_postgres postgres psql -h mars-postgres -U postgres
docker run -it --rm --network mars_bridge_postgres postgres bash -c "PGPASSWORD=pg-pass psql -h mars-postgres -U postgres"



PG tutorial :

https://www.tutorialspoint.com/postgresql/postgresql_quick_guide.htm

https://www.postgresqltutorial.com/


PG data types :

https://www.postgresqltutorial.com/postgresql-data-types/


Import CSV to SQL  in Postgre :

https://www.postgresqltutorial.com/import-csv-file-into-posgresql-table/


Export SQL to CSV from Postgre :

https://www.postgresqltutorial.com/export-postgresql-table-to-csv-file/


PG Admin :

https://www.pgadmin.org/

https://www.pgadmin.org/download/

2021-01-23

Git cheat sheet


Clone git repo

git clone https://github.com/user/project.git

git clone ssh://git@github.com/user/project.git

gh repo clone user/project




GitHub how to

Get started with GitHub

GitHub profile

GitHub email settings




Create new repo (add existing project to Git)

# Create also remote repository, i.e. create repo on GitHub

git init -b main # previously master, init.defaultBranch

echo "New project" > README.md

git add . # or: git commit -a

git commit -a -m "Initial commit"

git remote add origin https://github.com/user/project.git

git remote add origin git@github.com:username/project.git

git remote -v # verify

git push -u origin main # previously master

# configure default name of main branch:

git config --global init.defaultBranch main

see also:

Create new repo in GitHub (how to)

Add existing project to GitHub




Pull

git pull # update (fetch) from remote tracking upstream, merge into current branch

git pull origin # update from origin

git pull origin branch1 # update from origin, merge remote branch1 into current branch

# or:

git fetch origin

git merge origin/branch1

git pull –-all # fetch all remotes



Show branches

# local:

git branch -l

# remotes:

git branch -r

# all:

git branch -a  # remotes prefixed with "remotes/"

# current:

git branch --show-current

# branch parent:

git parent

# git parent alias in Windows Cmd:

git config --global alias.parent2 "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//' #"

src: stackoverflow

# git parent alias in Linux or Windows Git Bash:

git config --global alias.parent2 "!""git show-branch | grep '*' | grep -v \"\$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//' #"

src: stackoverflow

# creates following alias in ~/.gitconfig :

[alias]

    parent = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"



Switch to another git branch

# switch to and reset (-B) local branch or create new local :

git checkout -B branch1 origin/branch1

# switch to existing local branch:

git checkout branch1

# since git 2.23.0:

git switch branch1 origin/branch1



Clone/Create branch and switch into it

# create (-b) new branch1 from origin/master^0, checkout (optionally: --track, --no-track)

git checkout -b branch1 origin/master^0 --

More at StackOverflow



Push new local branch to remote

git push -u origin HEAD

git push -u origin refs/heads/branch1:branch1



Merge branch1 to master

git checkout origin/master

git merge origin/branch1

git push

git push origin HEAD

git push origin refs/heads/master:master



Merge remote branch1 into current branch

git pull origin branch1

git push



Merge Squash

git checkout origin/master

git merge --squash origin/branch1

git push



Merge without merge commit / avoid merge commit

git checkout origin/master

git merge --ff-only origin/branch1

git push

src: Q: stackoverflow

A: stackoverflow



Merge using Patch

git checkout feature

git diff main > feature.patch

git checkout main

patch -p1 < feature.patch

git add .

src: stackoverflow



Merge conflicts - resolve conflicts

# resolve conflicts:

vim file1.txt # resolve conflicts

git mergetool # resolve conflicts

# add (stage) resolved changes to index:

git add -A -f -- file1.txt # add (-A now equiv to ., including removal)

git add -u # add all modified (previously added)

# commit resolved changes:

git commit -a -m "commit message" # add and commit

git commit -F C:\git\project1\.git\MERGE_MSG --



Merge - resolve conflicts helpers

git status

git log --merges # print only merge commits

git diff

git checkout

git merge --abort

git reset

git mergetool # uses merge tool to resolve merge conflicts

git am --show-current-patch # see failed patch (from merge)

see: atlassian - merge conflicts



Merging strategies

ours

theirs

patience

octopus (?)

diff-algorithm

see: atlassian - merge strategy



Rebase

git checkout origin/branch1

git rebase origin/master

git add fixed_file.txt

git commit -m "fixed conflict"

git rebase --continue # skip, abort

git push --force



Rebase pull

git pull --rebase

Config:

git config branch.autoSetupRebase always

git config --global pull.rebase true

git config --global pull.rebase preserve # set up Git to automatically rebase upon pull

src: stackoverflow



# Change parent branch:

git rebase --onto origin/newBase



# Interactive rebase (squash, drop, ...)

git rebase --interactive origin/master

git rebase -i origin/master

# p, pick = use commit

# r, reword = use commit, but edit the commit message

# e, edit = use commit, but stop for amending

# s, squash = use commit, but meld into previous commit

# f, fixup = like "squash", but discard this commit's log message

# x, exec = run command (the rest of the line) using shell

# d, drop = remove commit

See more about Rebase



The Golden Rule of Rebasing

Never rebase public branches

# Rebase public branch – if ever:

git --fork-point



Undo git rebase

git reset --hard ORIG_HEAD # rebase saves start point


git reflog # find head commit before rebase

git reset --hard "HEAD@{2}"# reset to commit before rebase


# proper config:

git config core.logallrefupdates=true



Push

git push # Push to tracked/upstream/remote

git push origin branch1 # Push to branch1

git push -u origin branch1 # Push to branch1 and set upstream

git push -u origin local1:remote1 # push local1 to remote1 and set-upstream

See Push default



Push force

git push --force-with-lease

git push --force-with-lease origin X

src: stackoverflow

src: stackoverflow



Push tags

git push --tags # tags are not pushed automatically



Push all

git push --all # all branches



Delete branch

# Delete local:

git branch -d branch1

# Force delete local

git branch -D branch1

# Delete remote:

git push --delete origin/branch1

# SOLVED: fatal: --delete doesn't make sense without any refs

git push origin :branch1 # actually deletes branch1



Rename branch

git branch -m branch1 # rename current branch to branch1



Prune

# Delete local branches without remotes

git remote prune origin --dry-run # prunes tracking branches not on the remote

git fetch -p

git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done

Note: see differences between differences between git remote prune, git prune, git fetch --prune, etc



Git tag

# Tags are ref's pointing to git history. Types: 

# lightweight tags (absence of the -a, -s, -m), 

# annotated tags


# Lightweight tag (absence of the -a, -s, -m)

# Create a new tag checksum and store it in the .git/ of project's repo

git tag v1.4


# Annotated Tag

# full objects in the Git database (store the tagger name, email, and date)

git tag -a v1.4


# Add (commit-like) tag message:

git tag -a v1.4 -m "my version 1.4"


# List tags

git tag

git tag -l *-rc*


# Tag old commit

git log --pretty=oneline

git tag -a v1.2 commit-id


# fatal: tag 'v0.4' already exists => force

git tag -a --force v1.4 commit-id


# Push tag:

git push origin v1.4


# Checkout tag:

git checkout v1.4


# Delete tag:

git tag -d v1


# Prune tags:

git fetch --prune-tags

src: atlassian.com



Reset branch (move back in history)

# reset your branch to master and destroy changes:

git reset --hard origin/master

# reset your branch to master and keep changes as commited:

git reset --soft origin/master

# reset your branch to master and mixed (not added to index):

git reset --mixed origin/master

Reset Demystified



Commit References (move back in history)

HEAD~ and HEAD^

~ most of the time

^ on merge commits

*

Mnemo:

Tilde ~ is almost linear in appearance and wants to go backward in a straight line

Caret ^ suggests an interesting segment of a tree or a fork in the road

*

Order of Parent Commits

Show 89e4fcb0dd’s immediate parents in sequence:

git rev-parse 89e4fcb0dd^1 89e4fcb0dd^2 89e4fcb0dd^3

src: good article: stackoverflow



Cherry pick

# Syntax:

git cherry-pick commit-sha

# i.e.: you want to get f into Main:

    a - b - c - d   Main

         \

           e - f - g Feature

git checkout main

git cherry-pick f

Options

git cherry-pick -x f # generate standard commit message – keep track of origin of commit

   https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x

git cherry-pick --edit f # you can edit commit message

git cherry-pick --no-commit f # do cherry pick but do not commit and keep changes in working directory

git cherry-pick --signoff f # add signoff signature to end of cherry-pick commit message

git cherry-pick --abort --continue –quit # when solving conflicts

Copy notes attached to cherry pick:

git notes copy <from> <to>

src: atlassian: cherry-pick

https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean

example: https://stackoverflow.com/a/30218784

*

see also: atlassian: merge-strategy



Revert file

# remove untracked including ignored:

git clean -fd # remove untracked directories and untracked files

git clean -fX # remove only ignored files

git clean -fx # remove directories, ignored and non-ignored untracked files (include build target)

src: stackoverflow

answer: stackoverflow

-n, --dry-run # dry run

git clean -i # interactive

git add --all && git reset --hard HEAD

src: https://stackoverflow.com/a/37614185


# undo/revert local changes:

git reset --hard

git stash

git reset HEAD file1.txt # unstage to current commit

git checkout -- file1.txt

git checkout HEAD -- file1.txt


# revert (remove) uncommited file:

git rm --cached -f -- file1.txt

git reset file1.txt

See more at Revert all local changes



Stash

# simple:

git stash

git stash -u # include ignored and untracked

git stash pop


# name stash:

git stash save "my stash name"


# list

git stash list


# apply and keep

git stash apply stash@{0} # apply and keep

git stash pop # apply/pop and drop


# branch from stash

git stash branch branch1 stash@{2}


# view details

git stash show


# delete

git stash drop stash@{1}


# delete all

git stash clear



Git log

git log --oneline --decorate

git log --graph --oneline --decorate

git log --pretty=format:"%cn committed %h on %cd"

git log -3 # 3 lines

git log main..feature

git log --no-merges

git log -–merges

src: https://www.atlassian.com/git/tutorials/git-log

# Pretty format

git log --all --decorate --oneline -–graph # "A Dog" 

git config --global alias.adog "log --all --decorate --oneline --graph"

src stackoverflow.com



Ref log

# Show git commands history:

git reflog

git reflog --relative-date

git reflog --all

git reflog show

See more Many undo possibilities

See on Atlassian



Push default

git config --global push.default matching # old default behavior

git config --global push.default simple # new default behavior

See default git push

See push -u



Upstream config

# snippet of git config – refs remotes upstreams :

git config --local -–list | grep '^remote'

# remote and refspec def :

remote.origin.url=https://github.com/username/project.git

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

# branch master :

git config --list | grep "^branch"

branch.master.remote=origin

branch.master.merge=refs/heads/master

src: stackoverflow.com



Set branch upstream

# If you create new branch:

git checkout -b branch1 origin/branch1

# you have to set upstream branch during push:

git push -u origin HEAD

git branch -u origin/branch1 branch1

git push origin refs/heads/branch1:branch1 --set-upstream

git push origin refs/heads/branch1:branch1 -u

# updates git project config as :

branch.branch1.remote

branch.branch1.merge

# Config branch:

git config branch.master.remote origin

git config branch.master.merge refs/heads/master



Remote origin (add show update)

git remote add origin https://github.com/user/project.git

git remote show origin

git remote update

# Set remote URL (https or ssh)

git remote set-url origin https://github.com/username/project.git

git remote set-url origin git@github.com/username/project.git

# Check remotes / upstreams / origin / repo URLs

git remote -v

origin  https://github.com/username/project.git (fetch)

origin  https://github.com/username/project.git (push)

# Show Git remote URL

git config --get remote.origin.url



Parent branch - merge base

git merge-base branch2 branch3

git merge-base origin/main branch1

git reset $(git merge-base master $(git branch --show-current))

git show --summary `git merge-base foo master` # when was branch created

git log --first-parent



Git commands workflow

HEAD working tree, index, staging area:

Workspace is the directory tree of (source) files that you see and edit.

Index is a single, large, binary file in <baseOfRepo>/.git/index, which lists all files in the current branch, their sha1 checksums, time stamps and the file name -- it is not another directory with a copy of files in it.

Local repository is a hidden directory (.git) including an objects directory containing all versions of every file in the repo (local branches and copies of remote branches) as a compressed "blob" file.

src: stackoverflow

See: Git Branch, HEAD, Refs

See index, commit, repo



Git config - initial setup

https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup

*

git config --global user.name 'Jon Doe'

git config --global user.email 'jon.doe@github.com'

git config --global core.editor emacs

git config --global core.editor vim

git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

git config --global init.defaultBranch main

*

git config -l

git config --list [--local | --global | --system]

Git config - which config

git config --show-origin --list # show config origin

*

Git config - files

# source:

[path]/etc/gitconfig # system

~/.gitconfig or ~/.config/git/config # global

.git/config # repository



Git alias

git config --global alias.alias "!""git config -l | grep ^alias\\."

git config --global alias.configure "!""vi ~/.gitconfig"

src:

Atlassian aliases

Most useful aliases



CRLF:

git config core.autocrlf true

git config core.autocrlf false

git config core.autocrlf input

# src: stackoverflow.com



Different Git configs

git config --list                              # local: /.git/config - repo-specific

git config --global --list # global: /.gitconfig - user-specific

git config --system --list # system: $(prefix)/etc/gitconfig - system-wide

git config --global --edit # edit



Global proxy settings

git config --global http.proxy myproxy.com:8080


Global SSL verify

git config --global http.sslVerify "false"

git config --global --unset http.sslVerify


Project specific SSL verify

cd C:\git\my-project

git config http.sslVerify "false"

:: git config --unset http.sslVerify



Git template dir:

# ~/.config/git/config or ~/.gitconfig

[init]

    templateDir = ~/.config/git/template/



Relative Refs

# display the grandparent of HEAD:

git show HEAD~2

merge commits => more complicated

merge commints => more parents => more paths to follow


i.e. 3-way merge:

1. parent == main branch you merged into

2. parent == branch mentioned in git merge branchName

~ = follow first parent of merge commit

^ = follow different parent


i.e.: if HEAD is merge commit, display second parent of HEAD by:

git show HEAD^2


Combine into:

git show HEAD^2^1

it is: grandparent of HEAD (if merge commit) which is on the second parent.


Examples:

# Only list commits that are parent of the second parent of a merge commit

git log HEAD^2


# Remove the last 3 commits from the current branch

git reset HEAD~3


# Interactively rebase the last 3 commits on the current branch

git rebase -i HEAD~3


# get back before you ran git reset

git checkout HEAD@{1}

src: atlassian.com



SSH Keys

ssh-keygen -t rsa -b 4096 -C 'username@github.com'

details: https://stackoverflow.com/a/37075506

files: https://en.wikipedia.org/wiki/Ssh-keygen


Linux SSH Keys registration

cat > ~/.ssh/config <<EOF

Host vs-ssh.visualstudio.com

  IdentityFile ~/.ssh/id_rsa

EOF

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys




Sources

ProGit Book

Reset Demystified

git branch vs git checkout -b

track remote branch

IntelliJ Idea branches



Cheat sheets

Atlassian git cheat sheet page

GitHub cheat sheet

GitLab cheat sheet

Atlassian git advanced – crossroad

Rebase reset revert log hooks refs reflog



MarS: Git unplugged notes

2020-04-29

Daňová informační schránka

Nově pouze DIS+
Přístupná přes mojedane.cz nebo daneelektronicky.cz - Online finanční úřad - Seznam DIS+



Žádost o zřízení

Když už mám datovou schránku, tak už je DIS zřízená a já nemusím žádat (viz Jak se přihlásím do DIS)
Jinak vyplním Žádost o zřízení daňové informační schránky



Přihláška

Vyplním
Přihláška k nahlížení do daňové informační schránky
Potvrdím přihlášením do datové schránky.
Uložím si pracovní soubory, potvrzení, odeslaný soubor.
Čekám na výsledek, když jsem vyplnil telefon, tak odpověď přijde SMSkou.



Přihlásím se

Daňový portál - úvodní stránka
Přihlášení uživatele ke službám daňového portálu 1 nefunguje
Přihlášení uživatele ke službám daňového portálu 2 funguje



Pracuji

Daně elektronicky - špatný certifikát (etrzby.cz)



Zdroje, odkazy, reference

Jak se přihlásím do DIS
Přihlášení uživatele ke službám daňového portálu
Daňová informační schránka - obecné info
Dokumentace k DIS
Kontrola stavu podání (např. stavu žádosti, přihlášky)

2020-03-19

Gradle Maven install notes


Gradle Maven install notes



Intro

Gradle quick reference how to:
download
install
setup
test



Download

Go to manual installation
Or open direct Gradle download link - Windows, bin-only



Install

Unzip downloaded file gradle-6.2.2-bin.zip to your chosen target, i.e. to C:\software

In Windows Start menu search for and open:
Edit environment variables for your account

In User variables for user click New, fill in:
Variable name: GRADLE_HOME
Variable value: C:\software\gradle-6.2.2
Click OK.

Choose Variable PATH, click Edit (do not remove any existing content, click key End)
Append to Variable value: ;%GRADLE_HOME%\bin
Click OK.



Test

Open command prompt, run:
gradle -v
gradle -version



Notes

Changes will apply in newly opened applications and Command prompts.



Links

Gradle home

Installation Steps

Gradle releases

Getting started guide

Upgrade Gradle wrapper

Spring Boot JMS


Spring Boot JMS

Notes for building and running test Spring Boot JMS application with embedded ActiveMQ.



Clone, build

setlocal enableextensions
mkdir C:\dev\jms\
cd C:\dev\jms
git clone https://github.com/spring-guides/gs-messaging-jms.git
cd gs-messaging-jms
cd complete
mvn clean install



Run

C:\dev\jms\gs-messaging-jms\complete
java -jar target/gs-messaging-jms-0.1.0.jar



Resources

Spring Messaging JMS tutorial - main resource

git clone https://github.com/spring-guides/gs-messaging-jms.git


2020-03-18

Spring Boot Rabbit MQ


Content
Install Erlang
Install and setup Rabbit MQ
Create sample Spring Boot Rabbit MQ client/server application
Run the application



Install Erlang and Rabbit MQ
Install Erlang

Rabbit MQ download - crossroad
Rabbit MQ - Windows builds - all
Rabbit MQ Win64 installer - exe



Setup Rabbit MQ

cd C:\Program Files\RabbitMQ Server\rabbitmq_server-3.8.3\sbin

Start service (if not yet started):
rabbitmq-service start

Enable Web UI:
rabbitmq-plugins enable rabbitmq_management

Add user:
rabbitmqctl add_user Admin_UserName Admin_Password

Grant admin rights:
rabbitmqctl set_user_tags admin administrator

Open Web UI:
http://localhost:15672/

More details:
https://www.rabbitmq.com/management.html



Clone and build project

setlocal enableextensions
mkdir C:\dev\rabbitmq\
cd C:\dev\rabbitmq\
git clone https://github.com/spring-guides/gs-messaging-rabbitmq.git
cd gs-messaging-rabbitmq
mvn clean install
cd complete
java -jar target/messaging-rabbitmq-0.0.1-SNAPSHOT.jar



Run project

cd C:\dev\rabbitmq\gs-messaging-rabbitmq\complete
java -jar target/messaging-rabbitmq-0.0.1-SNAPSHOT.jar



Resources

git clone https://github.com/spring-guides/gs-messaging-rabbitmq.git

Config dir: %APPDATA%\RabbitMQ