Skip to content

Instantly share code, notes, and snippets.

View lsevero's full-sized avatar

Lucas Severo lsevero

  • São Paulo, Brazil
View GitHub Profile
@lsevero
lsevero / listen.py
Created January 8, 2021 14:13 — forked from kissgyorgy/listen.py
How to use PostgreSQL's LISTEN/NOTIFY as a simple message queue with psycopg2 and asyncio
import asyncio
import psycopg2
# dbname should be the same for the notifying process
conn = psycopg2.connect(host="localhost", dbname="example", user="example", password="example")
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cursor = conn.cursor()
cursor.execute(f"LISTEN match_updates;")
@lsevero
lsevero / airflow_eg.py
Created April 29, 2021 22:03 — forked from abridgett/airflow_eg.py
airflow XCOM notification example
MAP_SLACK_ATTACHMENTS = [
{
"fallback": "{{params.map}} {{ task_instance.xcom_pull(task_ids=params.map, key='slack_status') }}",
"pretext": "{{params.map}} update {{ task_instance.xcom_pull(task_ids=params.map, key='slack_status') }}",
"fields": [
{
"title": "Copied",
"value": "{{ task_instance.xcom_pull(task_ids=params.map, key='copied') }}",
"short": True
}
@lsevero
lsevero / run_in_executor.py
Created September 23, 2021 02:38 — forked from ddelange/executor.py
Make a sync function async
import asyncio
from functools import wraps, partial
def run_in_executor(fn=None, *, executor=None):
"""Make a sync function async. By default uses ThreadPoolExecutor."""
if fn is None:
# allow using this decorator with brackets, e.g.
# @run_in_executor(executor=ThreadPoolExecutor(1))
return partial(run_in_executor, executor=executor)
@lsevero
lsevero / GPG and git on macOS.md
Created November 17, 2021 15:48 — forked from danieleggert/GPG and git on macOS.md
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys
@lsevero
lsevero / diff_side_by_side.py
Created May 8, 2024 21:05 — forked from jlumbroso/diff_side_by_side.py
Side-by-Side Diff Comparison in Python
# Code licensed LGPLv3 by Jérémie Lumbroso <[email protected]>
import difflib
import itertools
import textwrap
import typing
def side_by_side(
left: typing.List[str],