This file contains hidden or 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
# Usage: jq --stream --null-input --from-file stream_array.jq | |
# | |
# Or, as a one-liner: | |
# jq --stream -n 'def end_array_or_object: length == 1 and (first | length == 1); def outer_primitive: length == 2 and (first | length == 0); def end_element: length > 0 and (last | (end_array_or_object or outer_primitive)); foreach (inputs | del(.[0][0])) as $path ([]; if end_element then [$path] else . + [$path] end; if end_element then fromstream(.[]) else empty end)' | |
# This is useful for processing large JSON files/indefinite streams of elements | |
# that happen to be wrapped in an outer array. | |
# The process is: | |
# - Stream the path elements (via `jq --stream`) | |
# - Remove the leading path element from all entries. This effectively drops the |
This file contains hidden or 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
// Taken from https://stackoverflow.com/a/9382383 | |
let decycle; | |
decycle = (obj, stack = []) => { | |
if (!obj || typeof obj !== 'object') { | |
return obj; | |
} | |
if (stack.includes(obj)) { | |
return null; | |
} | |
let s = stack.concat([obj]); |
This file contains hidden or 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
let range = (start, end, step) => { | |
return { | |
*[Symbol.iterator]() { | |
for (let n = start; n < end; n += step) { | |
yield n; | |
} | |
}, | |
}; | |
}; |
This file contains hidden or 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 argparse | |
import asyncio | |
import codecs | |
import contextlib | |
import json | |
import sys | |
import threading |
This file contains hidden or 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 asyncio | |
import json | |
import sys | |
async def main(): | |
reader, writer = await asyncio.open_connection("127.0.0.1", 8888) | |
messages = ["One", 2, {"thr": "ee"}, ["4"], [5, 6]] |
This file contains hidden or 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
create table j as select json(column0) as j from read_csv_auto('eventlog.json', delim='\0'); | |
.mode list | |
.header off | |
.once 'schema.json' | |
select json_group_object(event, structure) from (select j->>'Event' as event, json_group_structure(j) as structure from j group by event); |
This file contains hidden or 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
-- To use this, invoke wrk with the lua script option, e.g.: | |
-- env WRK_OUTPUT_CSV='timing.csv' wrk -s log_data.lua 'http://localhost:8000/' | |
done = function(summary, latency, requests) | |
-- Unfortunately, writing output to stdout is not a good option because it | |
-- gets intermingled with other `wrk` output. The maintainer is not amenable | |
-- to suppressing this (see -- https://github.com/wg/wrk/issues/245). | |
-- Similarly, we cannot write to stdout safely because _actual_ error messages | |
-- are also logged there. Instead, we write to a file (or stdout by default, | |
-- for human-readability purposes). | |
filename = os.getenv("WRK_OUTPUT_CSV") |
This file contains hidden or 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 argparse | |
from typing import Callable, Generator, TypeVar | |
def main(): | |
parser = argparse.ArgumentParser( | |
"Generates necklace-related sequences using the FKM algorithm as described by \"Combinatorial Generation\" by Frank Ruskey. See https://web.archive.org/web/20221203232527/https%3A%2F%2Fpage.math.tu-berlin.de%2F~felsner%2FSemWS17-18%2FRuskey-Comb-Gen.pdf" |
This file contains hidden or 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 | |
from abc import ABC, abstractmethod | |
from enum import Enum | |
from typing import Any, Callable, ForwardRef, Generic, TypeAlias, TypeVar, cast | |
class RecordSeparator(Enum): | |
VALUE = "RecordSeparator" |
This file contains hidden or 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 | |
def main(): | |
print("powerset:") | |
for subset in powerset([0, 1, 2, 3]): | |
print(subset) | |
print() | |
print("combinations:") | |
for subset in combinations([0, 1, 2, 3, 4, 5], 3): | |
print(subset) |