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
.venv: requirements.txt | |
test -d ".venv" || python -m virtualenv .venv | |
.venv/bin/pip install -r ./requirements.txt | |
touch .venv | |
.PHONY: serve | |
serve: .venv | |
.venv/bin/python ./server.py | |
.PHONY: worker |
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
SELECT pid, age(clock_timestamp(), query_start) as age, usename, trim(regexp_replace(query, '\s+', ' ', 'g')) as query | |
FROM pg_stat_activity | |
WHERE | |
query != '<IDLE>' | |
AND query NOT ILIKE '%pg_stat_activity%' AND query_start < NOW() - interval '1 seconds' | |
ORDER BY query_start desc; |
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 multiprocessing, os, time | |
try: | |
multiprocessing.set_start_method('fork') | |
except Exception: | |
pass | |
queue = multiprocessing.Queue() | |
def run(queue): | |
while True: | |
task = queue.get() |
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 os | |
import datetime | |
import time | |
import sys | |
def hide_cursor(): | |
sys.stdout.write("\033[?25l") | |
sys.stdout.flush() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 constraint import * | |
ROWS = 'abcdefghi' | |
COLS = '123456789' | |
DIGITS = range(1, 10) | |
VARS = [row + col for row in ROWS for col in COLS] | |
ROWGROUPS = [[row + col for col in COLS] for row in ROWS] | |
COLGROUPS = [[row + col for row in ROWS] for col in COLS] | |
SQUAREGROUPS = [ | |
[ROWS[3 * rowgroup + k] + COLS[3 * colgroup + j] | |
for j in range(3) for k in range(3)] |
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 typing import Callable, Iterable, T | |
from multiprocessing.pool import ThreadPool | |
def threaded_map(f: Callable[..., T], it: Iterable, num_threads: int) -> Iterable[T]: | |
pool = ThreadPool(num_threads) | |
try: | |
results = pool.map(f, it) | |
finally: | |
pool.close() |
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
digraph { | |
0 -> "*" [key=0, | |
label="[b]"]; | |
1 -> "*" [key=0, | |
label="[d]"]; | |
enter -> "*" [key=0, | |
label=ε]; | |
"*" -> 0 [key=0, | |
label="[a]"]; | |
"*" -> 1 [key=0, |
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
class _Stub(object): | |
pass | |
def serialize(model_class, field_name, value): | |
field = model_class._meta.get_field(field_name) | |
obj = _Stub() | |
setattr(obj, field.attname, value) | |
return field.value_to_string(obj) |
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
DROP TABLE IF EXISTS mytable; | |
DROP TABLE IF EXISTS mytable_patches; | |
CREATE TABLE mytable( | |
id SERIAL PRIMARY KEY, | |
data JSON | |
); | |
CREATE TABLE mytable_patches( | |
id SERIAL PRIMARY KEY, |