Skip to content

Instantly share code, notes, and snippets.

Avatar
🌊

Tom Lankhorst tomlankhorst

🌊
View GitHub Profile
@tomlankhorst
tomlankhorst / mqtt-demo.cpp
Created May 11, 2021
MQTT mosquitto demo (with fmt/7.1.3 mosquitto/2.0.10)
View mqtt-demo.cpp
#include <iostream>
#include <csignal>
#include <thread>
#include <chrono>
#include <string_view>
#include <fmt/core.h>
#include <fmt/color.h>
#include <mosquitto.h>
#include <openssl/ssl.h>
@tomlankhorst
tomlankhorst / libpqxx_boost_uuid.hpp
Last active Apr 19, 2021
Basic support for `boost::uuids::uuid` in `libpqxx` 7.4
View libpqxx_boost_uuid.hpp
#pragma once
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
/**
* This snippet implements basic string conversion support for `boost::uuids::uuid`
* in libpqxx.
*
View decay_optional.hpp
template<typename T>
struct decay_optional {
using type = T;
};
template<typename T>
struct decay_optional<std::optional<T>> {
using type = T;
};
@tomlankhorst
tomlankhorst / rebind-usb.sh
Created Oct 31, 2020
Re-bind XHCI driver to make USB devices responsive again after a wakeup. https://tomlankhorst.nl/unresponsive-usb-unbind-bind-linux
View rebind-usb.sh
#!/bin/bash
# See https://tomlankhorst.nl/unresponsive-usb-unbind-bind-linux
DEV=${1:-0000:06:00.3}
echo $DEV | sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind
sleep 1
echo $DEV | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind
@tomlankhorst
tomlankhorst / talker_listener_ros.launch
Last active Jun 3, 2020
Launch ROS nodes in a docker container (roscpp_tutorial/talker_listener). This example uses host networking, but creating a network and setting the ROS_MASTER_URI should work just as well. See: https://github.com/ros/ros_tutorials/tree/melodic-devel/roscpp_tutorials https://hub.docker.com/_/ros/
View talker_listener_ros.launch
<launch>
<node launch-prefix="docker run --rm --name listener -v$HOME:$HOME -u$UID --privileged --net=host -eROS_HOME=$ROS_HOME ros:melodic-ros-base-bionic" name="listener" pkg="roscpp_tutorials" type="listener" output="screen"/>
<node launch-prefix="docker run --rm --name talker -v$HOME:$HOME -u$UID --privileged --net=host -eROS_HOME=$ROS_HOME ros:melodic-ros-base-bionic" name="talker" pkg="roscpp_tutorials" type="talker" output="screen"/>
</launch>
@tomlankhorst
tomlankhorst / thanks
Last active Apr 29, 2020
Thanks! Star the current GitHub repository.
View thanks
#!/usr/bin/env python3
import os
import re
import requests
from subprocess import check_output
github_origin_re = r"^(git@github\.com:|https:\/\/github.com\/)([\w\-_]+)\/([\w\-_]+)\.git$"
try:
View apache-cors-site.conf
<VirtualHost *:443>
ServerName service.com
# Set CORS headers to allow XHR
# Determine if Origin matches the regex
SetEnvIf Origin "http(s)?://(www.api-client.com|beta.api-client.com:8000)$" AccessControlAllowOrigin=$0
# Set Access-Control-Allow-Origin if the Origin is allowd
Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header always set Access-Control-Allow-Credentials true
Header always set Access-Control-Allow-Headers "Origin, Authorization, Accept"
View trigger.groovy
// https://javadoc.jenkins.io/jenkins/model/Jenkins.html#getItemByFullName-java.lang.String-
def organization = Hudson.instance.getItemByFullName('my_organization')
if (!organization) throw new Exception("No organization by that name")
// https://javadoc.jenkins.io/plugin/cloudbees-folder/com/cloudbees/hudson/plugins/folder/AbstractFolder.html#getItems--
def jobs = organization.getItems()
jobs.each {
// find the sub-job that's named "master"
// https://javadoc.jenkins.io/hudson/model/Item.html#getName--
master = it.items.find { it.getName() == "master" }
@tomlankhorst
tomlankhorst / authorized_keys.sh
Created Mar 21, 2020
AuthorizedKeysCommand that appends a public list of keys to the user's list.
View authorized_keys.sh
#!/bin/bash
# USE AT OWN RISK
# Current user
USER=$1
HOME=$(eval echo ~$USER)
# Base keys
cat $HOME/.ssh/authorized_keys
@tomlankhorst
tomlankhorst / docker-swarm-gpu.md
Last active Jul 1, 2022
Instructions for Docker swarm with GPUs
View docker-swarm-gpu.md