Skip to content

Instantly share code, notes, and snippets.

#lang racket
;; Conways PRIMEGAME
;; https://en.wikipedia.org/wiki/FRACTRAN
(define primegame-seq (list (/ 17 91) (/ 78 85) (/ 19 51) (/ 23 38) (/ 29 33) (/ 77 29) (/ 95 23) (/ 77 19) (/ 1 17) (/ 11 13) (/ 13 11) (/ 15 2) (/ 1 7) (/ 55 1)))
(define (calc-next-int num)
(define (iter num seq)
(let ((a (* num (first seq))))
@LukasWoodtli
LukasWoodtli / multi_dim_array.c
Created December 26, 2017 22:08
Example of multidimensional array in C/C++
#include <stdio.h>
/* Multidimensional arrays are stored with the last index as least significant,
i.e. changing fastest.
from: http://www.agner.org/optimize/calling_conventions.pdf */
#define x_dim 5
#define y_dim 3
int array[x_dim][y_dim]= {{1, 2, 3},
{4, 5, 6},
clear
graphics_toolkit('qt')
# 2D Graph
x = [-10:0.1:10];
y = 50*sin(x).+x.^2+x;
figure(1)
plot(x,y, "linewidth", 2)
grid
# Example for a include-what-you-use mapping
[
{ include: ["<bits/std_function.h>", private, "<functional>", public ] },
{ include: ["<bits/shared_ptr.h>", private, "<memory>", public] },
{ include: ["<boost/asio/ip/impl/address.ipp>", private, "<boost/asio/ip/address.hpp>", public] },
{ include: ["<ext/alloc_traits.h>", private, "<type_traits>", public] },
{ include: ["<bits/exception.h>", private, "<exception>", public ] },
{ include: ["<boost/asio/detail/impl/reactive_socket_service_base.ipp>", private, "<boost/asio/socket_base.hpp>", public] },
# Use regex with '@' at the beginning
{ include: ["@<boost/signals2/detail/.*>", private, "<boost/signals2.hpp>", public] },
@LukasWoodtli
LukasWoodtli / doxyfy_comments.py
Last active February 18, 2019 13:52
Filter for doxygen that converts normat comments to doxygen style comments in C/C++
#!/usr/bin/env python
import sys
filename = sys.argv[1]
f = open(filename, 'r')
data = f.read()
@LukasWoodtli
LukasWoodtli / CMakeGraphVizOptions.cmake
Last active October 21, 2023 00:02
How to produce dependency graphs from cmake
# put this file in the top source dir (CMAKE_SOURCE_DIR)
# see: https://cmake.org/cmake/help/latest/module/CMakeGraphVizOptions.html
set(GRAPHVIZ_EXTERNAL_LIBS FALSE)
# only dependencies between libraries
set(GRAPHVIZ_EXECUTABLES FALSE)
#!/bin/bash
# If scan-build (clang static analyzer) can't analyze the code properly
# setting the analyzer implizitely can help
analyzerPath=$(realpath "$(dirname $(which clang))/../libexec")
cmake -G Ninja \
-DCMAKE_CXX_COMPILER="$analyzerPath/c++-analyzer" \
-DCMAKE_C_COMPILER="$analyzerPath/ccc-analyzer" \
@LukasWoodtli
LukasWoodtli / ros_docker_init.sh
Created May 9, 2019 20:36
Run ROS from a Docker container with X11 support
#!/bin/bash
source /ros_entrypoint.sh
ip=$(hostname -I)
export ROS_IP=$ip
export ROS_MASTER_URI=http://172.17.0.2:11311
echo $ROS_IP
echo $ROS_MASTER_URI
bash
@LukasWoodtli
LukasWoodtli / setDoneDate
Created June 11, 2019 11:39
Google sheets onEdit callback example
// add this to the script editor in google sheets
// this hook is called when a table (cell) is edited
function onEdit(e) {
// get the sheet that is worked on
var s = SpreadsheetApp.getActiveSheet();
// cell that is edited
var r = s.getActiveCell();
// uncomment for some messages for debugging
//Browser.msgBox(e.range.getColumn());
//Browser.msgBox(s.getName());
@LukasWoodtli
LukasWoodtli / Approvals.cmake
Created April 15, 2020 11:04
Some testing functionality for CMake files. Inspired by ApprovalTests
## Diffs two files. Aborts if the diff fails
function(diff_files file_a file_b)
execute_process(COMMAND diff ${file_a} ${file_b}
RESULT_VARIABLE DIFF_RESULT)
if (DIFF_RESULT)
execute_process(COMMAND meld "${file_a}" "${file_b}")
message(FATAL_ERROR "Diffing failed: ${file_a} ${file_b}")
else()
message("Successful diff: ${file_a} ${file_b}")