Skip to content

Instantly share code, notes, and snippets.

@Bktero
Bktero / main.css
Created July 1, 2019 12:17
[HTML/CSS/JS] HandleBarJS example
* {
font-family: 'Roboto', sans-serif;
font-weight: normal;
}
button.open {
display: inline-block;
width: 4rem;
height: 2rem;
@Bktero
Bktero / demangle_name.cpp
Last active December 15, 2023 09:50
[C++] Demangling type name so that it is human-readable
#include <cxxabi.h>
#include <iostream>
#include <typeinfo>
// http://en.cppreference.com/w/cpp/types/type_info/name
// https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
template<typename T>
void sayMyName() {
auto name = typeid(T).name();
@Bktero
Bktero / numpy_array_to_from_file.py
Created February 22, 2019 08:27
[Python] Use Numpy and Matplotlib to save data to a file and load these data to plot them
import os.path
import matplotlib.pyplot as plt
import numpy as np
FILENAME = 'data.txt'
SEPARATOR = '\n'
# Data can be generated with any tool as long as the format is good
# Create one to show the format of the file
@Bktero
Bktero / CMakeLists.txt
Created December 10, 2018 14:35
[C++][Python] Create Python module with C++ and boost::python
cmake_minimum_required(VERSION 3.10)
project(Boost_Python_Example)
# Find Boost
find_package(Boost COMPONENTS python3)
# Find Python
find_package(PythonInterp 3 REQUIRED)
find_package(PythonLibs 3 REQUIRED)
@Bktero
Bktero / example.bat
Created November 22, 2018 13:34
[BAT] Test the result of a command in a Windows BAT script
@echo off
ping %1
if %ERRORLEVEL% NEQ 0 (
echo *** ERRORLEVEL = %ERRORLEVEL% ***
goto failure
)
:success
@Bktero
Bktero / live_graph.py
Last active April 25, 2023 05:12
[Python] Live graph with matplotlib
import datetime
import random
import matplotlib.animation as animation
import matplotlib.pyplot as plt
def read_temperature():
"""Read temperature (stub here of course)
@Bktero
Bktero / sizeof_compile_time.c
Last active March 23, 2024 23:45
[C][C++] Print size of type at compile time
char (*__kaboom)[sizeof( xxx )] = 1;
// xxx can be a variable or a data type
// See https://stackoverflow.com/questions/20979565/how-can-i-print-the-result-of-sizeof-at-compile-time-in-c
// Exemple of code:
// char (*__kaboom)[sizeof( long long )] = 1;
// GCC error:
// error: invalid conversion from 'int' to 'char (*)[8]' [-fpermissive]
// So sizeof(long long) == 8
@Bktero
Bktero / main.cpp
Last active July 27, 2018 10:44
[C++17] Example of std::variant to execute various type of request on a SPI bus
#include <cassert>
#include <cstdint>
#include <variant>
struct ReadRequest {
ReadRequest(std::uint8_t* data, std::size_t length) :
data(data),
length(length) {
assert(data != nullptr);
}
@Bktero
Bktero / producer_consumer_threads.cpp
Last active May 30, 2018 07:32
[C++11] Example of producer/consumer threads sharing data thanks to a queue protected by a mutex
#include <iostream>
#include <mutex>
#include <queue>
#include <sstream>
#include <thread>
int main(int, char*[]) {
std::queue<std::string> queue;
std::mutex mutex;
@Bktero
Bktero / class__str__.py
Last active January 10, 2023 20:30
[Python] Generic __str__ method for a Python class
def __str__(self):
elements = []
for key, value in self.__dict__.items():
elements.append("{key}='{value}'".format(key=key, value=value))
return ', '.join(elements)