Skip to content

Instantly share code, notes, and snippets.

def a_long_function():
    ... # do some stuff
    # Something is broken around here, we want to poke around, so we add this:
    import pdb;pdb.set_trace()
    ... # other stuff

When we run the code, it stops at the import pdb;pdb.set_trace() and gives us control over the program. We can rewrite the code as its executing!

@jacksmith15
jacksmith15 / app.py
Created August 10, 2020 11:07
faust-component-test.py
from random import randint
import faust
from simple_settings import settings
app = faust.App(**settings.FAUST)
source_topic = app.topic("source", value_type=int)
@jacksmith15
jacksmith15 / _usage.py
Last active January 10, 2023 00:47
Redis wrapper leveraging pydantic models for a clean (and very strict) interface. Requires data structures be consistent for each database.
from typing import AsyncIterator
from pydantic import BaseModel
from radish import RedisInterface, Database
class User(BaseModel):
id: int
name: str
"""Very rough solution to problem posed @gecBurton.
https://gist.github.com/gecBurton/9b74f005d715317f70bb61528f05b29a
"""
from collections import defaultdict
from typing import Any, Dict, List
INDENT = " "
"""A set of helpers for reversing urls, similar to Django ``reverse``.
Usage:
.. code:: python
@router.get("/class/{class_id}")
async def get_class(request: Request, class_id: int = Path(...)):
student_route = get_route(request.app, "list_students")
class_students_url = URLFactory(student_route).get_path(class_id=class_id)
"""This module implements a parser for query strings encoded with Ruby RestClient:
https://www.rubydoc.info/gems/rest-client/RestClient%2FUtils.encode_query_string
"""
import re
from urllib.parse import unquote
class ParameterTypeError(Exception):
"""Exception for mixed parameter types."""
@jacksmith15
jacksmith15 / searchable_dict.py
Last active January 18, 2021 15:47
Searchable dictionary, allowing fast substring matching on keys.
"""Searchable dictionary, allowing fast substring matching on keys.
Requires:
- Python 3.8 or greater
- pytrie 0.4.0 or greater
Example:
>>> dictionary = SearchableDict({
... "foo bar": 1,

OpenAPI Combinator

Web app which combines OpenAPI specifications into a single specification.

Requirements:

fastapi ~= 0.63.0
httpx ~= 0.16.1
aiocache ~= 0.11.1
@jacksmith15
jacksmith15 / README.md
Last active April 11, 2022 16:14
k3s for local testing

K3s for local testing/CI

The following is a docker-compose k3s configuration, with a script to pre-populate images in the cluster, allowing complete tear-down and rebuild very quickly.

This could be useful for spinning up a small cluster during CI jobs, as it allows the images to be cached rather than pulled into the newly built cluster for each and every job.

Results from local testing:

| | No preloaded images | Preloaded images |

@jacksmith15
jacksmith15 / README.md
Last active December 21, 2021 10:51
Command-line log streaming from Elastic.

Logs

Stream logs from Elasticsearch to stdout.

Requirements

Python 3.8 or higher

pip install python-dateutil==2.8.2 fire==0.4.0 requests==2.26.0