Skip to content

Instantly share code, notes, and snippets.

@Bktero
Bktero / MaxSize.hpp
Created March 7, 2018 09:55
[C++14] Get the size of the largest type out of a list of types at compile time
#ifndef MAXSIZE_HPP_
#define MAXSIZE_HPP_
#include <algorithm>
#include <cstddef>
template<class ... Ts>
struct Max {
static_assert(sizeof...(Ts) == 0, "This is the terminal case of the recursion, this assertion shall never fail");
static constexpr std::size_t value = 0;
@Bktero
Bktero / optional_image.cpp
Last active November 20, 2017 21:08
[C++17] Example of std::optional
#include <iostream>
#include <optional>
class Image
{
public:
Image(const std::string& path) : path(path)
{}
std::string getPath()
@Bktero
Bktero / compute_footprint.py
Last active January 14, 2020 09:27
[Python 3] Use objdump to compute the footprint of a set of symbols in an elf file
import re
import sys
def text_contains(text, *patterns):
""" Check if 'text' contains at least one of the strings given in 'patterns'."""
for p in patterns:
if re.search(p, text, re.IGNORECASE):
# One pattern was found so the text contains at least of them
# So it is true that "it contains"
@Bktero
Bktero / birthday.py
Created September 12, 2017 06:35
[Python] Is it your birthday?
from datetime import datetime
from datetime import date
birth = datetime.strptime("08-08-1987", "%d-%m-%Y").date()
today = date.today()
if birth.day == today.day and birth.month == today.month:
age = today.year - birth.year
print("It's your birthday! You're", age,"! : )")
print("Let's celebrate!")
@Bktero
Bktero / LedPanel.hpp
Last active July 27, 2017 07:48
[Qt] Example of QPainter to create a simulator for led panels
#ifndef LEDPANEL_HPP
#define LEDPANEL_HPP
#include <QWidget>
#include <cassert>
#include <QPainter>
class LedPanel : public QWidget
{
@Bktero
Bktero / conversion_operators.cpp
Last active July 27, 2017 07:45
[C++11] Example of conversion operators
#include <iostream>
#include <string>
using namespace std;
class FilePath
{
public:
explicit FilePath(string filename) :
filename_m(filename),
@Bktero
Bktero / elapsed_time.cpp
Last active May 25, 2018 07:45
[C++11] How to measure elapsed time
#include <chrono>
#include <iostream>
#include <thread> // to get sleep_for()
/**
* How to measure elapsed time in C++11.
*
* It uses 'steady_clock' because it is monotonic. Being monotonic means that it cannot decrease so it is the most suitable clock
* for time measurements.
@Bktero
Bktero / barycenter.py
Last active July 27, 2017 07:47
[Python] Compute barycenter
import functools
import operator
points = [100, 66, 33, 0]
weights = [-50, 0, 0, 0]
numerator = functools.reduce(operator.add, [p * w for p, w in zip(points, weights)], 0)
denomimator = functools.reduce(operator.add, weights, 0)
barycenter = numerator / denomimator