Skip to content

Instantly share code, notes, and snippets.

View dnmiller's full-sized avatar

Dan Miller dnmiller

View GitHub Profile
@dnmiller
dnmiller / nix-on-macos-catalina.md
Last active January 11, 2022 16:11 — forked from chriselsner/nix-on-macos-catalina.md
Nix on macOS Catalina

Nix on macOS Catalina

I'm writing this gist for my own records but it might help someone else too.

Installing Nix

Support for Catalina has improved a lot since the update was first rolled out.

Note: See the NixOS manual for discussion of the --darwin-use-unencrypted-nix-store-volume option.

@dnmiller
dnmiller / endianness.h
Last active October 23, 2020 03:51 — forked from jtbr/endianness.h
cross-platform / cross-compiler standalone endianness conversion
/**
* @file endianness.h
* @brief Convert Endianness of shorts, longs, long longs, regardless of architecture/OS
*
* Defines (without pulling in platform-specific network include headers):
* bswap16, bswap32, bswap64, ntoh16, hton16, ntoh32 hton32, ntoh64, hton64
*
* Should support linux / macos / solaris / windows.
* Supports GCC (on any platform, including embedded), MSVC2015, and clang,
* and should support intel, solaris, and ibm compilers as well.
struct Connection {
void disconnected()
{
m_connection = Disconnected();
}
void interrupted()
{
m_connection = std::visit(InterruptedEvent(*this), m_connection);
}
@dnmiller
dnmiller / Anaconda.sublime-settings
Last active January 13, 2017 23:09
Sublime Text Sync Settings
{
"anaconda_linting": true,
"anaconda_gutter_theme": "alpha",
"anaconda_linter_mark_style": "none",
"pep8_ignore":
[
"E309"
],
}
@dnmiller
dnmiller / error_code_example.cpp
Created April 12, 2016 03:10
Basic demo for std::error_code
// Taken from http://stackoverflow.com/questions/11973798/comparing-an-error-code-enum-with-stderror-code
#include <iostream>
using namespace std;
#include <system_error>
#include <cassert>
namespace mylib
{
namespace errc {
@dnmiller
dnmiller / AutoRegister.cpp
Last active January 31, 2016 05:15
Dynamic registration of message types
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
// Taken from http://stackoverflow.com/questions/2850213
class Message {
protected:
inline Message() {};
@dnmiller
dnmiller / difftest.m
Created August 6, 2015 03:47
Test analytical derivatives
function maxeps = difftest(func, grad, theta, tol)
if nargin < 4 || isempty(tol)
tol = 1e-6;
end
function res = err(d)
fp = func(theta + d);
fm = func(theta - d);
res = max(abs((fp - fm)/2/d - grad(theta)));
@dnmiller
dnmiller / pidift.m
Created April 7, 2015 21:04
Iterative Feedback Tuning
function K = pidift(K, yd, y, u, gamma, lambda, beta)
% K = pidift - Calculate new PID gains from existing gains of a discrete
% PID controller
%
% K = pidift(K, yd, y, u)
%
% Calculate the new PID gains that will move the current system
% response closer to the desired system response. K is a vector of
% the current PID gains, [Kp, Ki, Kd], where the controller structure
% is of the following form:
@dnmiller
dnmiller / gist:8019009
Last active December 31, 2015 17:19
Todo for a fresh Xubuntu install
Fundamentals:
sudo apt-get install \
curl \
wget \
vim-gtk \
build-essential \
libatlas-base-dev \
gfortran \
python-dev \
@dnmiller
dnmiller / GoogleTest.cmake
Last active April 21, 2019 10:08
CMake custom target for adding Python tests and GoogleTest unit tests to compiled libraries. Tests are run via nose.
# Custom cmake target for creating a target using gtest for unit testing.
function(add_gtest_target TARGET_NAME TARGET_LIB)
set(TEST_EXEC _${TARGET_LIB}_test)
# Build the test executable.
add_executable(${TEST_EXEC} ${ARGN})
target_link_libraries(${TEST_EXEC} ${TARGET_LIB})
# gtest was not found with a find_package command and must be linked to