Skip to content

Instantly share code, notes, and snippets.

View ezander's full-sized avatar
🏠
Working from home

Elmar Zander ezander

🏠
Working from home
View GitHub Profile
@gocarlos
gocarlos / Eigen Cheat sheet
Last active February 11, 2024 14:07
Cheat sheet for the linear algebra library Eigen: http://eigen.tuxfamily.org/
// A simple quickref for Eigen. Add anything that's missing.
// Main author: Keir Mierle
#include <Eigen/Dense>
Matrix<double, 3, 3> A; // Fixed rows and cols. Same as Matrix3d.
Matrix<double, 3, Dynamic> B; // Fixed rows, dynamic cols.
Matrix<double, Dynamic, Dynamic> C; // Full dynamic. Same as MatrixXd.
Matrix<double, 3, 3, RowMajor> E; // Row major; default is column-major.
Matrix3f P, Q, R; // 3x3 float matrix.
@adamvduke
adamvduke / BitwiseMagic.c
Created August 29, 2012 00:17
A C function to compute an average without the risk of integer overflow
#include <stdio.h>
/* https://twitter.com/mikeash/status/240471662422810624
* Compute average with no possibility of integer overflow.
* Note: patented in 1996, so you can't use it!
*/
int patentedAverage(int a, int b)
{
int av = (a/2) + (b/2) + (a&b&1);
return av;
@zaius
zaius / background.sh
Created January 16, 2011 23:29
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
@larsch
larsch / PrecompiledHeader.cmake
Last active March 12, 2022 10:49
cmake module for setting up precompiled headers (MSVC & GCC)
# Function for setting up precompiled headers. Usage:
#
# add_library/executable(target
# pchheader.c pchheader.cpp pchheader.h)
#
# add_precompiled_header(target pchheader.h
# [FORCEINCLUDE]
# [SOURCE_C pchheader.c]
# [SOURCE_CXX pchheader.cpp])
#