Skip to content

Instantly share code, notes, and snippets.

@tg44
tg44 / mustacheSchema.test.ts
Last active February 23, 2023 15:07
JsonSchema generation from {{ mustache }} templates
import Ajv from "ajv";
import { describe, expect, test } from "@jest/globals";
import { schemaGenFromMustacheTemplate } from "./mustacheSchema";
interface TestGen {
name: string;
template: string;
schema: Record<string, any>;
expectedError: string | null;
}
@tg44
tg44 / linkchecker.js
Created June 5, 2021 07:25
Vuepress broken link checker
const path = require( 'path' );
const express = require( 'express' );
const app = express();
const blc = () => {
let err = 0
const blc = require('broken-link-checker')
const siteChecker = new blc.SiteChecker({}, {
robots: function(robots, customData){},
@tg44
tg44 / Bootstrap.scala
Last active May 11, 2021 14:45
Crowdin CDN from Play framework
import play.api.inject.Module
import helpers.{MessagesApiWithCrowdin, MessagesApiWithCrowdinProvider}
import play.api.i18n.{DefaultLangsProvider, Langs, MessagesApi}
import play.api.inject.Binding
import play.api._
//possibly some imports are missing
class AppStartModule extends Module {
override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = {
Seq(
@tg44
tg44 / AdaptiveQueueSource.scala
Created April 29, 2021 10:17
AdaptiveQueueSource akka streams extension
package akka.streams
import akka.Done
import akka.stream.OverflowStrategies.{Backpressure, DropBuffer, DropHead, DropNew, DropTail, Fail}
import akka.stream.{
Attributes,
BufferOverflowException,
Outlet,
OverflowStrategy,
QueueOfferResult,
@tg44
tg44 / README.md
Last active April 12, 2023 20:16
Cheap IP camera video converter

install nodejs 12

run with node app.js cameraRootDir

Almost works with Blitzwolf BW-SHC2 (no audio for me).

Not tested on windows, but probably changing the ffmpeg in the first two function-returns to something like ffmpeg.exe will make this work.

The script will recursively walk on every sudir, group the files ased on parent dir,

@tg44
tg44 / PrettyDuration.scala
Created June 7, 2020 09:35
Helper to pretty print scala Duration
import concurrent.duration._
import scala.annotation.tailrec
object PrettyDuration {
val timeUnitList: List[TimeUnit] =
DAYS ::
HOURS ::
MINUTES ::
SECONDS ::
MILLISECONDS ::
@tg44
tg44 / SpoiwoGridExamples.scala
Created January 15, 2020 16:20
Spoiwo Grid Examples
"Grid" should {
import com.norbitltd.spoiwo.natures.xlsx.Model2XlsxConversions._
def generateGrid(n: Int, m: Int, c: Color) = {
val cell = Cell("").withStyle(CellStyle(fillForegroundColor = c, fillPattern = CellFill.Solid))
val row = Row().withCells(Seq.fill(m)(cell))
Grid { f =>
Seq.fill(n)(row)
}
}
@tg44
tg44 / Makefile
Created May 30, 2019 17:26
home-server config files
file-compose=docker-compose -f file-server.compose.yml -p file-server
hassio-compose=docker-compose -f hassio.compose.yml -p hassio-server
default: help
fup: ## Spin up services
$(file-compose) up -d
fstop: ## Stop services
$(file-compose) stop
@tg44
tg44 / light-sensor-test-v2.ino
Last active February 3, 2019 09:35
Wemos D1 mini TSL2561
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <SPI.h>
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
void setup(void) {
Serial.begin(9600);
Serial.println("");
@tg44
tg44 / humidity-sensor-test.ino
Last active February 3, 2019 09:33
Wemos D1 mini with BME280 test
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <SPI.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
void setup(void) {