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 / string_buffer.cpp
Last active October 30, 2015 22:52
StringBuffer
/*
(c) 2013 +++ Filip Stoklas, aka FipS, http://www.4FipS.com +++
THIS CODE IS FREE - LICENSED UNDER THE MIT LICENSE
ARTICLE URL: http://forums.4fips.com/viewtopic.php?f=3&t=1075
*/
#include <array>
#include <cassert>
#include <stdarg.h> // va_list
#define WIN32_LEAN_AND_MEAN
@facontidavide
facontidavide / lz4_sample.cpp
Created May 26, 2016 11:08
Simple LZ4 example
#include "lz4.h"
using namespace std;
int main()
{
char szSource[] = "2013-01-07 00:00:04,0.98644,0.98676 2013-01-07 00:01:19,0.98654,0.98676 2013-01-07 00:01:38,0.98644,0.98696";
int nInputSize = sizeof(szSource);
// compress szSource into pchCompressed
@facontidavide
facontidavide / factory.cpp
Last active November 16, 2022 09:16
Factory pattern in C++
#include <iostream>
#include <unordered_map>
#include <functional>
#include <vector>
// Base class
class Shape {
public:
virtual void draw() = 0;
};
#include <atomic>
#include <chrono>
#include <deque>
#include <iostream>
#include <mutex>
#include <future>
#include <thread>
// shared stuff:
std::deque<std::packaged_task<void()>> tasks;
typedef struct{
time_t start_date; end_date;
std::string company_name;
std:.string responsibilities_and_achievements;
} PreviousJob;
typedef struct Candidate{
std::vector<PersonalityTraits> traits;
std::vector<boost::any > skills; // use boost::any as type erasure.
std::vector<PreviousJob> previous_jobs;
@facontidavide
facontidavide / template_check_class_member.cpp
Created November 14, 2016 09:38
When using a template, check if the template argument has a specific method
#include <iostream>
#include <typeinfo>
struct Hello
{
int helloworld() { return 0; }
};
struct Generic {};
@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;
@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 / 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 / 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>