Skip to content

Instantly share code, notes, and snippets.

[core]
editor = emacs
[user]
name = pgjones
email =
[pull]
rebase = true
from random import choice
from string import Formatter
from timeit import timeit
from werkzeug.routing import Map, Rule
from werkzeug.routing.matcher import TableMatcher, TreeMatcher
# With thanks to https://github.com/richardolsson/falcon-routing-survey for the paths below
PATHS = [
@pgjones
pgjones / brackets.py
Last active May 26, 2022 14:43
Rainwater trials
pairs = {
")": "(",
"}": "{",
"]": "[",
}
class Solution:
def isValid(self, s: str) -> bool:
stack = []
for c in s:
@pgjones
pgjones / schema.sql
Last active December 22, 2020 15:09
DROP TABLE IF EXISTS todos;
CREATE TABLE todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
complete BOOLEAN NOT NULL DEFAULT FALSE,
due TIMESTAMPTZ,
task TEXT NOT NULL
);
import asyncio
import inspect
from functools import partial
import pytest
scope = object()
receive = object()
send = object()
@pgjones
pgjones / release.sh
Created January 18, 2019 10:19
RELEASE - simple instructions to build and release a Python project
rm -rf dist/ build/
python setup.py sdist
python setup.py bdist_wheel
twine upload dist/*
@pgjones
pgjones / gcra.py
Last active September 16, 2019 04:02
Generic Cell Rate Algorithm example
class RateLimit:
def __init__(self, count: int, period: timedelta) -> None:
self.count = count
self.period = period
@property
def inverse(self) -> float:
return self.period.total_seconds() / self.count
@pgjones
pgjones / fetch_app.py
Last active March 6, 2018 02:50
Understanding Asyncio Snippets
import asyncio
import aiohttp
from quart import Quart
app = Quart(__name__)
async def fetch(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
@pgjones
pgjones / test_flask_cookie.py
Created February 12, 2017 16:00
Example of how to use the Flask `test_request_context` with a cookie set
@pgjones
pgjones / threadPool.js
Created August 21, 2016 20:59
Simple javascript thread pool example
ThreadPool = function(script, size) {
this.threads = [];
this.tasks = [];
for (var ithread = 0; ithread < size; ithread++) {
this.threads.push(new lxst.FilterThread(script, this));
}
};
ThreadPool.prototype.queueTask = function(task, callback) {
const task = {task: task, callback: callback};