Skip to content

Instantly share code, notes, and snippets.

ERROR:root:STDOUT: File "/mnt/workspace/lunr/lunr/db/uuidimpl.py", line 62, in process_result_value
ERROR:root:STDOUT: return str(uuid.UUID(value))
ERROR:root:STDOUT: File "/usr/lib/python2.6/uuid.py", line 134, in __init__
ERROR:root:STDOUT: raise ValueError('badly formed hexadecimal UUID string')
ERROR:root:STDOUT: ValueError: badly formed hexadecimal UUID string
$ cat test.py
from cStringIO import StringIO
expected = 'a'
result = StringIO('a').read()
assert result is expected
expected = 'abc'
result = StringIO('abc').read()
assert result is expected, "%s is not %s" % (repr(result), repr(expected))
@clayg
clayg / ctype initgroups system call
Created February 6, 2012 22:28
how to get access to initgroups in python < 2.7
import os
from ctypes import CDLL, get_errno, c_char_p, c_int
libc = CDLL(None, use_errno=True)
def errcheck(result, func, arguments):
if result != 0:
e = get_errno()
raise OSError(e, os.strerror(e))
class ResourceExceptionHandler(object):
"""Context manager to handle Resource exceptions.
Used when processing exceptions generated by API implementation
methods (or their extensions). Converts most exceptions to Fault
exceptions, with the appropriate logging.
"""
def __enter__(self):
return None
import os
import mmap
from contextlib import contextmanager
BLOCK_SIZE = 4 * 1024
@contextmanager
def dopen(filename, blockno=1):
try:
fd = os.open(filename, os.O_CREAT | os.O_DIRECT | os.O_RDWR)
import ctypes
from ctypes import cdll, util
import os
libc = cdll.LoadLibrary(util.find_library('c'))
_get_errno_loc = libc.__errno_location
_get_errno_loc.restype = ctypes.POINTER(ctypes.c_int)
def get_errno():
return _get_errno_loc().contents.value
COMMANDS = {}
def command(f):
COMMANDS[f.__name__] = f
return f
@command
def func1():
print 'func1'
(pep8)clayg@clayg-laptop:~/devenv/sandbox/pep8$ cat test.py
class A(object):
def __init__(self,
blah,
monkies):
self.blah = blah
a = A('monkies',
'yay')
(pep8)clayg@clayg-laptop:~/devenv/sandbox/pep8$ cat test.py
# passes
foo = long_function_name(var_one, var_two,
var_three, var_four)
# passes
def long_function_name(
var_one, var_two,
var_three, var_four):
#!/bin/bash
set -v
aptitude update &> /dev/null
DEBIAN_FRONTEND=noninteractive aptitude install mdadm -y
mdadm --create /dev/md0 --chunk=4096 --level=0 --raid-devices=5 /dev/xvd[e-i]
time dd if=/dev/md0 of=/dev/null iflag=direct bs=4096 count=10240
time dd if=/dev/md0 of=/dev/null iflag=direct bs=65536 count=640
time dd if=/dev/zero of=/dev/md0 oflag=direct bs=4096 count=10240
time dd if=/dev/zero of=/dev/md0 oflag=direct bs=65536 count=640
while !$(mdadm --stop /dev/md0); do