Skip to content

Instantly share code, notes, and snippets.

View llllllllll's full-sized avatar

Joe Jevnik llllllllll

View GitHub Profile
#!/usr/bin/env python
import os
import statistics
import subprocess
from time import time as _time
class time:
def __init__(self):
self._start = None
@llllllllll
llllllllll / a.pyx
Last active February 1, 2018 19:55
I sure love allocating PyObjects!
"""Tested with:
- cython==0.27.3
- cython==0.25.2
"""
cdef class PairWithConstructor:
cdef int a;
cdef int b;
"""
In [1]: from the_worst_way import why_though
In [2]: import ast
In [3]: code = '''
...: if a == 1 and a == 2 and a == 3:
...: print('ayy')
...: else:
...: print('lmao')
@llllllllll
llllllllll / wut
Created January 3, 2018 08:38
generator qualname
In [1]: def f():
...: def g():
...: yield
...: return g
...:
In [2]: g = f()
In [3]: g().__qualname__
Out[3]: 'f.<locals>.g'
"""
In [1]: class C:
...: __slots__ = 'a', 'b'
...:
In [2]: C.__slots__
Out[2]: ('a', 'b')
In [3]: from deslot import deslot
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:
@llllllllll
llllllllll / constexpr_dict.h
Last active April 15, 2024 13:53
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...>;
>>>> 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
#![feature(use_extern_macros)]
use std::io::Read;
struct State {
program: Vec<u8>,
ipt: usize,
tape: [u8; 30000],
ptr: usize,
control_stack: Vec<usize>,
/** 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>