Skip to content

Instantly share code, notes, and snippets.

View aleneum's full-sized avatar

Alexander Neumann aleneum

View GitHub Profile
@aleneum
aleneum / scan_map.rs
Last active June 18, 2024 17:22
Iterate and store partial results as a new iterator
pub struct ScanMap<I, F, T> {
iter: I,
f: F,
acc: T,
}
impl<I, F, T> ScanMap<I, F, T>
where
I: Iterator,
F: FnMut(&T, I::Item) -> T,
@aleneum
aleneum / async_introspection.py
Last active June 22, 2020 10:02
Testing which introspection functions accepts what kind of awaitable
import asyncio
import inspect
async def async_func():
await asyncio.sleep(1)
@asyncio.coroutine
def decorator_func():
yield from asyncio.sleep(1)
@aleneum
aleneum / example.py
Last active April 10, 2019 15:03
this gist was done to evaluate how django and transitions could work together and is based on work from jxskiss. See his [gist](https://gist.github.com/jxskiss/01816eec9a2b64bae341f4d07f58646e) for more details.
# add the other files to your django app and migrate
# enter django shell with python manage.py shell and execute the following
# I called my app 'issues'; so change issues to your app name in case you choose another one
# there are 5 models which realize state machine bindings to django models in different ways
# Item: add a transitions.Machine instance to each record/item
# ItemSingleton: add each model to a global transitions.Machine
# ItemSingletonSet: Extend transitions.Machine to use set instead of list to store models; this increases look up speed in add_model
# ItemNoMachine: just a minimal model without a state machine (for referencing purposes)
# ItemFysom: add a customized fysom machine to each record/item
@aleneum
aleneum / unload_modules.py
Created November 1, 2016 10:59
Unloads all module related imports from current python session
# unloads all imports from a certain module
def unload_module(name):
dk = []
for k in sys.modules.keys():
if k.startswith(name):
dk.append(k)
for k in dk:
del sys.modules[k]