Skip to content

Instantly share code, notes, and snippets.

View DjaPy's full-sized avatar
:octocat:
git

Sergey Ivanov DjaPy

:octocat:
git
  • Moscow
View GitHub Profile
@DjaPy
DjaPy / README.md
Created July 4, 2020 13:30 — forked from inklesspen/README.md
Fast and flexible unit tests with live Postgres databases and fixtures

(This gist is pretty old; I've written up my current approach to the Pyramid integration on this blog post, but that blog post doesn't go into the transactional management, so you may still find this useful.)

Fast and flexible unit tests with live Postgres databases and fixtures

I've created a Pyramid scaffold which integrates Alembic, a migration tool, with the standard SQLAlchemy scaffold. (It also configures the Mako template system, because I prefer Mako.)

I am also using PostgreSQL for my database. PostgreSQL supports nested transactions. This means I can setup the tables at the beginning of the test session, then start a transaction before each test happens and roll it back after the test; in turn, this means my tests operate in the same environment I expect to use in production, but they are also fast.

I based my approach on [sontek's blog post](http://sontek.net/blog/

def get_intersection_arrays(arr_1: list, arr_2: list) -> list:
st_1 = set(arr_1)
st_2 = set(arr_2)
return list(st_1 & st_2)
lst_1 = [1, 2, 3, 4, 5, 6]
lst_2 = [2, 4, 6, 8]
result_intersection = get_intersection_arrays(lst_1, lst_2)
print(result_intersection)
@DjaPy
DjaPy / mysql-docker.sh
Created January 14, 2020 05:03
Dump and restore data from/to mysql docker container.
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
# or
docker exec -i CONTAINER sh -c 'exec mysql -uroot -p"$MYSQLROOTPASSWORD" DATABASE' < /path/to/dump/sql/file/mys
@DjaPy
DjaPy / postgres-cheatsheet.md
Created May 10, 2019 20:05 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@DjaPy
DjaPy / dml.py
Last active November 30, 2018 04:21
Create distribution manager locker with python for redis.
import redis
import uuid
import time
import logging
CONN_SETTINGS = {
'host': 'localhost',
'port': 6379,
'db': 0,
}