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() |
Loading
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
import numpy as np | |
import cv2 | |
def sp_noise(image, prob): | |
''' | |
Add salt and pepper noise to image | |
prob: Probability of the noise | |
''' | |
output = image.copy() |
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
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, |
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
>>> type(Union[int, str]) | |
typing.Union | |
>>> type(Union[int, str]) == Union | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/Users/lucaswiman/.pyenv/versions/3.6/lib/python3.6/typing.py", line 760, in __eq__ | |
return self._subs_tree() == other | |
File "/Users/lucaswiman/.pyenv/versions/3.6/lib/python3.6/typing.py", line 760, in __eq__ | |
return self._subs_tree() == other | |
File "/Users/lucaswiman/.pyenv/versions/3.6/lib/python3.6/typing.py", line 760, in __eq__ |