Skip to content

Instantly share code, notes, and snippets.

View michaeloliverx's full-sized avatar
🏠
Working from home

Michael Oliver michaeloliverx

🏠
Working from home
View GitHub Profile
@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@betrcode
betrcode / README.md
Created June 24, 2014 06:36
Using Python to check if remote port is open and accessible.
@kissgyorgy
kissgyorgy / sqlalchemy_conftest.py
Last active June 26, 2024 20:01
Python: py.test fixture for SQLAlchemy test in a transaction, create tables only once!
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from myapp.models import BaseModel
import pytest
@pytest.fixture(scope="session")
def engine():
return create_engine("postgresql://localhost/test_database")
@ygotthilf
ygotthilf / jwtRS256.sh
Last active June 27, 2024 16:13
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@Hammer2900
Hammer2900 / download_multiple.py
Created September 28, 2016 17:51 — forked from harrisont/download_multiple.py
Use asyncio and aiohttp to asynchronously download multiple files at once and handle the responses as they finish
import asyncio
from contextlib import closing
import aiohttp
async def download_file(session: aiohttp.ClientSession, url: str):
async with session.get(url) as response:
assert response.status == 200
# For large files use response.content.read(chunk_size) instead.
@jasco
jasco / README.md
Last active April 18, 2024 18:07
Workaround for SqlAlchemy Alembic Migrations

Dialect specific migration with Alembic

DDL

Certain SQL dialect specific SQL including triggers and stored procedures are not abstracted away by SqlAlchemy. In those cases SqlAlchemy provides a DDL interface that can be connected to events that conditionally trigger the appropriate dialect specific code.

ddl = sqlalchemy.DDL(custom_pg_trigger)

@Tarliton
Tarliton / async_sqlalchemy_thread.py
Last active February 26, 2023 13:07
asyncio with a thread executor and sqlalchemy
import asyncio
import base64
import os
import random
from sqlalchemy import Column, Integer, String
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker, declarative_base
# SQLAlchemy==2.0.4
@Integralist
Integralist / Python Async Decorator.py
Last active June 30, 2024 09:22
[Python Async Decorator] #python #asyncio #decorator
import asyncio
from functools import wraps
def dec(fn):
@wraps(fn)
async def wrapper(*args, **kwargs):
print(fn, args, kwargs) # <function foo at 0x10952d598> () {}
await asyncio.sleep(5)
@nitred
nitred / db_manager.py
Last active January 19, 2024 10:09
Creating thread safe and managed sessions using SQLAlchemy
"""Creating thread safe and managed sessions using SQLAlchemy.
The sessions that are created are expected to be:
- thread safe
- handle committing
- handle rolling back on errors
- handle session removal/releasing once context or thread is closed.
Author: Nitish Reddy Koripalli
License: MIT
@dmfigol
dmfigol / asyncio_loop_in_thread.py
Last active June 30, 2024 09:29
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable