Skip to content

Instantly share code, notes, and snippets.

@kovalbogdan95
kovalbogdan95 / singleton.py
Created August 20, 2020 16:06
SQLAlchemy singleton model
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.exc import IntegrityError
from rates.extensions import db
class LoadSingleton:
@classmethod
def load(cls):
id_ = {"id": 1}
try:
@kovalbogdan95
kovalbogdan95 / send_email_with_gmail.py
Created February 21, 2020 20:45
Send email via Gmail smtp
import smtplib, ssl
port = 587 # For starttls
smtp_server = "smtp.gmail.com"
sender_email = "my@gmail.com"
receiver_email = "your@gmail.com"
password = input("Type your password and press enter:")
message = """\
Subject: Hi there
@kovalbogdan95
kovalbogdan95 / theme.py
Last active February 5, 2020 01:59
Set random terminal profile on Ubuntu
#!/usr/bin/python3
# Credits to https://github.com/aruhier/gnome-terminal-colors-solarized
# Install ALL themes using this tool https://github.com/Mayccoll/Gogh
# You may nedd to install dconf - sudo apt-get install dconf-cli
import subprocess
import ast
import random
import os
@kovalbogdan95
kovalbogdan95 / concur.py
Created November 7, 2019 13:00
Python Threading example
from concurrent.futures import ThreadPoolExecutor
from time import sleep
def return_after_5_secs(message):
sleep(5)
return message
pool = ThreadPoolExecutor(3)
future = pool.submit(return_after_5_secs, ("hello"))
@kovalbogdan95
kovalbogdan95 / await_example.py
Created November 7, 2019 12:59
Asyncio example
import asyncio
import datetime
import random
async def my_sleep_func():
await asyncio.sleep(random.randint(0, 5))
async def display_date(num, loop):
@kovalbogdan95
kovalbogdan95 / scr.sh
Created November 7, 2019 12:55
Get run info inside bash script
#!/bin/bash
echo
echo "# arguments called with ----> ${@} "
echo "# \$1 ----------------------> $1 "
echo "# \$2 ----------------------> $2 "
echo "# path to me ---------------> ${0} "
echo "# parent path --------------> ${0%/*} "
echo "# my name ------------------> ${0##*/} "
echo
@kovalbogdan95
kovalbogdan95 / singleton_python.py
Last active October 29, 2019 14:20
Singletone examples in python
# One
class Singleton:
def __new__(cls, *args, **kwargs):
if not hasattr(cls, 'instance'):
cls.instance = super(Singleton, cls).__new__(cls)
return cls.instance
a = Singleton()
a.prop = "PROP"
@kovalbogdan95
kovalbogdan95 / smtp_python2.py
Created May 10, 2019 12:04
Send email using smtplib and python2
import smtplib
gmail_user = 'user'
gmail_password = 'password'
sent_from = gmail_user + '@gmail.com'
to = ['me@gmail.com', 'bill@gmail.com', 'user@gmail.com']
subject = 'OMG Super Important Message'
body = 'Hey, what"s up?\n\n- You'
@kovalbogdan95
kovalbogdan95 / yggdrasil-scanner.py
Last active May 10, 2019 12:01
Yggdrasil network scanning for active hosts with 80 open port
#! /usr/bin/python3
# -*- coding: utf-8 -*-
from urllib.request import urlopen
import re
import os
import subprocess
#ipv6
regex = r"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-" \
@kovalbogdan95
kovalbogdan95 / fabfile.py
Created May 10, 2019 11:13
Fabric script to run command on several hosts
# pip3 install fabric3==1.14.post1
# Usage: fab cmd:'whoami'
from fabric.api import *
env.hosts = [
'pi@192.168.0.111',
'pi@192.168.0.112',
'pi@192.168.0.113',
]