Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am malthe on github.
  • I am malthe (https://keybase.io/malthe) on keybase.
  • I have a public key ASDrplWb0b2fpoxO3wkqNFadCp9nMBMad9cUiGufDM4PQAo

To claim this, I am signing this object:

@malthe
malthe / dedent.js
Created December 16, 2014 11:25
This is similar to Python's "textwrap.dedent" function
function dedent(text) {
var re_whitespace = /^([ \t]*)(.*)\n/gm;
var l, m, i;
while ((m = re_whitespace.exec(text)) !== null) {
if (!m[2]) continue;
if (l = m[1].length) {
i = (i !== undefined) ? Math.min(i, l) : l;
} else break;
import base64
import requests
from Crypto.Signature import PKCS1_v1_5
from Crypto.Hash import SHA
from Crypto.PublicKey import RSA
from Crypto.Util.asn1 import DerSequence
def import_pubkey_from_x509(pem):
@malthe
malthe / path.py
Created November 27, 2012 09:30
Chameleon 2.x "path traverser" implementation in Python
import re
import ast
from chameleon.tales import TalesExpr
from chameleon.codegen import template
from chameleon.astutil import load
from chameleon.astutil import Symbol
from chameleon.exc import ExpressionError
@malthe
malthe / patch.diff
Created June 8, 2012 12:42
Zope 2 patch to warn on transaction resource commits for a GET request
Index: src/Zope2/App/startup.py
===================================================================
--- src/Zope2/App/startup.py (revision 126687)
+++ src/Zope2/App/startup.py (working copy)
@@ -327,6 +327,9 @@
def abort(self):
transaction.abort()
+ def get(self):
+ return transaction.get()
@malthe
malthe / btree.py
Created March 2, 2012 22:51 — forked from gaubert/btree.py
A pure-python B+ tree implementation (interpreter versions 2.6 thru 3.2)
# Based on code by Travis Parker
import bisect
import operator
try:
xrange
except NameError:
xrange = range
@malthe
malthe / cproperty.py
Created February 24, 2012 18:58
Cached property in Python with invalidation
import functools
_invalid = object()
def cached_property(_get, _set, _del=None):
name = _get.__name__
mangled = "_" + name
@functools.wraps(_get)
def cached_get(inst):
@malthe
malthe / .emacs.el
Created February 24, 2012 11:06
Dot-emacs
;; .emacs
;; =========================================================================
;;
;; Malthe Borch
;;
;; Last updated: Fri Feb 24, 2012.
;; Add own packages to load path
(let* ((my-lisp-dir "~/.emacs.d/site-lisp")
(default-directory my-lisp-dir)
@malthe
malthe / nuke.el
Created January 20, 2012 11:09
Nuke dashes in Emacs
(defun nuke-dashes ()
(interactive) (save-excursion (goto-char (point-min)) (while (re-search-forward "^-" nil t) (replace-match ""))))
(global-set-key "\C-d" 'nuke-dashes)
@malthe
malthe / hyphenation.py
Created September 22, 2011 13:11
Dictionary-based HTML hyphenation using soft hyphen
import os
import re
from htmlentitydefs import name2codepoint
# Must install the `hyphenator` library from PyPi!
from hyphenator import Hyphenator
# Firefox comes with an English hyphenation dictionary
path = os.popen('locate hyph_en_US.dic').readlines()[0].strip()