Skip to content

Instantly share code, notes, and snippets.

View markrwilliams's full-sized avatar

Mark Williams markrwilliams

View GitHub Profile
import csv
from parsley import makeGrammar
import sys
raw = r'''
squote = '\''
escaped_squote = '\\' squote
float = <digit+ '.' digit*>:f -> float(f)
int = <digit+>:i -> int(i)
string = squote <(escaped_squote | ~squote anything)*>:s squote -> s
def collect_keys(d):
if not isinstance(d, dict):
return []
level = d.keys()
for k, v in d.items():
level.extend('%s.%s' % (k, c) for c in collect_keys(v))
return level
def analyze(paths):
from itertools import chain, combinations
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
def remove_indices(s, indices):
ret, prev = '', 0
>>> A.mro()
[<class '__main__.A'>, <type 'object'>]
>>> B.mro()
[<class '__main__.B'>, <type 'object'>]
>>> set.mro()
[<type 'set'>, <type 'object'>]
>>> dict.mro()
[<type 'dict'>, <type 'object'>]
>>> class C(A, B): pass
...
from twisted.internet import reactor, defer, protocol, task
from twisted.internet.ssl import ClientContextFactory
from twisted.words.protocols import irc
class NoPingBotProtocol(irc.IRCClient):
def __init__(self, *args, **kwargs):
self.nickname = 'noping'
self.password = 'balloonatics'
#include <stdio.h>
#include <sys/socket.h>
int
main(int argc, char *argv[])
{
printf("%d %d %d\n", CMSG_ALIGN(sizeof(int)), CMSG_ALIGN(sizeof (struct cmsghdr)), CMSG_SPACE(sizeof(int)));
}
import ctypes
class cmsghdr0(ctypes.Structure):
_fields_ = [('cmsg_len', ctypes.c_size_t),
('cmsg_level', ctypes.c_int),
('cmsg_type', ctypes.c_int)]
class cmsghdr(ctypes.Structure):
import ctypes
import os
import socket
socklen_t = ctypes.c_uint
SCM_RIGHTS = 0x01
libc = ctypes.CDLL('libc.so.6')
class iovec(ctypes.Structure):
_fields_ = [('iov_base', ctypes.c_void_p),
@markrwilliams
markrwilliams / qsortest.pyx
Last active January 4, 2016 15:29
somecython
cimport cython
from libc.stdlib cimport calloc, free
cdef extern from "qsortest.h":
void qsort_char(unsigned char *base, size_t nmemb)
def mvqsort(unsigned char[:] vofi):
qsort_char(&vofi[0], vofi.shape[0])
#!/bin/sh -x
die () {
msg="$1"
echo $msg 1>&2
exit 1
}
prep_sqlite() {