Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View pthom's full-sized avatar

Pascal Thomet pthom

View GitHub Profile
namespace Internal
{
struct SliderAdaptiveInterval
{
float max() const { return pow(10.f, CurrentPower); }
void SetTargetValue(float targetValue)
{
assert (targetValue >= 0.f);
// 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
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)
@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)
@pthom
pthom / test.py
Created September 29, 2022 10:03
def lambda_apriori_ratio_from_interval(value: float, interval: Interval) -> float:
"""
Returns 1 for a value at the center of the interval
Return 1.3 for a value at the border of the interval
i.e the values at the border are multiplied by 1.3
(and are thus less likely to be a minimum)
"""
# x is between -0.5 and 0.5 (0 is the interval center)
x = math_utils.unlerp(interval.Min, interval.Max, value) - 0.5
@pthom
pthom / CLion_Ninja.md
Last active December 21, 2020 07:50 — forked from nevkontakte/CLion_Ninja.md
Ninja support for CLion IDE

Ninja support for CLion IDE

This script enables Ninja-powered builds in CLion IDE by wrapping around CMake, which it uses. See my blog post for details.

Disclaimer

This script is provided AS IS with no guarantees given or responsibilities taken by the author. This script relies on undocumented features of CLion IDE and may lead to instability of build and/or IDE. Use it on your own risk under WTFPL terms.

@pthom
pthom / literate_programming.md
Last active August 1, 2020 21:15
literate_programming_editor

I sometimes dream of a source code editor that would allow inline diagrams and nicele rendered documentation and or equations. This could apply to any language that has support for multiline comments.

For example, a code like this, (where md stands for markdown)

/*md
Square value of *any* type
#include <atomic>
#include <future>
#include <iostream>
class AsyncRaiiExample
{
public:
AsyncRaiiExample() : mStopRequired(false)
{
#include <future>
class MyThreadedCameraCalibComputer
{
public:
struct GuiCalibInfo
{
cv::Mat mImage;
std::string result;
std::string userInstruction;
@pthom
pthom / instructions.md
Last active May 13, 2020 23:19
vcpkg / opencv4: instructions to test the build on android

These instructions were tested on a vanilla linux installation.

  1. Download Android ndk
mkdir ~/Android
cd ~/Android
wget https://dl.google.com/android/repository/android-ndk-r21b-linux-x86_64.zip
unzip android-ndk-r21b-linux-x86_64.zip
# edit the path below if needed