Skip to content

Instantly share code, notes, and snippets.

View DMRobertson's full-sized avatar

David Robertson DMRobertson

View GitHub Profile
@DMRobertson
DMRobertson / cayley_f3.py
Created December 15, 2017 12:57
Blender Python API example
"""A script to build a model representing the Cayley graph of F_3 in Blender. I threw this together in a morning so it's quite hacky and quite dirty."""
import bpy
from itertools import product
from math import sqrt
def make_alphabet(letters):
"""Group/monoid elements are represented in memory as numbers, but we should be able to list them as human-readable strings. We use an asterisk to denote inverse, so that (e.g.) xx* = 1."""
symbols = {}
for i, char in enumerate(letters):

Goal

We want only public profiles to be searchable and visible in the user directory search. By public profiles ("canonical" maybe?) we mean the thing returned by GET /profile/USER_ID.

Where does the leak come from?

We're getting names into the user directory (user_directory and user_directory_search) via calls to update_profile_in_user_dir. There are five calls:

  • main/user_directory.py (regenerate the user directory)

Scenario

Aiming to solve matrix-org/synapse#5677.

Follows on from matrix-org/synapse#10695.

We're running our own homeserver with users Bob and Eve. A remote user Alice is already in a public room on her own homeserver. Bob on our homeserver joins it.

@DMRobertson
DMRobertson / mypy-example.py
Last active September 7, 2021 17:34
TypedDicts and Dicts in mypy
#! /usr/bin/env python3
"""TypedDicts and Dicts in mypy"""
from typing import TypedDict, Dict, Any, Mapping
JsonDict = Dict[str, Any]
JsonMapping = Mapping[str, Any]
@DMRobertson
DMRobertson / test_dmr.py
Created September 30, 2021 11:09
Class and instance attributes in unittest.TestCase
from unittest import TestCase
class DMRTest(TestCase):
class_count = 0
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.instance_count = 0
@DMRobertson
DMRobertson / any-exprs.txt
Created October 27, 2021 11:54
Synapse `Any` reports
Name Anys Exprs Coverage
---------------------------------------------------------------------------------
__main__ 18 46 60.87%
synapse.api.auth 132 772 82.90%
synapse.api.auth_blocking 20 167 88.02%
synapse.api.constants 0 214 100.00%
synapse.api.errors 19 582 96.74%
synapse.api.filtering 35 660 94.70%
synapse.api.presence 1 62 98.39%
synapse.api.ratelimiting 4 319 98.75%
@DMRobertson
DMRobertson / example.py
Created October 28, 2021 13:58
Requiring multiple zope Interfaces
#! /usr/bin/env python3
from zope.interface import Interface, implementer
class IA(Interface):
def do_a() -> None:
...
class IB(Interface):
@DMRobertson
DMRobertson / dirty.py
Last active November 15, 2021 17:18
Dirty store inheritance script
import sys
import re
import subprocess
import networkx
from networkx import is_directed_acyclic_graph, descendants
oneline_class_pattern = re.compile("^class (.*)\((.*)\):$")
opening_class_pattern = re.compile("^class (.*)\($")
@DMRobertson
DMRobertson / parse.py
Created December 17, 2021 18:30
dirty script to ingest synapse request logs into sqlite
#! /usr/bin/env python3
import argparse
import re
import sqlite3
import sys
# Sorry everyone.
# Use nongreedy matches to make this well fast.
$ ./install-deps.pl
Starting with version 2.29 of the cpan shell, a new download mechanism
is the default which exclusively uses cpan.org as the host to download
from. The configuration variable pushy_https can be used to (de)select
the new mechanism. Please read more about it and make your choice
between the old and the new mechanism by running
o conf init pushy_https