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 / 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 / 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 / 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 / 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 / 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 / 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 / qt2.xml
Created May 4, 2017 09:29
My QtCreator style
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorCodeStyle>
<!-- Written by QtCreator 4.2.1, 2017-05-04T11:28:11. -->
<qtcreator>
<data>
<variable>CodeStyleData</variable>
<valuemap type="QVariantMap">
<value type="bool" key="AlignAssignments">true</value>
<value type="bool" key="AutoSpacesForTabs">false</value>
<value type="bool" key="BindStarToIdentifier">false</value>
@facontidavide
facontidavide / no_bind.cpp
Last active May 4, 2017 08:08
life without std::bind
struct CameraInfo{
// whatever
};
CameraInfo camera_info[5];
void callbackImplementation(CameraInfo& cam_info, const sensor_msgs::Image::ConstPtr& msg)
{
@facontidavide
facontidavide / .clang-format
Created May 2, 2017 14:00
My favourite clang-format
---
BasedOnStyle: Google
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
@facontidavide
facontidavide / ReadWriteSpinLock.h
Created March 8, 2017 12:34
ReadWrite SpinLock
#ifndef RW_SPINLOCK_H
#define RW_SPINLOCK_H
#include<atomic>
#include<cassert>
#define SPIN_LOCK_UNLOCK 0
#define SPIN_LOCK_WRITE_LOCK -1
using std::memory_order_relaxed;