Skip to content

Instantly share code, notes, and snippets.

@donaldmunro
donaldmunro / math-SKILL.md
Created October 14, 2026 19:54
SKILL for mathematical text output formatting from AI
name math-formatting
description Rules for writing mathematical notation in responses using Markdown LaTeX ($...$ inline, $$...$$ display) instead of Unicode math symbols. Use this skill whenever a response will contain any mathematics at all — equations, formulas, derivations, proofs, probability, statistics, calculus, linear algebra, complexity bounds, physics, or even a single symbol like ≤, ∑ or x². Use it even when the math is incidental to a coding, data, or engineering question, and even when the user doesn't mention formatting.

Math formatting

Write all mathematical notation as Markdown LaTeX. The reason: LaTeX renders cleanly and consistently, is unambiguous, and can be copied straight into a paper, notebook, or .tex file. Unicode math characters (∑, ≤, ℝ, x², →) look

clear_vars
reset()
%display latex

u,v,w,T = SR.var('x y z t')
E_x,E_y,E_z  = function('Ex'),function('Ey'), function('Ez')
B_x,B_y,B_z  = function('Bx'),function('By'), function('Bz')
M.<t, x, y, z> = manifolds.Minkowski(positive_spacelike=False)
F = M.diff_form(2, name='F')
@donaldmunro
donaldmunro / euclidean_forms.md
Last active August 3, 2021 22:44
Differential Forms on simple Euclidean manifolds using SageMath Manifolds package
clear_vars
reset()
%display latex
R3 = Manifold(3, 'R^3', start_index=1)
X.<x,y,z> = R3.chart()
g = R3.metric('g')
g[1,1], g[2,2], g[3,3] = 1, 1, 1

#R2 = Manifold(2, 'R^2', ambient=R3, start_index=1)
@donaldmunro
donaldmunro / bounded_map.h
Created January 26, 2019 22:58
A wrapped std::multimap which limits size by removing the smallest keys first. Useful for timestamped data where the oldest items (smallest timestamps) can be removed.
#ifndef _BOUNDED_MAP_H
#define _BOUNDED_MAP_H
#include <iostream>
#include <map>
#include <vector>
#include <utility>
/**
* A wrapped std::multimap which limits size by removing the smallest keys first.
# Using javah to generate .h files for Kotlin
# Assuming JNI function calls are in MainActivity.companion
STUDIO=/opt/android-studio
PACKAGE=my.package
$STUDIO/jre/bin/javah -jni -cp "$STUDIO/lib/kotlin-runtime.jar:build/tmp/kotlin-classes/debug" $PACKAGE.MainActivity.Companion
@donaldmunro
donaldmunro / boost-android.md
Last active November 25, 2024 07:35
Compile Boost for Android

Compiling Boost for Android

  1. Download Boost and cd to base directory.

  2. Create Android toolchains for desired architectures by running a script as below:

    NDK=/opt/android-sdk/ndk-bundle/
    TOOLCHAINS="$PWD/toolchains/"

rm -rf $TOOLCHAINS

@donaldmunro
donaldmunro / gist:a2a0a061de498b9dc0ec10be309de2b7
Created March 5, 2017 14:05
Access/dereference glm::mat4 contents
#include <glm/gtc/type_ptr.hpp>
..
glm::mat4 m = glm::mat4(1.0f);
..
auto p = glm::value_ptr(m);
std::cout << sizeof(p) << std::endl;
glUniformMatrix4fv(shader_uniform_m, 1, GL_FALSE, p);
@donaldmunro
donaldmunro / gist:38841d72c65a1c32f2bf83a4a00a2c9a
Created March 5, 2017 13:26
Display/print a GLM mat or vec
#include <glm/gtx/string_cast.hpp>
..
..
glm::mat4 mat;
..
..
std::cout << glm::to_string(mat) << std::endl;
@donaldmunro
donaldmunro / gist:afa2f57bd4e52aa3cc0e3bbe422c889e
Created February 25, 2017 21:11
Parse delimited string in C++
size_t split(std::string s, std::vector<std::string>& tokens,
std::string delim ="\t\n ")
{
tokens.clear();
size_t pos = s.find_first_not_of(delim);
while (pos != std::string::npos)
{
size_t next = s.find_first_of(delim, pos);
if (pos == std::string::npos)
tokens.emplace_back(s.substr(pos));
@donaldmunro
donaldmunro / gist:beb7f226adf9c585c67f2599384e43ab
Created February 24, 2017 16:58
Map OpenCv Mat to Eigen Matrix and calculate Eigenvectors
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Eigenvalues>
..
..
using RowMatrixXf = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
Eigen::Map<RowMatrixXf> mapped(extended_homograpy.ptr<float>(), homography.rows, homography.cols);
Eigen::EigenSolver<Eigen::MatrixXf> eigen_solve(mapped, true);
auto ev = eigen_solve.eigenvectors();
std::cout << "No of EigenVectors = " << ev.cols() << std::endl;
for (auto i=0; i<ev.cols(); i++)