Skip to content

Instantly share code, notes, and snippets.

@slingamn
slingamn / against_scram.md
Created August 13, 2021 01:15
Against SCRAM

Against SCRAM

I added support for the SCRAM-SHA-256 authentication mechanism to the Ergo IRC server, in response to demand for a reference implementation that clients could test against. Conversely, if you're implementing a server, I added an irctest server test covering it.

Nonetheless, this decision should not be taken as an endorsement of SCRAM. I recommend against implementing SCRAM-SHA-256 or any other SCRAM variant. Here's why.

The baseline: SASL PLAIN over TLS

@slingamn
slingamn / cooke-selfdriving.md
Last active January 2, 2018 12:18
response to Cooke on self-driving cars

Charles C. W. Cooke writes here about the privacy problems with self-driving cars. As often with privacy issues, the devil is in the details. Cooke begins with a fundamentally valid criticism: most people will not own self-driving cars, but will buy access to them on an ad-hoc basis from companies like Uber and Lyft. The implications for privacy from such a cultural shift are serious and should not be minimized. However, Cooke seemingly goes on to argue that it doesn't matter who owns the hardware, because self-driving is inherently not private:

>Regardless, everyone will suffer from the catastrophic loss of privacy. Any network of self-driving cars would, by definition, necessitate total and unceasing tracking of their occupants. I may know how to get to the local liquor store without a map, but my car most certainly does not. To make it there in a driverless model, I'd first have to tell it where

@slingamn
slingamn / gist:4332611
Created December 18, 2012 22:19
old leak test from kennethreitz/requests#520
import gc, os, subprocess, requests
gc.disable() # Just to make sure - I have seen this with gc enabled
for x in range(20):
requests.head("http://www.google.com/")
print "Open sockets after 20 head requests:"
pid = os.getpid()
subprocess.call("lsof -p%d -a -iTCP" % (pid,), shell=True)
@slingamn
slingamn / gist:4231260
Created December 7, 2012 06:41
_fileobject.readline() from Python's standard-library socket.py
def readline(self, size=-1):
buf = self._rbuf
buf.seek(0, 2) # seek end
if buf.tell() > 0:
# check if we already have it in our buffer
buf.seek(0)
bline = buf.readline(size)
if bline.endswith('\n') or len(bline) == size:
self._rbuf = StringIO()
self._rbuf.write(buf.read())
@slingamn
slingamn / clt.py
Created December 6, 2012 07:03
central limit theorem demonstration
#!/usr/bin/python
import math
import random
def bernoulli(p=0.5):
"""Bernoulli random variable with parameter p."""
return 1 if random.random() < p else 0
def bernoulli_sum(n, p=0.5):
diff --git a/requests/packages/urllib3/connectionpool.py b/requests/packages/urllib3/connectionpool.py
index 97da544..fd324fd 100644
--- a/requests/packages/urllib3/connectionpool.py
+++ b/requests/packages/urllib3/connectionpool.py
@@ -189,6 +189,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
self.num_connections += 1
log.info("Starting new HTTP connection (%d): %s" %
(self.num_connections, self.host))
+ print "adding new connection for", self.host
return HTTPConnection(host=self.host, port=self.port)
@slingamn
slingamn / gist:3318253
Created August 10, 2012 21:38 — forked from eranrund/gist:3313868
demonstrates python-requests socket leak
import requests
import os
import subprocess
pid = os.getpid()
reqsess = requests.session()
try:
r = reqsess.get(r'http://www.mouser.com/Search/Refine.aspx?Keyword=test')
d = r.text
finally:
reqsess.close()
# catch urllib3 exceptions and throw Requests exceptions
try:
# Send the request.
r = conn.urlopen(
method=self.method,
url=self.path_url,
body=body,
headers=self.headers,
redirect=False,
assert_same_host=False,
#!/usr/bin/python
class A(object):
field = 0
def __hash__(self):
return hash(self.field)
def __eq__(self, other):
return self.field == other.field
diff --git a/requests/models.py b/requests/models.py
index 62aeb9c..1104604 100644
--- a/requests/models.py
+++ b/requests/models.py
@@ -299,7 +299,6 @@ class Request(object):
r.history = history
self.response = r
- self.response.request = self