Skip to content

Instantly share code, notes, and snippets.

"""Very rough solution to problem posed @gecBurton.
https://gist.github.com/gecBurton/9b74f005d715317f70bb61528f05b29a
"""
from collections import defaultdict
from typing import Any, Dict, List
INDENT = " "
@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
@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)
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!

EAFP vs LBYL

This illustrates the difference between EAFP (Easier to ask forgiveness than permission) vs LBYL (Look before you leap).

To illustrate, consider a function which gets a value from a dictionary by key, returning a default if not present. This is the function implemented in each style:

Look before you leap:

def get(dictionary, key, default):
 if key in dictionary:

Some examples of CSV operations in Python

Using standard library

The following uses the csv standard library, specifically DictReader, to parse a CSV as a list of dictionaries.

DictReader accepts the file handler, and automatically parses the header for the field names. It can then be iterated to get each row of the CSV. This happens lazily by default, but since we want the whole thing, we load it into a list (which means we can let the file close.

import csv
@jacksmith15
jacksmith15 / type-annotations.md
Last active September 23, 2022 15:12
Type annotations 101

Type Annotations

Full documentation is here.

Type annotations do not affect runtime, but allow other tools to statically analyse you code for errors. The offical checker is MyPy, which has an IntelliJ extension.

Variable annotations

Type annotations come after the variable/attribute declaration (unlike Java):

foo: int
foo = 1
from sys import argv, exit
import csv
def main():
if len(argv) != 3:
print("Usage: python dna.py filename.csv filename.txt")
exit(1)
people = []
from typing import List, Union
from statham.dsl.constants import Maybe
from statham.dsl.elements import (
AnyOf,
Array,
Boolean,
Integer,
Null,
Number,

Release guide

Developer-oriented guide to named release branching process.

This concerns how delivery teams interact with the release process via a branching strategy rather than the wider release process.

Steps

  1. Release candidate branches may be merged into master once the previous named release completes E2E testing.
    • Mark to own updates on completion of E2E testing.
  • Developers to own: