Skip to content

Instantly share code, notes, and snippets.

View facontidavide's full-sized avatar
🤓
Developing

Davide Faconti facontidavide

🤓
Developing
View GitHub Profile
@facontidavide
facontidavide / Dockerfile
Last active August 21, 2017 04:31
Xenial. Dockerfile for KF5 development + heaptrack + hotspot
FROM ubuntu:xenial
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common locate
RUN add-apt-repository ppa:beineri/opt-qt58-xenial -y
RUN apt-get update
RUN apt-get dist-upgrade -y
RUN apt-get install -y --no-install-recommends build-essential git cmake gettext snapcraft wget apt-utils
@facontidavide
facontidavide / GenericROSPublisher.cpp
Created September 12, 2017 14:48
Generic ROS publisher using ShapeShifter
#include "ros/ros.h"
#include "sensor_msgs/JointState.h"
#include "topic_tools/shape_shifter.h"
#include "ros/message_traits.h"
#include <sstream>
template <typename T>
void SerializeToByteArray(const T& msg, std::vector<uint8_t>& destination_buffer)
{
const uint32_t length = ros::serialization::serializationLength(msg);
@facontidavide
facontidavide / static_or_private.cpp
Created November 6, 2017 19:05
Static variable VS local variable
class FooA
{
public:
FooA(){}
double calculateAnswer(double val)
{
static double prev_val_ = 0;
if( val == 0.0 ) return 0.0;
@facontidavide
facontidavide / MyOwnPartialSortCopy.cpp
Last active November 22, 2017 13:35
Trying (for fun) to re-implement something similar to std::partial_sort_copy
#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
#include <benchmark/benchmark.h>
static std::vector<int> CreateShuffledVector(unsigned n)
{
std::vector<int> vect(n);
for (unsigned i=0; i<n; i++) vect[i] = i;
@facontidavide
facontidavide / my_vector.h
Created January 31, 2018 13:49
std::vector skeleton
// implement std::vector
template <typename T>
class Vector
{
public:
// to keep it simpler, iterators are just T*
typedef T* iterator;
typedef T* reverse_iterator;
@facontidavide
facontidavide / simplistc_matrix_vector_template.h
Last active February 28, 2018 15:16
Used for a programming exercise...
#pragma once
template <typename T>
class Vector
{
public:
Vector(size_t order); // constructor for squared-matrix
Vector(const Vector& other); // copy constructor
~Vector(); //destructor
@facontidavide
facontidavide / signal.cpp
Last active July 16, 2020 12:46
Super Simple Signal Slot implementation in C++ 11
#include <stdio.h>
#include <memory>
#include <functional>
#include <list>
/**
* Super simple Signal/Slop implementation, AKA "Observable pattern".
* The subscriber is active until it goes out of scope or Subscriber::reset() is called.
*/
template <typename... CallableArgs>
@facontidavide
facontidavide / unordered_with_string_view.cpp
Last active June 6, 2023 22:22
Use std::string_view to find() an element in std::unordered_map<string,T>, avoiding potential memory allocations
#include <iostream>
#include <cstring>
#include <unordered_map>
// https://github.com/martinmoene/string-view-lite
#include "string_view.hpp"
template <typename Value>
class StringMap: public std::unordered_map<std::string, Value>
{
public:
@facontidavide
facontidavide / problematic_miltithreading.cpp
Created January 9, 2019 11:03
This simple multithreading C++ may sometimes crash (SIGSEGV) or remain blocked forever inside waitStart. Can you figure out why?
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <atomic>
// The purpose of the this apparently fine application is to make you appreciate thread santizers
// https://clang.llvm.org/docs/ThreadSanitizer.html
class Foo{
@facontidavide
facontidavide / copy_on_write.h
Created January 22, 2019 11:38
Copy on Write utility (from stlab)
/*
Copyright 2013 Adobe
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
/**************************************************************************************************/
#ifndef STLAB_COPY_ON_WRITE_HPP
#define STLAB_COPY_ON_WRITE_HPP