Skip to content

Instantly share code, notes, and snippets.

@bfueldner
bfueldner / gist:ec3169a01c924a8cf3ed4e935434c4ed
Created March 18, 2021 11:35 — forked from RhysU/gist:5281465
Using Boost Spirit 2.1+ to evaluate constant arithmetic expressions. See http://agentzlerich.blogspot.com/2011/06/using-boost-spirit-21-to-evaluate.html
//--------------------------------------------------------------------------
//
// Copyright (C) 2011, 2012, 2013 Rhys Ulerich
// Copyright (C) 2012, 2013 The PECOS Development Team
// Please see http://pecos.ices.utexas.edu for more information on PECOS.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
@bfueldner
bfueldner / template_functor_parameter.cpp
Created July 6, 2016 11:13
Template with functor parameter.
struct linear
{
int operator()(const int value) const
{
return value;
}
};
struct logarithmic
{
@bfueldner
bfueldner / embedded_variadic.hpp
Last active July 1, 2016 07:44
Set alternate pin function on STM32F4xx with variadic template
/* Usage: function<PA2::usart2_tx, PA3::usart2_rx>(); */
enum class alternate_t
{
AF0 = 0x0,
AF1 = 0x1,
AF2 = 0x2,
AF3 = 0x3,
AF4 = 0x4,
AF5 = 0x5,
@bfueldner
bfueldner / specialization.cpp
Last active November 12, 2015 22:45
Template specialization
#include <iostream>
#define FLOAT_VALIDATOR_
template<typename T>
struct validator
{
static const bool has_validator = false;
bool operator()(const T value) const
{
@bfueldner
bfueldner / callback.cpp
Created October 8, 2015 22:05
Callback with C++ class
#include <iostream>
#include <vector>
struct callback_interface
{
virtual void callback() = 0;
};
typedef std::pair<callback_interface *, int> callback_timeout;
@bfueldner
bfueldner / dict_rep.py
Last active August 29, 2015 14:21
Replace keywords in string from dict
import re
ifile = open("smybol.txt, "r")
data = ifile.read()
ifile.close()
map = {}
map["DEVICE"] = "Resistor"
map["VALUE"] = "10k"
@bfueldner
bfueldner / meta.py
Created May 12, 2015 22:16
Automatic class registration using metaclass
#!/usr/bin/python
reg = {}
class metaclass_register(type):
def __init__(cls, name, bases, nmspc):
super(metaclass_register, cls).__init__(name, bases, nmspc)
reg[name] = cls
class class1(object):
@bfueldner
bfueldner / isr_template.cpp
Last active August 29, 2015 14:10
C++ interrupt service routine using templates
#include <iostream>
using namespace std;
typedef void (*callback)(void);
struct timer1_tag {};
struct timer2_tag {};
static callback isr_vector[8];