This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import edgedb | |
import sys | |
EXT = 'ltree' | |
def main(argv): | |
db = edgedb.create_client( | |
port=5656, database='edgedb', tls_security='insecure' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import textwrap | |
from typing import Any | |
# Escape delimeters for maintaining a nesting structure in strings | |
# that the user produces. Obviously, as with all schemes for in-band | |
# signalling, all hell can break loose if the signals appear in the | |
# input data unescaped. | |
# | |
# Our signal sequences contain a null byte and both kinds of quote | |
# character, so you should be fine as long as any untrusted data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Hacky implementation of "view patterns" with Python match | |
A "view pattern" is one that does some transformation on the data | |
being matched before attempting to match it. This can be super useful, | |
as it allows writing "helper functions" for pattern matching. | |
We provide a class, ViewPattern, that can be subclassed with custom | |
`match` methods that performs a transformation on the scructinee, | |
returning a transformed value or raising NoMatch if a match is not | |
possible. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
OPS = { | |
x.__doc__.split()[3]: x | |
for k in dir(operator) | |
if not k.startswith('__') | |
and (x := getattr(operator, k)).__doc__.startswith("Same as a ") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with | |
# I made an object Input with a data property, which made it easier to | |
# develop this in the CLI. It also works fine to make the input a parameter. | |
input := (select Input filter .day = 1).data, | |
# input := <str>$0, | |
grps := array_unpack(str_split(input[:-1], '\n\n')), | |
sums := (for grp in grps union ( | |
with entries := <int64>array_unpack(str_split(grp, '\n')), | |
select sum(entries) | |
)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from dataclasses import dataclass | |
import json | |
import time | |
import textwrap | |
from typing import Any, Callable | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Script that tries to scrape all potential test inputs. | |
By default it writes all of them to files in the directory | |
<day>.tests. It also prints all of the contents out along | |
with the file names so that you can quickly inspect and | |
determine which you want to use. | |
Depends on advent-of-code-data 1.1.0 (later versions may |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%%% Formalization of a simply typed lambda-calculus with n-ary tuples. | |
% I decided to do this because it seemed like something small and | |
% interesting that was definitely not on the twelf wiki as a case | |
% study or a tutorial. n-ary tuples are a great feature in that they | |
% add no expressive power over pairs but are a much bigger pain to | |
% machine formalize! | |
% | |
% Doing it on paper is mostly just a matter of sprinkling "subscript i" | |
% and "..." around, but is otherwise pretty straightforward. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Do a FULL OUTER JOIN on User.name[0] = Card.name[0] | |
# (the seed computable is to demonstrate that it works with computed data) | |
WITH | |
L := User { seed := random() }, | |
R := Card, | |
joined := DISTINCT { | |
(FOR l IN {L} UNION ([l.id], [(SELECT R FILTER l.name[0] = R.name[0]).id] ?? <array<uuid>>[])), | |
(FOR r IN {R} UNION (([(SELECT L FILTER L.name[0] = r.name[0]).id] ?? <array<uuid>>[]), [r.id])), | |
}, | |
FOR row in {joined} UNION ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Run with: | |
# edb test tests/test_edgeql_ir_scopetree.py 2>&1 | python3 scopetree-test-fixup.py -i | |
import textwrap | |
import sys | |
from typing import * |
NewerOlder