Skip to content

Instantly share code, notes, and snippets.

@ctoth
ctoth / Python
Created June 19, 2015 20:02
Uploading with requests_toolbelt
import os
import requests
from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor
def upload(filename, url, key='file', user_agent='HTTP-UPLOADER/1.0', callback=None):
total_size = os.stat(filename).st_size
payload = {key: (filename, open(filename, 'rb'), "application/octet-stream")}
encoder = MultipartEncoder(fields=payload, encoding='ascii')
def encoder_callback(mon):
if callback is not None:
@ctoth
ctoth / gist:7bd8b32215b4eae73439
Created June 19, 2015 20:04
Uploading with Poster
import os
import urllib2, poster.streaminghttp
from poster.encode import multipart_encode
opener = poster.streaminghttp.register_openers()
def upload(filename, url, key='file', user_agent='HTTP Uploader', callback=None):
with open(filename, 'rb') as to_upload:
datagen, headers = multipart_encode({key: to_upload}, cb=callback)
req = urllib2.Request(url, datagen, headers)
@ctoth
ctoth / CLAUDE.md
Created November 30, 2025 20:46
My Current global CLAUDE.md

Working with Q — Coding Agent Protocol

What This Is

Applied rationality for a coding agent. Defensive epistemology: minimize false beliefs, catch errors early, avoid compounding mistakes.

This is correct for code, where:

  • Reality has hard edges (the compiler doesn't care about your intent)
  • Mistakes compound (a wrong assumption propagates through everything built on it)
  • The cost of being wrong exceeds the cost of being slow