Skip to content

Instantly share code, notes, and snippets.

parity3

Block or report user

Report or block parity3

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gzip_stream.py
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()
View 42672128.json
{
"account": {
"customerInfo": null,
"giftCardBalance": null,
"giftCardRedeemCode": "",
"giftCardRedeemError": "",
"isGiftCardRedeemed": false,
"isGiftCardRedeemLoading": false,
"isLoading": false
},
View 39332122.json
{
"account": {
"customerInfo": null,
"giftCardBalance": null,
"giftCardRedeemCode": "",
"giftCardRedeemError": "",
"isGiftCardRedeemed": false,
"isGiftCardRedeemLoading": false,
"isLoading": false
},
View ariat-coniston-pro-gtx-insulated-ebony__product__8762583.json
{
"account": {
"customerInfo": null,
"giftCardBalance": null,
"giftCardRedeemCode": "",
"giftCardRedeemError": "",
"isGiftCardRedeemed": false,
"isGiftCardRedeemLoading": false,
"isLoading": false
},
@parity3
parity3 / httplib2_noclose_HEAD.py
Created Oct 6, 2017
prevent HEAD requests from auto-closing the connection
View httplib2_noclose_HEAD.py
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
@parity3
parity3 / spin_check_race_works.py
Last active Sep 9, 2017
The maybe-you-have-data-ready spin-check solves most problems obnoxiously and robustly with blatant disregard for CPU
View spin_check_race_works.py
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 / test-racers.py
Created Sep 9, 2017
Explain queue get behavior of other task siblings when cancelling parent nursery
View test-racers.py
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 / dispatcherqueue.py
Last active Sep 5, 2017
trio wait on multiple queues
View dispatcherqueue.py
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 / gist:6e0bd4979d9e808ecb86
Last active Aug 29, 2015
stwatch (syncthing path change monitoring, cygwin inotifywait version)
View gist:6e0bd4979d9e808ecb86
#!/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=( )
You can’t perform that action at this time.