blog.udartsev.ru


GOLANG - go.sum (fix)

Delete conflict package sums:

sed '/^github.com\/hyperledger\/fabric v1.4.4/d' ./go.sum > temp.txt && mv temp.txt go.sum

DOCKER - Powerfull comands


[CONTAINERS] ПОИСК КОНТЕЙНЕРОВ:

docker ps -a $(docker ps -a -f "since=b2f3a7899d6d" -q) 
  • since= все контейнеры ПОСЛЕ
  • before= все контейнеры ДО
  • -q вернуть только ID контейнеров

[CONTAINERS] УДАЛИТЬ ВСЕ КОНТЕЙНЕРЫ:

docker rm -f $(docker ps -a -q)

[CONTAINERS] УДАЛИТЬ КОНТЕЙНЕР С ПРЕФИКСОМ В ИМЕНИ = cli:

docker rm -f $(docker ps -a -f "name=cli" -q)

[CONTAINERS] ЗАЙТИ В КОНТЕЙНЕР С ПРЕФИКСОМ В ИМЕНИ = cli:

docker exec -ti $(docker ps -a -f "name=cli" -q) bash
peer chaincode list --installed
peer channel list

[IMAGES] УДАЛИТЬ ВСЕ IMAGES:

docker image rm -f $(docker images -a -q)

[IMAGES]УДАЛИТЬ IMAGES (поиск):

docker image rm $(docker image ls -f "since=b2f3a7899d6d" -q) 

[VOLUMES] УДАЛИТЬ ВСЕ UNUSED VOLUMES:

docker volume prune

[VOLUMES]УДАЛИТЬ ВСЕ VOLUMES:

docker volume rm $(docker volume ls -q)

[GLOBAL] ОЧИСТА ОТ НЕИСПОЛЬЗУЕМЫХ КОНТЕЙНЕРОВ, IMAGES и VOLUMES:

docker system prune

[NETWORKS] СПИСОК ВСЕХ NETWORKS:

docker network ls

[CONTAINERS] ИНФОРМАЦИЯ О КОНТЕЙНЕРЕ:

docker inspect -f 25942aa05b32

[CONTAINERS] ПОЛУЧИТЬ IP КОНТЕЙНЕРА:

docker inspect -f '{{range.NetworkSettings.Networks}}{{.Aliases}} | {{.IPAddress}}{{end}}' 25942aa05b32

[CONTAINERS] ПОИСК КОТЕЙНЕРА ПО IP

docker inspect -f '{{range.NetworkSettings.Networks}}{{.Aliases}} {{.IPAddress}}{{end}}' $(docker ps -q) | grep 172.20.0.20

[IMAGES] ФИЛЬТР IMAGES:

docker images --filter "<option>=<value>"
docker image ls --filter "<option>=<value>"

docker image ls --filter "reference=hyperledger/fabric-peer:crypto-pro"

“–filter” options:

  • reference : that can be used in order to isolate images having a certain name or tag;

  • before : to filter images created “before” a specific point in time;

  • since: to filter images since a specific point in time (usually another image creation);

  • label: if you used the LABEL instruction to create metadata for your image you can filter them later with this key;

  • dangling: in order to isolate images that are not used anymore.


DJANGO - ORM lookup classees

**Django 3.***

Доступные подклассы для выборки запросов типа:
"user_name__icontains"
"user_name__iregex"
"user_name__startswith"
django.db.models.query_utils :
  'contained_by':     <class 'django.contrib.postgres.fields.ranges.RangeContainedBy'>,
  'gte':              <class 'django.db.models.lookups.IntegerGreaterThanOrEqual'>,
  'lt':               <class 'django.db.models.lookups.IntegerLessThan'>,
  'contains':         <class 'django.db.models.lookups.Contains'>,
  'endswith':         <class 'django.db.models.lookups.EndsWith'>,
  'exact':            <class 'django.db.models.lookups.Exact'>,
  'gt':               <class 'django.db.models.lookups.GreaterThan'>,
  'gte':              <class 'django.db.models.lookups.GreaterThanOrEqual'>,
  'icontains':        <class 'django.db.models.lookups.IContains'>,
  'iendswith':        <class 'django.db.models.lookups.IEndsWith'>,
  'iexact':           <class 'django.db.models.lookups.IExact'>,
  'in':               <class 'django.db.models.lookups.In'>,
  'iregex':           <class 'django.db.models.lookups.IRegex'>,
  'isnull':           <class 'django.db.models.lookups.IsNull'>,
  'istartswith':      <class 'django.db.models.lookups.IStartsWith'>,
  'lt':               <class 'django.db.models.lookups.LessThan'>,
  'lte':              <class 'django.db.models.lookups.LessThanOrEqual'>,
  'range':            <class 'django.db.models.lookups.Range'>,
  'regex':            <class 'django.db.models.lookups.Regex'>,
  'startswith':       <class 'django.db.models.lookups.StartsWith'>,

SUBLIME - Anaconda plugin

SublimeText3 Anaconda (Python plugin)

https://sublime-text.zeef.com/zeefcom Anaconda config:

{ "pep8_ignore": [
    "E501",
    "E402",
    "UnusedImport",
    "W291",
    "E722",
  "E111"
    ] ,
  "pyflakes_explicit_ignore": [
    "UnusedImport",
    ],
  "auto_formatting": true,
  "autoformat_ignore":
    [
        "E309",
        "E501",        
    ],
  "auto_complete": true,
  "auto_complete_commit_on_tab": true,
}

PYTHON - Remove commented lines from .py code files

1. Create clear.sh file with:

#!/bin/sh
FILES=$(find . -name "*.py" -not -path "./env/*")
for FILE in $FILES
    do
        sed '/""".*"""/d;s/#.*$//;s/^\n$/\n/' $FILE > temp.txt && mv temp.txt $FILE
        echo "Processed file: $FILE"
    done
exit 0

2. Copy in in /your_project_root_foder/ and run:

    sh clear.sh

Ubuntu Linux - 3+more monitors Artifacts fix

Ubuntu Monitor Artifacts FIX

1. Change GRUB config file:

    gedit /etc/default/grub

Changed this line:

GRUB_CMDLINE_LINUX=""

to this:

GRUB_CMDLINE_LINUX="amd_iommu=on iommu=pt"

then:

sudo update-grub && sudo reboot

2. Update kernel iniframs:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git
cd linux-firmware/
sudo cp -va amdgpu/ /lib/firmware/
sudo update-initramfs -u
reboot

SSH key to server

SSH => server

Create a key:

ssh-keygen -t rsa

Copy it to the server:

ssh-copy-id -i ./mainserver.pub archive@5.45.79.2

OR

ssh archive@5.45.79.2 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

cat ./mainserver.pub | ssh archive@5.45.79.2 'cat >> .ssh/authorized_keys'

OR

ssh -i /root/.ssh/mainserver.pub archive@5.45.79.2

NODE.JS REACT clean start

Install Node 12:

sudo apt update
sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

sudo apt -y install nodejs
sudo apt -y  install gcc g++ make

$ node --version
v12.10.0

$ npm --version
6.10.3


rm -f package-lock.json
sudo npm install
sudo npm audit fix
sudo npm run build

DJANGO - clean run

1) Install requirements.txt

pip install -r requirements.txt
(same: cat requirements.txt | xargs -n 1 pip install)

2) Create migrations:

python manage.py makemigrations
python manage.py migrate

3) Make seeds:

python manage.py seed all
python manage.py seed all --refresh

Superuser:

admin
admin (or `SUPERUSER_PASS={password}` in env)

Django template error fix:

first install: pip install django==2.2 then install: pip install django==3.0.2

Install Python 3.9

sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.9
python3.9 --version

Installing ENV (linux):

sudo apt install python3.9-venv
python3.9 -m pip install --user --upgrade pip
python3.9 -m pip install --user virtualenv
python3.9 -m venv env
source env/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install --upgrade -r requirements.txt  # upgrade all packages
deactivate

Update ENV and requirements.txt (linux)

pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
pip freeze > requirements.txt

pip install pipupgrade
pipupgrade --verbose --latest --yes
pip freeze > requirements.txt

LINUX BASH

1) Deletes all DJANGO migrations:

cd {django-project-folder}/
find . -path "*/migrations/*.py" -not -name "__init__.py" -not -path "*/geodata/*" -delete
find . -path "*/migrations/*.pyc" -not -path "*/geodata/*" -delete

CELERY ON LOCALHOST

celery -A core_backend worker --loglevel=DEBUG

REDIS RESVER 6+

sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-server

ERRORS:

https://github.com/django/daphne/issues/262 https://stackoverflow.com/questions/55916808/django-channels-reader-at-end-of-file-exception


PostgreSQL - Run server on startup (Linux)

1) Check your chmod file available:

sudo chmod +x /etc/rc.local

2) Edit rc.local file:

sudo gedit /etc/rc.local

3) Add:

# PostgreSQL
mkdir /var/run/postgresql
mkdir /var/run/postgresql/12-main.pg_stat_tmp
touch /var/run/postgresql/12-main.pg_stat_tmp/global.tmp
chown -R postgres:postgres /var/run/postgresql
su postgres -c '/usr/lib/postgresql/12/bin/pg_ctl start -D /etc/postgresql/12/main'

# OR CHANGE YOUR DB VERSION AND DATABASE FILES FOLDER
# su postgres -c '/usr/lib/postgresql/9.5/bin/pg_ctl start -D /etc/postgresql/9.5/main'

4) Enable rc.local instructions (it is turned off by default):

sudo systemctl enable rc-local.service

5) Start your rc.local scripts right now:

sudo systemctl start  rc-local.service