Skip to content

Instantly share code, notes, and snippets.

View bensimner's full-sized avatar

Ben Simner bensimner

  • University of Cambridge
  • Cambridge, UK
View GitHub Profile
@bensimner
bensimner / output
Last active April 11, 2020 22:03
Nedbat's coverage bug
PS C:\...\example> dir
Directory: C:\...\example
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 11/04/2020 22:43 220 test_bad.py
-a---- 11/04/2020 22:43 235 test_good.py
@bensimner
bensimner / future.py
Created March 5, 2020 19:24
asyncio almost-compatible hand-made Future object
import asyncio
class FutIterator:
def __init__(self, fut):
self.fut = fut
def __iter__(self):
return self
import glob
import itertools
with open("rmem.tex", "w") as outf:
outf.write(
r"""
\documentclass{article}
\usepackage[a4paper, margin=0in, left=8mm, top=15mm]{geometry}
\usepackage{listings}
\usepackage{xcolor}
@bensimner
bensimner / sb.py
Created July 24, 2019 08:29
Python store-buffering
from multiprocessing import Process, Manager
from multiprocessing.managers import SharedMemoryManager
import array
T = 200000
def f(X, Y, Out, b):
X, Y = X.buf, Y.buf
@bensimner
bensimner / output.txt
Last active July 22, 2019 15:15
mp shared memory
Process Process-3:
Traceback (most recent call last):
File "/home/bjs/.pyenv/versions/3.9-dev/lib/python3.9/multiprocessing/process.py", line 313, in _bootstrap
self.run()
File "/home/bjs/.pyenv/versions/3.9-dev/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/bjs/Downloads/e4671450a50df5a0648c6dda0c7b642a-3db67c29d8d9e6a6d629c2c016f5853ec22000ed/test.py", line 11, in g
X[0]
File "/home/bjs/.pyenv/versions/3.9-dev/lib/python3.9/multiprocessing/shared_memory.py", line 413, in __getitem__
(v,) = struct.unpack_from(
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <err.h>
int main() {
uint32_t x = 0;
uint64_t c = 0;
@bensimner
bensimner / litmus_self_modifying_thread.c
Last active August 21, 2018 14:17
Self-modifying thread showing cache incoherency on ARMv8-A processors.
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
int main(int argc,char **argv) {
/* IGNORE ...
* this block is needed to change the write protections on the page the asm is written to. */
void* code_block_ptr = &&code;
unsigned int pagesize = getpagesize();
from collections import MutableMapping
class Hashtable(MutableMapping):
def __init__(self, iterable=None):
self._map = [[] for _ in range(10)]
self._size = 0
if iterable is not None:
for (k, v) in iterable:
self[k] = v
@bensimner
bensimner / mcts.fs
Created September 11, 2017 07:04
Monte-Carlo Tree Search for discovering invariant test cases
module MCTS
open System
let rnd = System.Random()
[<AutoOpen>]
module Exprs =
type Expr<'a> =
| Lit of 'a
| Add of Expr<'a> * Expr<'a>
(lambda a0:a0.meta_path.append((type('',(),{'find_module':lambda a1,a2,a3:None if not a2.startswith('_')else print((('fizz' if not int(a2[1:]) % 3 else '')+('buzz' if not int(a2[1:]) % 5 else ''))or str(int(a2[1:])))or type('',(),{'load_module':(lambda a4,a5:a0.modules.update(**{a2:None}))})()})())))(__import__('sys'))
import _1
import _2
import _3
import _4
import _5
import _6
import _7