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
function poetry() { | |
dot_env_path=$(pwd) | |
while [[ "$dot_env_path" != "" && ! -e "$dot_env_path/.env" ]]; do | |
dot_env_path=${dot_env_path%/*} | |
done | |
# if POETRY_DONT_LOAD_ENV is *not* set, then load .env if it exists | |
if [[ -z "$POETRY_DONT_LOAD_ENV" && -f "$dot_env_path/.env" ]]; then | |
>&2 echo 'Loading .env environment variables…' | |
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
from collections import defaultdict | |
from asyncio import Semaphore | |
MAX_CONNECTIONS_PER_MX = 1 | |
leaky_bucket = defaultdict(lambda: Semaphore(MAX_CONNECTIONS_PER_MX)) | |
async def ping_server_handler(request): | |
... |
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
function parseURI(uri) { | |
/* parse <uri> into invidual components (loosely, some errors allowed) */ | |
// see https://regex101.com/r/l96l7F/1 for explanation | |
var regex = /(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?((?:\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?[^?#\/]*)(?:\?([^#]*))?(?:#(.*))?/, | |
groupNames = [ | |
"fullMatch", | |
"scheme", | |
"username", | |
"password", |
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
// if performance is not important | |
function compress(str) { | |
/* shorten <str> by reducing consecutive character repetitions */ | |
return str.replace(/(.)\1*/g, function(fullMatch, g1) { | |
return g1 + fullMatch.length; | |
}); | |
} | |
console.assert(compress('') === '', "blank string"); | |
console.assert(compress('a') === "a1", "single char"); |
NewerOlder