Skip to content

Instantly share code, notes, and snippets.

@xaedes
xaedes / poly2fit_from_3points.py
Created August 11, 2018 16:44
Fast quadratic polynomial fit from three points
def poly2fit_from_3points(xs,ys):
# p0,p1,p2
# quadratic function:
# y=a*x*x + b*x + c
#
# [1] p0y=a*p0x*p0x + b*p0x + c
# [2] p1y=a*p1x*p1x + b*p1x + c
# [3] p2y=a*p2x*p2x + b*p2x + c
# [4] isolate c in [1]: c = p0y - a*p0x*p0x - b*p0x
# [5] insert [4]c in [2]: p1y = a*p1x*p1x + b*p1x + p0y - a*p0x*p0x - b*p0x
@xaedes
xaedes / ResamplingSyncPolicy.h
Created June 30, 2018 17:34
ros resampling sync policy
#pragma once
#include "message_filters/synchronizer.h"
#include "message_filters/connection.h"
#include "message_filters/null_types.h"
#include "message_filters/signal9.h"
#include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
@xaedes
xaedes / uml2-activity-diagram.tex
Last active May 31, 2018 20:35
UML2 Activity Diagram with Tikz in Latex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[T1]{fontenc}
%\usepackage{fontspec}
% http://www.texample.net/tikz/examples/diagram-chains/
\usetikzlibrary{%
arrows,%
calc,
shapes,
@xaedes
xaedes / threeruleslogic.py
Created February 25, 2018 11:46
threeruleslogic
# solution for 9gag.com/gag/a1oXmYw
def match(c1,c2):
intersection = set(c1).intersection(set(c2))
match_result = []
for digit in intersection:
idxs1 = [k for k,d in enumerate(c1) if digit==d]
idxs2 = [k for k,d in enumerate(c2) if digit==d]
for i in idxs1:
for k in idxs2:
@xaedes
xaedes / Callback.cpp
Created January 11, 2018 12:14
Callback.cpp
// Example program
#include <iostream>
#include <string>
#include <functional>
struct PipedBuffer
{
int bufSize;
};
// Example program
#include <iostream>
#include <string>
#include <ostream>
template<typename T>
class Maybe
{
public:
@xaedes
xaedes / Maybe.hpp
Created October 5, 2017 14:45
Maybe<T> statically typed and allocated Maybe type for C++
template<typename T>
class Maybe
{
public:
static Maybe Just(const T& just)
{
return Maybe(just);
}
static Maybe Just()
@xaedes
xaedes / removeExistingStowTargetFiles.sh
Created June 23, 2017 18:20
Remove existing stow target files
#!/bin/sh
# iterate over all packages
for package in */ ; do
# go to stow package and remove all existing target files
cd $package > /dev/null
find . -type f -print0 | xargs -0 -i rm $(pwd)/../../{}
cd - > /dev/null
done
@xaedes
xaedes / EqualsMat.hpp
Created May 27, 2017 15:57
Catch.hpp Matcher for cv::Mat
#include <opencv2/opencv.hpp>
#include "catch/catch.hpp"
// The matcher class
class MatMatcher : public Catch::MatcherBase<cv::Mat>
{
public:
MatMatcher(cv::Mat mat)
: m_mat(mat)
@xaedes
xaedes / benchmark_ptrs.cpp
Created May 24, 2017 13:17
benchmark ptr access
#include <memory>
#include <iostream>
#include "common/measureTime.h"
using namespace common;
int main(int argc, char* argv[])
{
int n = 100000000;