Skip to content

Instantly share code, notes, and snippets.

View lvh's full-sized avatar

lvh lvh

View GitHub Profile
from twisted.protocols import amp
class NestedAMPBox(amp.AmpList):
def fromStringProto(self, inString, proto):
value, = amp.AmpList.fromStringProto(self, inString, proto)
return value
def toStringProto(self, inObject, proto):
return amp.AmpList.toStringProto(self, [inObject], proto)
@lvh
lvh / manhole.py
Created September 15, 2012 11:10
Manhole and Axiom demo
from axiom import attributes, item, store
import jinja2
import sys
from twisted.cred import checkers, portal
from twisted.conch import manhole, manhole_ssh
from twisted.internet import reactor
from twisted.python import log
from twisted.web import resource, server
def _immediateResponder(f):
"""
A decorator for responder functions that should return immediately and
execute asynchronously, as a defense against timing attacks.
The responder decorator should be applied after (above) this decorator::
@SomeCommand.responder
@_immediateResponder
def responder(...):
@lvh
lvh / release-procedure.txt
Last active December 19, 2015 18:29
Updated release procedure for Divmod
1. Check Jenkins builders.
2. Get the latest revision:
% bzr pull
3. Bump version number in <Package>/<package>/_version.py
4. Write release notes in <Package>/NEWS.txt. Add version number and date.
@lvh
lvh / _about.md
Last active March 22, 2017 20:32
How the generate a random password or security question

https://imgs.xkcd.com/comics/password_strength.png

This is a generator for random passwords. It is also useful as the answer to security questions.

How this works

  1. Install gshuf. It's in GNU coreutils. On Macs with homewbrew, brew install coreutils. (On Linux, it night be called just shuf.)
  2. ./get-some.sh

What are these words?

@lvh
lvh / client.py
Created July 6, 2012 08:37
Twisted file upload
import random
import StringIO
from zope import interface
from twisted.internet import abstract, defer, reactor
from twisted.web import client, http_headers, iweb
class _FileProducer(object): # pragma: no cover
"""
@lvh
lvh / cached_protocol.clj
Last active August 28, 2022 01:54
An automatic cached protocol impl I wrote but didn't end up using.
;; (:import
;; (java.nio.file Path FileSystems StandardWatchEventKinds))
(def ^:private all-events
(object-array
[StandardWatchEventKinds/ENTRY_CREATE
StandardWatchEventKinds/ENTRY_DELETE
StandardWatchEventKinds/ENTRY_MODIFY]))
(defn ^:private watch!