Skip to content

Instantly share code, notes, and snippets.

@anentropic
anentropic / test_pyparsing_grammar.py
Last active November 25, 2017 22:38
pyparsing grammar tests
from collections import namedtuple
import re
import pytest
from myproject import grammar
EXAMPLES = (
pytest.param(
@anentropic
anentropic / test_pyparsing_indented.py
Last active November 27, 2017 15:13
Test cases for my attempted pyparsing 'docstring' grammar
from collections import namedtuple
from functools import partial
import re
import pyparsing as pp
import pytest
def _flatten(tokens):
# type: (pp.ParseResults) -> pp.ParseResults
@anentropic
anentropic / morelia.py
Last active June 24, 2019 15:04
Per-scenario test methods in Morelia
import os
import re
import unicodedata
from django.conf import settings
from morelia import run
from morelia.grammar import Scenario
from morelia.parser import Parser
@anentropic
anentropic / show_locks.sql
Last active January 24, 2020 14:30
(Postgres) Function to preview locks acquired by a schema change
-- Usage:
-- ---------------------------
-- BEGIN;
-- <statements to analyze: ALTER TABLE ...whatever...;>
-- SELECT * FROM show_locks();
-- ROLLBACK;
-- ---------------------------
CREATE OR REPLACE FUNCTION show_locks()
RETURNS TABLE (
"lock_type" VARCHAR,
package
{
public class StringTemplate
{
/**
* Mimics the python template string format, eg:
*
* "blah blah %(varname)s blah blah"
*
* then you pass in a 'dict' of varnames which get
@anentropic
anentropic / SketchSystems.spec
Last active June 23, 2020 17:00
CHECKOUT FLOW
CHECKOUT FLOW
View bag*
checkout -> Checkout summary
Checkout summary
buy -> Reserve stock
Reserve stock
Lock product*
locked -> Insert purchase record
failed -> Error
Insert purchase record
@anentropic
anentropic / reflection.json
Created April 24, 2021 09:42
GraalVM native-image reflection config for Log4J
[
{
"name" : "org.apache.log4j.Category",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredClasses" : true,
"allPublicClasses" : true
},
class CustomQuerySetManager(Manager):
"""
A re-usable Manager to access a custom QuerySet
"""
def __getattr__(self, attr, *args):
try:
return getattr(self.__class__, attr, *args)
except AttributeError:
# don't delegate internal methods to queryset
# NOTE: without this, Manager._copy_to_model will end up calling