Skip to content

Instantly share code, notes, and snippets.

@qstokkink
qstokkink / main.py
Last active March 4, 2024 10:26
IPv8 online time crawler
import logging
import sys
import time
from asyncio import run
from binascii import hexlify
from pathlib import Path
from ipv8.configuration import ConfigBuilder, WalkerDefinition, Strategy, default_bootstrap_defs
from ipv8.peerdiscovery.community import DiscoveryCommunity
from ipv8.peerdiscovery.network import PeerObserver
@qstokkink
qstokkink / unbound_pony_entity.py
Created January 31, 2024 12:19
An Entity class to inherit from and bind later.
from __future__ import annotations
from typing import Type, TypeVar, cast
from pony.orm import Database
from pony.orm.core import EntityMeta # This is a "secret" import
class UnboundEntityMeta(EntityMeta):
"""
@qstokkink
qstokkink / test_W0621_example.py
Last active January 11, 2024 07:23
How pytest fixtures + redefined-outer-name (W0621) can be dangerous
"""
In this example we have the `important_protection` fixture,
that SHOULD be called. It triggers "redefined-outer-name (W0621)" and
"Redefining name '...' from outer scope".
This example shows that two types of errors could have been prevented
by following the suggested Pylint definition, instead of ignoring the
warning.
## The suggested definition
@qstokkink
qstokkink / tcp_over_ipv8.py
Created December 25, 2023 12:55
Default asyncio TCP over IPv8 example
from __future__ import annotations
from asyncio import StreamReader, StreamWriter, StreamReaderProtocol, get_running_loop, Transport
from typing import Mapping, Any
from ipv8.community import Community
from ipv8.messaging.lazy_payload import vp_compile, VariablePayload
from ipv8.peer import Peer
@qstokkink
qstokkink / pydepfindver.py
Created January 28, 2022 19:36
Python Dependency Find Version
"""
Python Dependency Find Version (pydepfindver.py)
=============================================
Brute force all known versions of your pip dependencies to see which ones work for your project.
- Includes html report functionality.
- Stores (intermediate) results in files so you can resume or quickly update for new releases of dependencies.
- Uses venv.
An example for https://github.com/Tribler/py-ipv8:
@qstokkink
qstokkink / overlay_tutorial1.py
Created October 3, 2020 07:35
Documentation checks
from asyncio import ensure_future, get_event_loop
from pyipv8.ipv8_service import IPv8
from pyipv8.ipv8.configuration import get_default_configuration
async def start_ipv8():
# Create an IPv8 object with the default settings.
ipv8 = IPv8(get_default_configuration())
await ipv8.start()
@qstokkink
qstokkink / attestation_tutorial_attest.py
Created October 3, 2020 07:31
Attestation test scripts
import os
import shutil
from attestation_tutorial_common import finish, http_get, http_post, start, urlstr, wait_for_list
# Remove the output of previous experiments.
if os.path.exists('./state_1'):
shutil.rmtree('./state_1')
if os.path.exists('./state_2'):
shutil.rmtree('./state_2')
@qstokkink
qstokkink / attestation_tutorial_attest.py
Created October 3, 2020 07:24
Deprecated Attestation test scripts
import os
import shutil
from attestation_tutorial_common import finish, http_get, http_post, start, urlstr, wait_for_list
# Remove the output of previous experiments.
if os.path.exists('./state_1'):
shutil.rmtree('./state_1')
if os.path.exists('./state_2'):
shutil.rmtree('./state_2')
@qstokkink
qstokkink / string.py
Last active March 8, 2019 09:04
No-character-mapping-nonsense Python2/3 String class
import six
from six.moves import xrange
class String(six.text_type):
@staticmethod
def as_raw_unicode(value=u""):
if isinstance(value, six.text_type):
return value
@qstokkink
qstokkink / opcodereader.py
Created December 19, 2018 18:18
Convert a given lambda function's body to a human readable format (does NOT support all Python bytecode)
import dis, os, struct, sys
from six import integer_types
unary_ops = {
'UNARY_POSITIVE': '+%s',
'UNARY_NEGATIVE': '-%s',
'UNARY_NOT': 'not %s',
'UNARY_CONVERT': '`%s`',