Skip to content

Instantly share code, notes, and snippets.

@dhet
dhet / Debouncer.java
Created July 7, 2022 15:51
A debouncer written in Java
import lombok.RequiredArgsConstructor;
import lombok.val;
import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.*;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
/**
@dhet
dhet / LenientFutureCollector.java
Last active January 15, 2024 17:34
Wait for the completion of multiple Java Futures or time out
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.*;
import java.util.stream.Collector;
@dhet
dhet / RateLimiter.java
Last active March 29, 2022 10:22
Minimal rate limiter in plain Java
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Deque;
import java.util.concurrent.*;
public class RateLimiter {
private final int invocations;
private final Duration window;
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
@dhet
dhet / secrets.yaml
Last active February 7, 2021 10:04
An Ansible playbook for setting up a host which can run Docker Compose (including an unprivileged service account for deployments)
docker_username: dhetbot
docker_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
33383361346365316566663434303530346663636261653934316366323162616137343464656438
3032616265386530393237663533323834393064343531390a626233353961363632643661376164
65336635366130663266623861613834646232393766396462316365346665613065646638333534
6364373831346235610a366639393163666234643631396464643036623536396335666336343133
6561
@dhet
dhet / tag-sbt.yml
Created May 24, 2020 20:18
Github action for tagging a repo with the project version pulled from SBT (only create tag when the SBT version differs from the previous tag)
name: Create git tag from SBT
on:
push:
branch: master
jobs:
Tag:
runs-on: ubuntu-latest
steps:
@dhet
dhet / cross-compile.md
Last active January 4, 2018 14:56
Cross compile OpenDDS for Raspberry Pi

Install cross compiler

sudo apt install -y build-essential \
  g++-arm-linux-gnueabihf \
  gdb-multiarch

Get OpenDDS

@dhet
dhet / labnote-29-11-24.md
Last active November 29, 2017 16:06
Docker swarm for Raspberry Pi cluster

Challenges

Services are incompatible with the nodes

By default, docker swarm will assume that a service will run on x86 systems and accordingly set the services target platform to amd64. In the case of our raspis, this results in an error ("no suitable node") when inspecting the service execution list. This problem can be circumvented by specifying the --no-resolve-image flag when running docker service create.

Specifying which node a service may run on

In order to specify compatibility between nodes and services two things need to be done

  1. The node needs to be specified with a label. This can be done when running docker node create by specifying the tag --label cam=true. When updating the node: docker node update --label-add cam=true.
  2. The service needs to have a constraint. A constraint may be added via docker service create --constraint 'node.labels.cam==true' .... When updating a node: docker service update --constraint-add 'node.labels.cam==true'

Error: "`memory cgroup

@dhet
dhet / labnote-28-11-24.md
Last active December 1, 2017 10:37
Labnote 28-11-24: Embedded OpenDDS via Linux Containers

Embedded OpenDDS via Linux Containers

Ultimate Goal

Deploy OpenDDS programs within containers running on different Raspberry Pis connected via a LAN switch. The OpenDDS participants need to be able to communicate with each other using RTPS. The programs must be able to use sensor data from sensors connected to the Raspberry Pi's GPIO interface. One participant should make use of the Raspberry Pi's camera.

Test Environment

  • OpenDDS 3.12
  • Three Raspberry Pis v3 Model B
  • Docker 17.11.0-ce