Skip to content

Instantly share code, notes, and snippets.

View usefulthink's full-sized avatar

Martin Schuhfuss usefulthink

  • Hamburg / Germany
  • 07:57 (UTC +02:00)
View GitHub Profile
@usefulthink
usefulthink / overlay.js
Created October 17, 2023 09:14
Skeleton for implementing a custom overlay for google maps.
class CustomOverlay {
constructor() {
this.overlay = new google.maps.OverlayView();
this.overlay.onAdd = () => this.onAdd();
this.overlay.onRemove = () => this.onRemove();
this.overlay.draw = () => this.draw();
}
onAdd() { /* ... */ }
onRemove() { /* ... */ }
draw() {
console.clear();
const DAY = 16;
const DEBUG = false;
const INPUT_URL = `https://adventofcode.com/2021/day/${DAY}/input`;
const testInput = `A0016C880162017C3686B18A3D4780`.trim();
const tests = {
literal: () => {
<!doctype html>
<body><script src="index.js" type="module"></script></body>
LAST_PWD=""
LAST_NPM_BIN=""
# find the npm binary path for a given directory ($1).
# Mostly equivalent to calling `npm bin` (except it doesn't report
# non-existing directories), but around 40x faster.
function fastNpmBin() {
local dir="${1}"
local candidate=""
@usefulthink
usefulthink / three-example-to-codepen.js
Last active October 1, 2017 23:05
opens any three.js example in codepen to play around with it.
function extractScriptContent(root) {
return Array.from(root.querySelectorAll('script:not([src])'))
.filter(el => !el.type || el.type.endsWith('javascript'))
.reduce((result, el) => {
el.parentNode.removeChild(el);
return result + el.textContent;
}, '');
}
function extractCssContent(root) {
@usefulthink
usefulthink / .bashrc
Last active August 17, 2017 14:06
automatically add current node-binary path to $PATH
LAST_PWD=""
LAST_NPM_BIN=""
# find the npm binary path for a given directory ($1).
# Mostly equivalent to calling `npm bin` (except it doesn't report
# non-existing directories), but around 40x faster.
function fastNpmBin() {
local dir="${1}"
local candidate=""
while [ "${dir}" != "/" ] ; do
@usefulthink
usefulthink / EnttecUsbOpenDriver.js
Created June 26, 2017 21:02
A fivetwelve-driver for the enttec usbopen-interface.
/**
* A fivetwelve-driver for the enttec usbopen-interface.
*
* @example
* import fivetwelve from 'fivetwelve';
* import Serialport from 'serialport';
* import EnttecUsbOpenDriver from 'fivetwelve-driver-enttec-usbopen';
*
* // I read somewhere that connection settings like baudrate etc are not
* // required as it's just a virtual serialport or something like that
# add this to your .bashrc to add `npm bin` dynamically to your path (works with bash > 4):
function command_not_found_handle() {
npmBinDir=`npm bin`
if [ -x "$npmBinDir/$1" ] ; then
"$npmBinDir/"$@
else
echo "$1: command not found" >&2
( exit 127 )
fi
}
function makeLessCrappy(crappyData) {
const entries = crappyData.feed.entry;
const data = [];
const tmp = entries.map(entry => ({
address: entry.id.$t.replace(/.*\/R(\d+)C(\d+)$/, '$1,$2').split(',').map(Number),
content: entry.content.$t
}));
tmp.forEach(({address, content}) => {
@usefulthink
usefulthink / fivetwelve-driver-enttec-usbpromk2.js
Last active March 13, 2017 21:04
fivetwelve-driver for enttec usbpro mk2 supporting both dmx-universes.
const DEFAULT_OPTIONS = {
universeMapping: {1: 1, 2: 2}
};
const API_KEY = 0xC8D088AD; // taken from qlc+
const labels = {
SEND_DMX_PORT1: 0x06,
SEND_DMX_PORT2: 0xA9,
SET_API_KEY: 0x0D,
SET_PORT_ASSIGNMENT: 0xCB