Skip to content

Instantly share code, notes, and snippets.

#ifndef PATOMIC_PATOMIC_H
#define PATOMIC_PATOMIC_H
#include <stddef.h>
#include <patomic/types/align.h>
#include <patomic/types/feature_check.h>
#include <patomic/types/ids.h>
#include <patomic/types/ops.h>
#include <patomic/types/memory_order.h>
#include <cstddef>
#include <iterator>
#include <memory>
#include <type_traits>
template <class T, class Derived, bool is_const>
requires std::is_object_v<T>
class random_access_iterator_crtp
{
@doodspav
doodspav / py_eventfd.c
Last active June 17, 2020 09:46
Transparent python wrapper around eventfd syscall
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <errno.h>
#include <stdatomic.h>
#include <stdint.h>
#include <string.h>
#include <sys/eventfd.h>
#include <unistd.h>
class CombinedLoopSemaphore:
__slots__ = ("_sync_sem", "_async_lock", "_sleep_period")
def __init__(self, value: int = 1, process_shared: bool = False, sleep_period: float = 0.01):
# could potentially accept an external semaphore as a param here too?
# should process_shared be stored as an attribute?
# we delegate validating `value` to the chosen semaphore implementation
self._sync_sem = multiprocessing.Semaphore(value) if process_shared else threading.Semaphore(value)
self._async_lock = asyncio.Lock()
@doodspav
doodspav / combined_lock.py
Last active June 13, 2020 21:09
Use a threading or multiprocessing lock/rlock in a coroutine fairly without blocking the event loop
import asyncio
import time
class CombinedLock:
def __init__(self, sync_lock, async_lock) -> None:
self.__sync_lock = sync_lock
self.__async_lock = async_lock
self.__is_locked = False
#ifndef HTTP_GET_HPP
#define HTTP_GET_HPP
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <unistd.h>
#include <algorithm>
#include <concepts>
#include <iterator>
namespace binary::concepts {
/*
* BINARY
* ------
*
* Explicitly Supported Types:
@doodspav
doodspav / io_concepts.hpp
Last active May 14, 2020 20:43
To -> Into and improved comments
namespace io::concepts {
/*
* Concept Inheritance Tree
* ------------------------
*
* INPUT
*
* Readable → ReadableExactly
* ↓ ↓
@doodspav
doodspav / iref.hpp
Last active April 30, 2020 15:29
reference wrapper for iterators
#ifndef TEST_IREF_HPP
#define TEST_IREF_HPP
#include <concepts>
#include <cstdint>
#include <iterator>
#include <memory>
#include <utility>
template <std::input_or_output_iterator It>
#include <iostream>
#include <memory>
#include <string>
template <typename T>
using allocator = std::allocator<T>;
template <typename A>
concept HasAllocatorTraits = requires
{