Skip to content

Instantly share code, notes, and snippets.

View rotu's full-sized avatar

Dan Rose rotu

  • Digi Labs
  • Minneapolis, MN
  • 09:37 (UTC -06:00)
View GitHub Profile
@rotu
rotu / iterator.bench.js
Last active October 28, 2024 02:12
Array of object iteration strategies, benchmarked
import { assert } from 'jsr:@std/assert'
const COUNT = 8
const ar = []
for (let i = 0; i < COUNT; ++i) {
ar.push({ x: Math.random() * 1000 })
}
const sum = ar.reduce((a, obj) => (a + obj.x), 0)
function mapX() {
@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 / 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 <[email protected]>"]
[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 ../..
enum Foo1 {
Bar1=1,
Baz1
#ifdef _MSC_VER
#pragma deprecated(Baz1)
#else
__attribute__ ((deprecated("Use something else")))
#endif
= 2,
Bang1=3,
repositories:
ament/ament_cmake:
type: git
url: https://github.com/ament/ament_cmake.git
version: master
ament/ament_index:
type: git
url: https://github.com/ament/ament_index.git
version: master
ament/ament_lint: