Skip to content

Instantly share code, notes, and snippets.

@ddlsmurf
ddlsmurf / bthome_sensors.json
Last active August 27, 2025 01:36
BTHome javascript definitions (see https://bthome.io/format/ )
[
{
"id": 0,
"name": "packet id",
"example": {
"data": "0009",
"result": "9"
},
"kind": "number",
"size": 1
This file has been truncated, but you can view the full file.
{
"header": {
"schema": {
"vendor": {
"label": "Vendors, devices and interfaces. Please keep sorted.",
"fields": [
{
"key": "vendor",
"value": "vendor_name",
#!/usr/bin/env node
/* Parse http://www.linux-usb.org/usb.ids */
let source = process.argv[2]
? require('fs/promises').readFile(process.argv[2], 'utf8')
: fetch('http://www.linux-usb.org/usb.ids').then(res => res.text());
source = source.then(text => parseUSBIDsFile(text));
// source = source.then(makeExampleSchema);
defmodule CLIHistogram do
defp block_index_from_fractional(blocks, fractional) when fractional >= 0 and fractional <= 1, do:
round(fractional * (tuple_size(blocks) - 1))
defp block_index_from_fractional(_blocks, fractional) when fractional < 0, do: 0
defp block_index_from_fractional(blocks, fractional) when fractional > 1, do: tuple_size(blocks) - 1
defp block_from_fractional(blocks, fractional), do: elem(blocks, block_index_from_fractional(blocks, fractional))
defp repeat_string(str, count) when count <= 0, do: str
defp repeat_string(str, count), do: String.pad_leading("", count, str)
@ddlsmurf
ddlsmurf / wordle_cheat.exs
Last active October 13, 2023 15:08
Playing around with wordle logic
defmodule WordleCheat do
defmodule Utils do
def chars_of(str) when is_binary(str), do: str |> String.downcase() |> String.graphemes()
def map_inc(map, key) when is_map(map), do: Map.update(map, key, 1, &(&1 + 1))
def map_dec(map, key) when is_map(map), do: Map.update(map, key, -1, &(&1 - 1))
def map_dec_or_del(map, key) when is_map(map) do
case Map.get(map, key) do
1 -> Map.delete(map, key)
n when n > 1 -> Map.put(map, key, n - 1)
end
@ddlsmurf
ddlsmurf / ssh_sign.exs
Last active February 6, 2022 01:36
SSH private key file and signature file reader
defmodule T do
def read_ssh_sig(filename) do
{:ok, raw_sig} = File.read(filename)
raw_sig = String.replace(raw_sig, ~r/.*-----BEGIN SSH SIGNATURE-----\n/s, "")
raw_sig = String.replace(raw_sig, ~r/\n-----END SSH SIGNATURE-----.*/s, "")
Base.decode64(raw_sig, ignore: :whitespace)
end
defp shift_string(<<len::unsigned-integer-32, str::binary-size(len), rest::binary>>), do: { str, rest }
defp parse_ssh_sig_body(sig_body) do
# ssh_sig_magic = 'SSHSIG'
@ddlsmurf
ddlsmurf / index.html
Last active December 25, 2021 22:37
Calculates more interesting dates to celebrate if your existence duration is the main variable
<html>
<head>
<title>Birthdates ! </title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data.js" integrity="sha512-oqSECbLRRAy3Sq2tJ0RmzbqXHprFS+n7WapvpI1t0V7CtV4vghscIQ8MYoQo6tp4MrJmih4SlOaYuCkPRi3j6A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- Select 2 -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
</head>
@ddlsmurf
ddlsmurf / philips_hue_tap_notes.md
Last active September 19, 2022 23:23
Philips Hue Tap notes

I had issues with my tap switch, it would stop working. Here are my notes from the disassembly.

Internally a PTM215Z.

Join (or re-join) procedure

This sometimes is required even if nothing changed, not sure why.

  • Set the hub to scan for sensors (POST api/${user}/sensors) - This could be optional if the channel was changed. Try skipping this first, if that doesn't work, retry without skipping this.
  • Press and hold button for your channel (see table below) for at least 7 seconds.
@ddlsmurf
ddlsmurf / index.html
Last active December 21, 2021 17:25
Watchy BLE OTA client #watchy #tool
<html>
<head>
<style>
.dragging {
background-color: rgb(236, 135, 135);
}
</style>
</head>
<body>
<h1>Watchy BLE firmware upload client</h1>
@ddlsmurf
ddlsmurf / wifi_update_client.c
Last active August 7, 2021 00:56
ESP32 https OTA #watchy #esp32
#include <wifi_update_client.h>
#include <esp_log.h>
#include <esp32-hal.h>
#include <esp_https_ota.h>
static const char *LOG_TAG = "wifi_update_client";
const char *url = "https://raw.githubusercontent.com/sqfmi/Watchy/master/examples/WatchFaces/7_SEG/7_SEG.bin";