Skip to content

Instantly share code, notes, and snippets.

View llllllllll's full-sized avatar

Joe Jevnik llllllllll

View GitHub Profile
@llllllllll
llllllllll / hook.py
Last active March 23, 2016 22:11
Inject a function call into an existing function (like a breakpoint)
from codetransformer import CodeTransformer, pattern
from codetransformer.patterns import matchany, var, option
from codetransformer.instructions import (
CALL_FUNCTION,
LOAD_CONST,
NOP,
POP_TOP,
POP_JUMP_IF_FALSE,
)
from codetransformer.utils.instance import instance
$ ./ts < ts.c
2016-12-13 14:52:33-0500 #include <stdlib.h>
2016-12-13 14:52:33-0500 #include <stdio.h>
2016-12-13 14:52:33-0500 #include <time.h>
2016-12-13 14:52:33-0500
2016-12-13 14:52:33-0500 int main(void) {
2016-12-13 14:52:33-0500 char c;
2016-12-13 14:52:33-0500 time_t t;
2016-12-13 14:52:33-0500 struct tm *tm;
2016-12-13 14:52:33-0500 char buf[BUFSIZ];
@llllllllll
llllllllll / alist.cc
Created December 23, 2016 02:20
association list for types in C++
#include <type_traits>
#include <utility>
namespace association_list {
template<typename... Ps>
struct alist {};
namespace dispatch {
template<typename A, typename K>
struct lookup {};
"""Example
.. code-block:: python
In [1]: a = Expensive(1, b=2)
In [2]: type(a)
Out[2]: __main__.LazyProxy
In [3]: a.method(3)
/** C++ implementation of a memory arena with no knowledge of the CPython API.
*/
#pragma once
#include <algorithm>
#include <array>
#include <exception>
#include <forward_list>
#include <iterator>
#include <new>
#![feature(use_extern_macros)]
use std::io::Read;
struct State {
program: Vec<u8>,
ipt: usize,
tape: [u8; 30000],
ptr: usize,
control_stack: Vec<usize>,
>>>> platform.python_implementation()
'PyPy'
>>>> sys.version_info
(major=2, minor=7, micro=13, releaselevel='final', serial=42)
>>>> def f():
.... a = 'ayy'
.... def g():
.... cell_set((lambda: a).__closure__[0], 'lmao')
.... g()
.... return a
@llllllllll
llllllllll / constexpr_dict.h
Last active December 3, 2024 08:14
compile-time hashtable for C++17 which supports mixed dtype keys and values
#include <array>
#include <tuple>
#include <type_traits>
#include <utility>
namespace cdict {
template<char... cs>
using string = std::integer_sequence<char, cs...>;
from itertools import chain, repeat
import sys
import types
# byte offsets for structures
if hasattr(sys, 'gettotalrefcount'):
# under PyDEBUG builds
_f_localsplus_offset = 392
_ob_item_offset = 40
else:
"""
In [1]: class C:
...: __slots__ = 'a', 'b'
...:
In [2]: C.__slots__
Out[2]: ('a', 'b')
In [3]: from deslot import deslot