Skip to content

Instantly share code, notes, and snippets.

View rotu's full-sized avatar

Dan Rose rotu

  • Digi Labs
  • Minneapolis, MN
  • 07:38 (UTC -05:00)
View GitHub Profile
@rotu
rotu / CMakeLists.txt
Last active May 2, 2024 23:20
CLion top level ROS2 Workspace CMakeLists
cmake_minimum_required(VERSION 3.14)
project("ROS2 Master")
# usually I put this in a separate file include("/opt/ros/_common/Colcon.cmake")
function(colcon_add_subdirectories)
cmake_parse_arguments(PARSE_ARGV 0 "ARG" "" "BUILD_BASE;BASE_PATHS" "")
message("search criteria: ${ARGV}")
execute_process(COMMAND colcon list
@rotu
rotu / iterators.mjs
Created September 23, 2023 04:54
iterator microbenchmark shootout
const { baseline, bench, run } = await import('https://esm.sh/mitata')
const data = Array.from(Array(1000).map(() => Math.random()))
bench('for {0;<;++} data[i]', () => {
let sum = 0
for (let i = 0; i < data.length; ++i) {
sum += data[i]
}
return sum
@rotu
rotu / MyDataVIew.js
Created September 13, 2023 08:38
Minimal ArrayBufferView compatible with DataVIew methods
// `extends null` isn't necessary but I prefer it.
class BareDataView extends null {
static fromBuffer(...args) {
// construct a new object, passing args to the DataView() constructor
// but use this (i.e. the BareDataView class) to set the prototype
return Reflect.construct(DataView, args, this)
}
}
// Select only the properties we actually want to expose
@rotu
rotu / prettier-multiple.sh
Created May 22, 2023 22:32
prettier multiple files
# list files changed by git (Added or Modified) and tidy them up in prettier
# xargs is a linux thing, but on Windows, can use Gow to get it.
git diff --name-only --diff-filter=AM | xargs -n99 prettier -uw
@rotu
rotu / main.mjs
Created January 17, 2023 20:24
open window and inject module
j = "data:text/javascript,"+encodeURIComponent(`console.log("hello from "+import.meta.url)`)
w = window.open("about:blank")
x1 = await w.eval(`import(${JSON.stringify(j)})`)
x2 = await w.eval(`import(${JSON.stringify(j)})`)
w2 = window.open("about:blank")
y1 = await w2.eval(`import(${JSON.stringify(j)})`)
y2 = await w2.eval(`import(${JSON.stringify(j)})`)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Untitled benchmark</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@rotu
rotu / .envrc
Last active August 23, 2022 08:41
environment setup for ROS 2 development
#!/usr/bin/env bash
# This file is meant to be run by direnv. Direnv will execute your script with bash, even if you're using another shell.
printf '─%.0s' $(seq $(tput cols))
################## CMake Generator (Cmake 3.15+)
# If available, use Ninja buildsystem generator, which is faster
# but Colcon may not show compiler output on a failed build
# if [ -x "$(command -v ninja)" ]; then
@rotu
rotu / pyproject.toml
Last active October 7, 2020 16:25
Poetry Colcon
[tool.poetry]
name = "Colcon"
version = "0.0.1"
description = "Workspace for editing Colcon"
authors = ["Dan Rose <dan@digilabs.io>"]
[tool.poetry.dependencies]
python = "^3.8"
colcon-argcomplete = {git = "https://github.com/colcon/colcon-argcomplete.git"}
colcon-bash = {git = "https://github.com/colcon/colcon-bash.git"}
PREFIX=$PWD/prefix
mkdir $PREFIX
# Fast-CDR
git clone https://github.com/eProsima/Fast-CDR.git
mkdir Fast-CDR/build && cd Fast-CDR/build
cmake .. -DCMAKE_INSTALL_PREFIX="$PREFIX" -DCMAKE_PREFIX_PATH="$PREFIX"
cmake --build . --target install
cd ../..
# generated with `vcs export ~/ros2_ws/src`
repositories:
bno055_driver:
type: git
url: https://github.com/RoverRobotics/bno055_driver.git
version: master
joint_state_publisher:
type: git
url: https://github.com/RoverRobotics-forks/joint_state_publisher.git