Skip to content

Instantly share code, notes, and snippets.

@markshannon
markshannon / dynattr.py
Created November 29, 2014 20:31
Pure Python module with dynamic attributes.
import sys
original = sys.modules[__name__]
class M(object):
__class__ = type(original)
#Define __str__, __repr__, etc. here
diff -r aa2517e9f9ce Lib/importlib/__init__.py
--- a/Lib/importlib/__init__.py Thu Jul 30 00:04:11 2015 +0300
+++ b/Lib/importlib/__init__.py Fri Sep 04 22:14:03 2015 +0100
@@ -135,12 +135,13 @@
The module must have been successfully imported before.
"""
- if not module or not isinstance(module, types.ModuleType):
- raise TypeError("reload() argument must be module")
try:
@markshannon
markshannon / dynattr.py
Created November 30, 2014 22:06
Dynamic attribute module
import sys
import warnings
from types import ModuleType
from importlib import import_module
try:
basestring
except NameError:
basestring = str
@markshannon
markshannon / waves.py
Created January 13, 2016 22:15
Supposed test case for GC failure.
""" Display endless waves on the LED display.
You can press the left button to have the waves go faster,
the right button to slow down things.
MAL 2016-01-06.
"""
import microbit
import math
class Voice:
def __init__(self, **config_options):
self.config(config_options)
def say(phonemes):
# This returns a generator (or C implemented iterator) of audio frames
...
:020000040000FA
:10000000004000208D590100C9590100CB59010061
:1000100000000000000000000000000000000000E0
:10002000000000000000000000000000CD590100A9
:100030000000000000000000CF590100D15901006C
:10004000D3590100E914010095550100D35901006D
:10005000D359010000000000C1910100D3590100F3
:10006000AD100000D35901000D940100D3590100D7
:10007000D3590100D3590100D3590100D3590100CC
:10008000D359010081520100D3590100D359010015

Taint tracking in Python

Overview

Taint tracking tracks how arbitrary values, "taint", flow throughout the program. This is useful for finding whether potentially malicious input can be used in an insecure way, whether dangerous arguments are passed to vulnerable functions, and whether confidential or sensitive data can leak. It is also useful for tracking invalid, insecure, or untrusted data in other analyses.

// Extending taint-tracking to support tracking through iteration is a bit fiddly prior in 1.20 and earlier
// We need to track both getting an item from the iterable *and* the assignment to the target variable.
/* Track the implicit `next` operation */
class NextItemExtension extends DataFlow::Extension {
ForNode for;
NextItemExtension() {
for.iterates(_, this)

range.sh

#!/bin/sh

PYTHON=python3

${PYTHON} -c 'from sys import version; print(version)'

timeit()

2021-05-21_09-57-master-b11a951f16f0.json.gz

Performance version: 1.0.0 Report on Linux-5.4.0-73-generic-x86_64-with-glibc2.31 Number of logical CPUs: 12 Start date: 2021-05-26 11:01:17.817118 End date: 2021-05-26 11:19:49.454870

2021-05-26_08-53-master-a316f34dd8dc.json.gz