Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Created November 4, 2025 22:30
Show Gist options
  • Save tbnorth/f616db9dbebb876056d9b8872c5cf6c3 to your computer and use it in GitHub Desktop.
Save tbnorth/f616db9dbebb876056d9b8872c5cf6c3 to your computer and use it in GitHub Desktop.

docker run -d --restart unless-stopped -it -p 30767:8767 -v $PWD/devsub:/src/devsub --mount src=shared_htdocs,dst=/out,volume-subpath=devlogs python python /src/devsub

HOST=maindev ; CONT=someapp ; on -n $HOST "docker logs -t --tail 1000 $(docker ps -fname=$CONT --format='{{println .ID}}')" | devpub $HOST $CONT

!/usr/bin/env python
import sys
from urllib.parse import quote
from urllib.request import Request, urlopen
BLOCKSIZE = 10_000_000
desc = " ".join(sys.argv[1:]) or "NONE PROVIDED"
data = sys.stdin.read().encode("utf-8")
print("Sending", len(data))
req = Request(
"http://some.example.com:30767/" + quote(desc),
headers={"Content-type": "text/plain"},
data=data,
method="POST",
)
resp = urlopen(req, timeout=5)
name = resp.read().decode("utf-8")
print("https://other.example.com/devlogs/" + name)
#!/usr/bin/env python
import http
import time
import uuid
from http.server import ThreadingHTTPServer
from urllib.parse import unquote
BLOCKSIZE = 10_000_000
SERVER_CLASS = ThreadingHTTPServer
class PostHandler(http.server.BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
def do_GET(self):
self._set_headers()
print("Getting")
self.wfile.write(b"Please use POST")
self.wfile.close()
def do_POST(self):
self._set_headers()
print("Post")
uid = str(uuid.uuid4())
filename = uid + ".txt"
desc = unquote(self.path.strip("/")) or "NONE PROVIDED"
ts = time.asctime()
print(filename)
content_length = int(self.headers["Content-Length"])
with open("/out/" + filename, "wb") as out:
out.write(f"# Dumped: {ts}\n".encode("utf-8"))
out.write(f"# Description: {desc}\n\n".encode("utf-8"))
while read := self.rfile.read(min(content_length, BLOCKSIZE)):
print("Read", len(read))
out.write(read)
if len(read) != BLOCKSIZE:
break
self.wfile.write(filename.encode("utf-8"))
# self.wfile.close()
with SERVER_CLASS(("0.0.0.0", 8767), PostHandler) as httpd:
print("Running")
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment