Skip to content

Instantly share code, notes, and snippets.

View stevesimmons's full-sized avatar

Steve Simmons stevesimmons

  • Sikoia Limited
  • Amsterdam and London
View GitHub Profile
@smurfix
smurfix / wrap.py
Last active February 14, 2024 18:15
Trio: results-gathering nursery wrapper
#!/usr/bin/python3
import trio
import outcome
from contextlib import asynccontextmanager
class StreamResultsNursery:
def __init__(self, max_buffer_size=1):
self.nursery = trio.open_nursery()
self.max_buffer_size = max_buffer_size
@simonw
simonw / vc__handler__python.py
Last active May 5, 2024 08:06
How Vercel serves Python applications - discovered using the new "vercel build" command
import sys
import base64
import json
import inspect
from importlib import util
from http.server import BaseHTTPRequestHandler
# Import relative path https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
__vc_spec = util.spec_from_file_location("index", "./index.py")
__vc_module = util.module_from_spec(__vc_spec)
@sneakers-the-rat
sneakers-the-rat / clean_pdf.sh
Last active June 24, 2024 18:18
Strip PDF Metadata
# --------------------------------------------------------------------
# Recursively find pdfs from the directory given as the first argument,
# otherwise search the current directory.
# Use exiftool and qpdf (both must be installed and locatable on $PATH)
# to strip all top-level metadata from PDFs.
#
# Note - This only removes file-level metadata, not any metadata
# in embedded images, etc.
#
# Code is provided as-is, I take no responsibility for its use,
@stevesimmons
stevesimmons / bloomfilter.py
Last active October 25, 2020 21:54
Python bloomfilter accelerated by numba
import base64
import math
import random
import timeit
from typing import List, Optional
import numba
import numpy as np
class BloomFilter:
@kissgyorgy
kissgyorgy / listen.py
Created September 4, 2020 16:37
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;")
@AnatomicJC
AnatomicJC / android-backup-apk-and-datas.md
Last active July 16, 2024 05:43
Backup android app, data included, no root needed, with adb

Backup android app, data included, no root needed, with adb

Note: This gist may be outdated, thanks to all contributors in comments.

adb is the Android CLI tool with which you can interact with your android device, from your PC

You must enable developer mode (tap 7 times on the build version in parameters) and install adb on your PC.

Don't hesitate to read comments, there is useful tips, thanks guys for this !

@danmou
danmou / onenote_export.py
Last active May 29, 2024 10:13
Onenote export to HTML. NOTE: This script is now maintained at https://github.com/Danmou/onenote_export
### README
# This Python scripts exports all the OneNote notebooks linked to your Microsoft account to HTML files.
## Output
# The notebooks will each become a subdirectory of the `output` folder, with further subdirectories
# for the sections within each notebook and the pages within each section. Each page is a directory
# containing the HTML file `main.html` and two directories `images` and `attachments` (if necessary)
# for the images and attachments. Any sub-pages will be subdirectories within this one.
## Setup