This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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 | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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))); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -x | |
die () { | |
msg="$1" | |
echo $msg 1>&2 | |
exit 1 | |
} | |
prep_sqlite() { |