Skip to content

Instantly share code, notes, and snippets.

Avatar

Tristan Seligmann mithrandi

View GitHub Profile
View gist:6c03ece47ba2dfd2ec339634855f1ab2
cryptography-rust v0.1.0 (/home/mithrandi/code/cryptography/src/rust)
├── asn1 v0.6.4
│ ├── asn1_derive v0.6.4
│ │ ├── proc-macro2 v1.0.29 (in debian)
│ │ ├── quote v1.0.10 (in debian)
│ │ └── syn v1.0.80 (in debian)
│ └── chrono v0.4.19 (in debian)
├── chrono v0.4.19 (in debian)
├── lazy_static v1.4.0 (in debian)
├── ouroboros v0.12.0
@mithrandi
mithrandi / sha256sum.py
Created Apr 26, 2014
Quick sha256sum implementation in Python
View sha256sum.py
from hashlib import sha256
from sys import argv
for fn in argv[1:]:
if fn == '-':
f = sys.stdin
else:
f = open(fn, 'rb')
with f:
print '%s *%s' % (sha256(f.read()).hexdigest(), fn)
View Polling.hs
import Control.Concurrent
import Control.Concurrent.STM
import Control.Exception.Safe
import Data.Time.Units
pollT :: TimeUnit t => t -> IO a -> IO (STM (Maybe a), Async b)
pollT delay act = do
tv <- newTVarIO Nothing
as <-
async . forever $ do
View maybe.py
def maybe(f, v, default=None):
"""
Return C{f(v)} if C{v} is not C{None}, otherwise return C{default}.
"""
if v is None:
return default
return f(v)
@mithrandi
mithrandi / mergemaps.py
Created Jul 12, 2016
Script to merge hg shamaps
View mergemaps.py
import sys
revmap2 = {}
with open(sys.argv[2]) as fMap2:
for line in fMap2:
a, b = line.rstrip('\n').split(' ')
revmap2[a] = b
with open(sys.argv[1]) as fMap1:
for line in fMap1:
a, b = line.rstrip('\n').split(' ')
@mithrandi
mithrandi / bench_nevow.py
Last active Apr 17, 2016
twisted.web.template / nevow.page optimization stuff
View bench_nevow.py
import time
from StringIO import StringIO
from nevow import tags
from nevow.context import WovenContext
from nevow.flat.twist import deferflatten
from nevow.loaders import stan, xmlstr
from nevow.page import Element, renderer
try:
@mithrandi
mithrandi / bench_builder.py
Created Mar 30, 2016
Cryptography X509 builder benchmark
View bench_builder.py
from __future__ import print_function
import time
from datetime import datetime, timedelta
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.x509.oid import NameOID
View test.rst

First Level

Some text.

Second Level

Some text.

@mithrandi
mithrandi / legacydecl.py
Created Feb 20, 2016
Legacy declaration generator
View legacydecl.py
#!/usr/bin/env python
from twisted.python.reflect import namedAny
template = """
declareLegacyItem(
typeName=%r,
schemaVersion=%d,
attributes=dict(
%s))
"""
@mithrandi
mithrandi / init.el
Created Feb 9, 2016
Twistedchecker for flycheck (Emacs)
View init.el
;; Define the checker
(flycheck-define-checker python-twistedchecker
"A Python syntax and style checker using twistedchecker."
:command ("twistedchecker"
;; Need `source-inplace' for relative imports (e.g. `from .foo
;; import bar'), see https://github.com/flycheck/flycheck/issues/280
source-inplace)
:error-filter
(lambda (errors)
(flycheck-sanitize-errors (flycheck-increment-error-columns errors)))