Skip to content

Instantly share code, notes, and snippets.

View zazaulola's full-sized avatar
🏠
Working from home

zazaulola

🏠
Working from home
View GitHub Profile
@zazaulola
zazaulola / README.md
Created November 5, 2024 04:17 — forked from storm1er/README.md
Script for OBS Studio to publish session stats to MQTT broker with autodiscovery set up for Home Assistant

OBS MQTT Status to Home Assistant

Setup:

  1. Download script
  2. Install mqtt-wrapper pip install mqtt-wrapper
  3. Open OBS Studio
  4. In OBS Studio add a script (Tools -> Scripts)
  5. Configure script parameters (my base channel is homeassistant and my sensor name is obs, creating the path homeassistant/sensor/obs)

script_parameters

@zazaulola
zazaulola / svg-to-data-url.js
Created November 5, 2024 04:40
Convert string with SVG code to DataURL
// for modern browsers
const svgToDataUrl = svg => `data:image/svg+xml;utf8,${svg.replace(/[#%]/g,s=>'%'+s.charCodeAt(0))}`;
// for old browsers
const svgToDataUrl = svg => `data:image/svg+xml;utf8,${svg.replace(/[<>#%{}"\s]/g,s=>'%'+s.charCodeAt(0))}`;
/** @format */
const path = require('path');
const fs = require('fs');
const https = require('https');
const http = require('http');
const cheerio = require('cheerio');
const os = require('os');
// Configuration
function debounce(fn, ms, obj){
return Object.assign( function fx(...args){
const now = Date.now();
if(now - fx.lastCall > ms){
fx.lastCall = now;
return fx.fn.call(fx.obj,...args);
}
if(fx.timeout) clearTimeout(fx.timeout);
fx.timeout = setTimeout(()=>fx(...args), fx.lastCall + ms - now);
}, { fn, obj, lastCall: 0, timeout: null });
@zazaulola
zazaulola / demo.ts
Created December 23, 2024 04:35 — forked from vedantroy/demo.ts
SQLite-backed key-value store with JS-like object manipulation and automatic JSON serialization.
import Database from 'better-sqlite3';
import { createDatabaseClient } from './proxy.ts';
// 1) Create an in-memory DB and your table(s).
const db = new Database(':memory:');
db.exec(`
CREATE TABLE users (
id TEXT PRIMARY KEY,
data JSON
);