Skip to content

Instantly share code, notes, and snippets.

@parity3
parity3 / unpriv.sh
Created December 1, 2023 04:41
Create and switch to a user matching the owner of the first bind mount
#!/usr/bin/env bash
set -o pipefail
set -e
set -x
function _get_userid_from_mounts() {
type -fp awk >/dev/null || return 1
local mountpath
local folder_uid
while read -r mountpath ; do
import functools
import logging
import os
import struct
from typing import Dict, cast, Optional, List
import cytoolz
from trio.hazmat import wait_readable
import inotify_simple
import trio
@parity3
parity3 / quart-trio-triopg.py
Created January 19, 2020 22:37
running quart-trio inside trio_asyncio.run
import logging
import sys
import trio, trio_asyncio, asyncio
from hypercorn.trio.run import worker_serve
from hypercorn import Config
import contextlib
import math
from types import TracebackType
from quart import current_app, json
@parity3
parity3 / pub_sub.py
Last active December 31, 2019 01:39
publish-subscribe with sequential async delivery
from contextlib import asynccontextmanager
import trio
class broadcaster:
def __init__(self):
super().__init__()
self.subscribers = {}
async def __aenter__(self):
@parity3
parity3 / InotifyWrapper.py
Created December 30, 2019 16:59
use of trio wait_readable and inotify_simple
import functools
import logging
import os
import struct
from typing import Dict, cast, Optional, List
import cytoolz
from trio.hazmat import wait_readable
import inotify_simple
import trio
@parity3
parity3 / httpfile_helpers.py
Created November 26, 2019 21:45
example of de-chunking a http-spec based chunked transfer encoding via a coroutine (entrypoint function: coro_te_with_packets)
import cStringIO
import logging
log = logging.getLogger('log')
class te_lengthfound_exception(StandardError):
def __init__(self, length, extension):
self.length=length
self.extension=extension
class te_trailer_exception(StandardError):
import functools, cStringIO, sys
import itertools, zlib, gzip, os
class savedata:
# convenience class used only while reading the gzip file header.
# it may not be a gzip file, so this instance will hold whatever was read so we don't have to seek backwards
def __init__(self, fileobj):
self.fileobj = fileobj
self.saved_data = cStringIO.StringIO()
{
"account": {
"customerInfo": null,
"giftCardBalance": null,
"giftCardRedeemCode": "",
"giftCardRedeemError": "",
"isGiftCardRedeemed": false,
"isGiftCardRedeemLoading": false,
"isLoading": false
},
{
"account": {
"customerInfo": null,
"giftCardBalance": null,
"giftCardRedeemCode": "",
"giftCardRedeemError": "",
"isGiftCardRedeemed": false,
"isGiftCardRedeemLoading": false,
"isLoading": false
},
{
"account": {
"customerInfo": null,
"giftCardBalance": null,
"giftCardRedeemCode": "",
"giftCardRedeemError": "",
"isGiftCardRedeemed": false,
"isGiftCardRedeemLoading": false,
"isLoading": false
},