Skip to content

Instantly share code, notes, and snippets.

@polozhevets
polozhevets / neo4j_async.py
Last active June 17, 2020 13:04
Asynchronous wrapper for Official Neo4j driver for Python
# Neo4j async
from neo4j import GraphDatabase
from neo4j.exceptions import ServiceUnavailable
import logging
import asyncio
NEO4J_HOST = 'localhost'
NEO4J_USER = 'neo4j'
@polozhevets
polozhevets / install_python37.sh
Created August 22, 2019 13:29
Install Python 3.7 Ubuntu 18.04 (bionic)
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
sudo tar xzf Python-3.7.4.tgz
cd Python-3.7.4
sudo ./configure --enable-optimizations
sudo make altinstall
python3.7 -V
@polozhevets
polozhevets / clone_model.py
Created July 10, 2019 12:51
Clone sqlalchemy model
def clone_model(model):
"""Clone an arbitrary sqlalchemy model object without its primary key values."""
# Ensure the model’s data is loaded before copying.
model.id
table = model.__table__
non_pk_columns = [k for k in table.columns.keys() if k not in table.primary_key]
data = {c: getattr(model, c) for c in non_pk_columns}
data.pop('id')
return data
@polozhevets
polozhevets / aesd.py
Last active August 22, 2022 12:43
Python Encode and Decode AES String+key
#!python3
import base64
import hashlib
from Crypto.Cipher import AES
from Crypto import Random
class AESCipher(object):
def __init__(self, key):
#! python3.7
from email.message import EmailMessage
import smtplib
from pathlib import Path
def send_simple_message(email, subject, html, from_subject="Company Name", bcc="", attachment=None):
from_address = 'no-reply@domain.com'
auth_user = ''
auth_password = ''
@polozhevets
polozhevets / responses.py
Last active November 14, 2018 07:42
Decorators with aiohttp response and some utils
import json
from bson import ObjectId
import datetime
from aiohttp import web
from aiohttp.client_exceptions import ClientConnectorError
import logging
from uuid import uuid4
import pandas as pd
from io import BytesIO
import hashlib