Skip to content

Instantly share code, notes, and snippets.

@rbtcollins
rbtcollins / syncerror.rs
Created April 26, 2021 21:05
error-chain migration support
/// Inspired by failure::SyncFailure, but not identical.
///
/// SyncError does not grant full safety: it will panic when errors are used
/// across threads (e.g. by threaded error logging libraries). This could be
/// fixed, but as we don't do that within rustup, it is not needed. If using
/// this code elsewhere, just hunt down and remove the unchecked unwraps.
pub struct SyncError<T: 'static> {
inner: Arc<Mutex<T>>,
proxy: Option<CauseProxy<T>>,
pkt-get on eth0
```
[ 171.678486] 373.942625 [3255] netmap_init run mknod /dev/netmap c 10 53 # error 0
[ 171.678530] netmap: loaded module
[ 191.078585] 393.342827 [1190] generic_netmap_attach Created generic NA ffff8801f913b000 (prev (null))
[ 191.112529] 393.376778 [2013] netmap_do_regif lut ffffc90000ffb000 bufs 163840 size 2048
[ 191.112579] 393.376827 [ 390] generic_netmap_register Generic adapter ffff8801f913b000 goes on
[ 191.112615] 393.376862 [ 441] generic_netmap_register RX ring 0 of generic adapter ffff8801f913b000 goes on
[ 191.112652] 393.376897 [ 451] generic_netmap_register TX ring 0 of generic adapter ffff8801f913b000 goes on
[ 191.113897] 393.378080 [ 475] generic_qdisc_init Qdisc #0 initialized with max_len = 1024
@rbtcollins
rbtcollins / __init__.py
Last active April 18, 2016 00:55
using testresources
from testresources import OptimisingTestSuite
def load_tests(standard_tests, module, loader):
# top level directory cached on loader instance
this_dir = os.path.dirname(__file__)
package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
standard_tests.addTests(package_tests)
return OptimisingTestSuite(standard_tests)
from operator import methodcaller
import random
import itertools
def card_values(card):
"""Get the possible values of a card in a blackjack game.
e.g. card_values(0) -> (1, 11)
:return: A tuple of the possible values.
"""
import csv
f = open('income-distribution.csv', 'rt')
l = list(csv.reader(f))
pre = l[5:157]
# top edge, lower edge, %
brackets = [(14000, 0, 0.105), (48000, 14001, 0.175), (70000, 48001, 0.30), (200000, 70001, 0.33)]
total = 0
for (_, people, total_income, _) in pre:
people = float(people)
total_income = float(total_income) * 1000000
class HandleEvent(testtools.StreamResult):
def __init__(self, callback):
self._buffers = {}
self._callback = callback
def status(self, test_id=None, test_status=None, test_tags=None,
runnable=True, file_name=None, file_bytes=None, eof=False,
mime_type=None, route_code=None, timestamp=None):
if not test_id:
return
@rbtcollins
rbtcollins / build-system-abstraction.rst
Last active October 27, 2015 01:38
build system abstraction
PEP

XX

Title

Build system abstraction for pip/conda etc

Version

$Revision$

Last-Modified

$Date$

Author

Robert Collins <rbtcollins@hp.com>, Nathaniel Smith <njs@pobox.com>

Discussions-To

distutils-sig <distutils-sig@python.org>

Status

Draft

Type

Standards Track

Content-Type

text/x-rst

@rbtcollins
rbtcollins / demo.py
Last active February 8, 2018 02:42
Getting at the mystery object
from ctypes import *
pythonapi.PyDict_SetItemString.argtypes=[c_void_p, c_char_p, c_void_p]
class PyObject(Structure):
_fields_ = [("refcnt", c_size_t),
("typeid", c_void_p)]
pythonapi.PyThreadState_GetDict.restype = POINTER(PyObject)
pythonapi.PyDict_SetItemString(c_void_p(id(locals())), b"threaddict", pythonapi.PyThreadState_GetDict())
repr([1])
print(threaddict)
@rbtcollins
rbtcollins / gist:f570a2dd4aa4c0ea0264
Last active August 29, 2015 14:23
Python Monad notes
PyMonad
https://pypi.python.org/pypi/PyMonad/
Doesn't duck type Writer - subclass
class StringWriter(Writer):
logType = str
PyMonads
https://github.com/dustingetz/pymonads
Doesn't duck type Writer:
https://github.com/dustingetz/pymonads/blob/master/writer.py#L6
@rbtcollins
rbtcollins / answers
Created April 22, 2015 10:23
answers to problems
//Copy this over the contents at tddbin.com
//Replace the [] in the assert statements with a functional equivalant
//Reference here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
//Lambda syntax: (x,y) => x + y, works in firefox, try it out :)
function range(start, end, jump) {
jump = jump || 1
if (start && !end)
return actualRange(0, start, jump)
return actualRange(start, end, jump)