Skip to content

Instantly share code, notes, and snippets.

View pthom's full-sized avatar

Pascal Thomet pthom

View GitHub Profile
@pthom
pthom / verbose_function_decorator.py
Last active December 15, 2022 14:19
Python decorator to log function call details (can include: input parameters, output parameters, return value)
import logging
import inspect
def verbose_function(dump_args: bool = True, dump_return: bool = False, dump_args_at_exit: bool = False):
"""
Decorator to print function call details.
This can include:
* input parameters names and effective values
* output parameters (if they were modified by the function)
import numpy as np
import cv2
def overlay_alpha_image_lazy(background_rgb, overlay_rgba, alpha):
# cf https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
# If the destination background is opaque, then
# out_rgb = overlay_rgb * overlay_alpha + background_rgb * (1 - overlay_alpha)
overlay_alpha = overlay_rgba[: , : , 3].astype(np.float) / 255. * alpha
overlay_alpha_3 = np.dstack((overlay_alpha, overlay_alpha, overlay_alpha))
overlay_rgb = overlay_rgba[: , : , : 3].astype(np.float)
// Namespace MyLibrary: an example namespace that will be exported to python as a module
namespace MyLibrary
{
// Types of full screen modes (enum class)
enum class FullScreenMode
{
NoFullScreen,
FullScreen, // Full screen with specified resolution
namespace Internal
{
struct SliderAdaptiveInterval
{
float max() const { return pow(10.f, CurrentPower); }
void SetTargetValue(float targetValue)
{
assert (targetValue >= 0.f);
// Beware, this code does use `<functional>`
// (because I was lazy. It is possible to rewrite the logic in terms of Begin/End)
// It works if the gui function that you pass as a parameter is nicely grouped
// (i.e. ` ImGui::GetItemID` and `ImGui::GetItemRectSize` will return its correct ID and size)
#include "imgui.h"
#include "imgui_internal.h"
#include <unordered_map>
#include <functional>
using VoidFunction = std::function<void()>;