Skip to content

Instantly share code, notes, and snippets.

@parity3
parity3 / gist:6e0bd4979d9e808ecb86
Last active August 29, 2015 14:09
stwatch (syncthing path change monitoring, cygwin inotifywait version)
#!/bin/bash
# Windows Cygwin version. Uses inotifywait port from: https://github.com/thekid/inotify-win
# This version does not support a built in wait timeout for inotifywait.
# The solution is to use the -m switch, and keep inotifywait process spawned outputting events.
# For timeouts we take advantage of the -t switch for bash read.
# Custom values should probably not be set in here. Copy these vars to stwatch.conf to be loaded by the script.
APIKEY=
ADDRESS=127.0.0.1:8080 # default configured port for syncthing REST API
WATCHDIRS=( ) # These 2 arrays represent corresponding paths/folder IDs
WATCHREPOS=( )
@parity3
parity3 / dispatcherqueue.py
Last active September 5, 2017 06:39
trio wait on multiple queues
import collections, operator, datetime, importlib
if 0:
trio = module()
trio.run = None # type: callable
trio.WouldBlock = None
trio.Abort = None # type: abort_class
trio.current_task = None # type: callable
# STUBS for PyCharm
class abort_class:
@parity3
parity3 / test-racers.py
Created September 9, 2017 07:29
Explain queue get behavior of other task siblings when cancelling parent nursery
import trio,itertools
count = itertools.count()
async def q_get(nurs,q,container):
container.append(await q.get())
nurs.cancel_scope.cancel()
async def q_putall(q1,q2):
q1.put_nowait(next(count))
q2.put_nowait(next(count))
@parity3
parity3 / spin_check_race_works.py
Last active September 9, 2017 18:07
The maybe-you-have-data-ready spin-check solves most problems obnoxiously and robustly with blatant disregard for CPU
import trio,itertools,functools
# noinspection PyProtectedMember
from trio._core._run import Nursery
count = itertools.count()
tasks = []
async def spin_check(nurs : Nursery, event : trio.Event,container : list, func : callable, reset : callable):
while True:
reset()
if container:
print("satisfied already")
@parity3
parity3 / httplib2_noclose_HEAD.py
Created October 6, 2017 18:58
prevent HEAD requests from auto-closing the connection
import httplib
import socket
import httplib2
# the whole reason this module is necessary is to prevent HEAD requests from auto-closing the connection.
class HTTPResponse(httplib.HTTPResponse):
def read(self, amt=None):
# prevent the HEAD check from closing the connection
{
"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
},
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()
@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):