Skip to content

Instantly share code, notes, and snippets.

View tomlankhorst's full-sized avatar
🌊

Tom Lankhorst tomlankhorst

🌊
View GitHub Profile
@tomlankhorst
tomlankhorst / docker-swarm-gpu.md
Last active March 24, 2024 22:10
Instructions for Docker swarm with GPUs
@tomlankhorst
tomlankhorst / nginx.conf
Last active May 29, 2022 02:47
Containerised NGINX config for HTTPS with HTTP/2 with Let's Encrypt certificates. https://tomlankhorst.nl/secure-nginx-docker-container-with-lets-encrypt/
# Used on nginx/1.15.5
# https://tomlankhorst.nl/secure-nginx-docker-container-with-lets-encrypt/
#
# see: https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.15.5a&openssl=1.0.1e&hsts=yes&profile=modern
# Oldest compatible clients: Firefox 27, Chrome 30, IE 11 on Windows 7, Edge, Opera 17, Safari 9, Android 5.0, and Java 8
server {
listen 80 default_server;
root /application/public/;
@tomlankhorst
tomlankhorst / rebind-usb.sh
Created October 31, 2020 09:24
Re-bind XHCI driver to make USB devices responsive again after a wakeup. https://tomlankhorst.nl/unresponsive-usb-unbind-bind-linux
#!/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 / mqtt-demo.cpp
Created May 11, 2021 14:59
MQTT mosquitto demo (with fmt/7.1.3 mosquitto/2.0.10)
#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 April 19, 2021 09:16
Basic support for `boost::uuids::uuid` in `libpqxx` 7.4
#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.
*
@tomlankhorst
tomlankhorst / decay_optional.hpp
Created April 14, 2021 07:40
Decay optional type
template<typename T>
struct decay_optional {
using type = T;
};
template<typename T>
struct decay_optional<std::optional<T>> {
using type = T;
};
@tomlankhorst
tomlankhorst / talker_listener_ros.launch
Last active June 3, 2020 10:08
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/
<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>
// 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 / thanks
Last active April 29, 2020 07:31
⭐ Thanks! Star the current GitHub repository.
#!/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:
<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"