Skip to content

Instantly share code, notes, and snippets.

View joeblackwaslike's full-sized avatar
💭
Working hard

Joe Black joeblackwaslike

💭
Working hard
View GitHub Profile
@joeblackwaslike
joeblackwaslike / 1-README.md
Created April 8, 2022 17:41
Quart Advanced Dependency Injection POC

Quart Advanced Dependency Injection POC

Instructions:

$ python -m venv venv
$ source venv/bin/activate
$ python -m pip install anyio di pydantic quart
$ python poc.py
@joeblackwaslike
joeblackwaslike / 1-README.md
Last active April 7, 2022 14:52
MacOS LaunchDaemon plist for TCP service thats launched on demand when socket is connected to

MacOS LaunchDaemon plist for TCP service thats launched on demand when socket is connected to

This service isn't started at launch, which is by design. The command being launched establishes a tunnel to a virtual machine running on the host using UTM.app. I created a LoginItem that launches the virtual machine at startup using UTM's registered URI handlers. By starting these tunnels lazily, we are able to connect at a time after the virtual machine has already booted and able to be reached on the network. Trying to do this at startup would result in a failure to connect.

Instructions

  1. Ensure ssh is configured on the remote machine, you've generated an ssh key and you've copied that ssh key to the remote host.
  2. Replace {{ path_to_public_key }} with the full path to the ssh key you generated in step 1.
  3. Replace {{ remote_user }} with your username on the remote machine.
  4. Replace {{ remote_host }} with the remote hostname or ip address (for virtual machines this will probably be an ip add
"""
This script demonstrates the use of nested transactions in SQLAlchemy, including
a workaround for an issue with the SQLite backend.
References:
http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#using-savepoint
http://docs.sqlalchemy.org/en/latest/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl
"""
from sqlalchemy import Column, String, Integer
@joeblackwaslike
joeblackwaslike / run_coroutine_in_another_thread.py
Created February 12, 2022 23:17 — forked from lars-tiede/run_coroutine_in_another_thread.py
Safely run a coroutine in another thread's asyncio loop and return the result
import threading
import asyncio
async def run_coro_threadsafe(self, coro, other_loop, our_loop = None):
"""Schedules coro in other_loop, awaits until coro has run and returns
its result.
"""
loop = our_loop or asyncio.get_event_loop()
# schedule coro safely in other_loop, get a concurrent.future back
@joeblackwaslike
joeblackwaslike / sitecustomize.py
Created February 7, 2022 19:33
Debugging utils for sitepython
import code, traceback, signal
def debug(sig, frame):
"""Interrupt running process, and provide a python prompt for
interactive debugging."""
d={'_frame':frame} # Allow access to frame object.
d.update(frame.f_globals) # Unless shadowed by global
d.update(frame.f_locals)
i = code.InteractiveConsole(d)
@joeblackwaslike
joeblackwaslike / RainbowDoge.md
Last active February 7, 2022 18:53
Rainbow Doge

Rainbow Doge

Imgur

Instructions

  1. Install lolcat:
    $ brew install lolcat
  2. Add the shell code to the end of your ~/.zprofile file
@joeblackwaslike
joeblackwaslike / find_common_ancestor.py
Created July 17, 2020 19:16
Find Common Ancestors
"""
PROBLEM
Suppose we have some input data describing a graph of relationships between
parents and children over multiple generations. The data is formatted as a
list of (parent, child) pairs, where each individual is assigned a unique
integer identifier.
For example, in this diagram, 6 and 8 have common ancestors of 4 and 14.