Skip to content

Instantly share code, notes, and snippets.

@ChadJPetersen
ChadJPetersen / topazSigString2svg.ts
Last active June 23, 2023 19:42
Conver the topaz SigString format into a SVG string using typescript.
function topazSigString2svg(SigString: string): SVGSVGElement {
let raw = Buffer.from(SigString, "hex").toString(); // Convert Hex
raw = raw.replace(/\r|\\r/g, ""); // Fix: remove '\r' occurrences because Windows
const arr = raw.split(/\r?\n/); // Split into array
if (parseInt(arr[1]) > 0) {
// Check if signature is empty
const coords = arr.slice(2, parseInt(arr[0]) + 2), // Separate coordinate pairs
lines = arr.slice(parseInt(arr[0]) + 2, parseInt(arr[1]) + parseInt(arr[0]) + 2), // Separate number of coordinate pairs per stroke
//You must first install the vis and react types 'npm install --save-dev @types/vis @types/react'
declare module "react-graph-vis" {
import { Network, NetworkEvents, Options, Node, Edge, DataSet } from "vis";
import { Component } from "react";
export { Network, NetworkEvents, Options, Node, Edge, DataSet } from "vis";
export interface graphEvents {
[event: NetworkEvents]: (params?: any) => void;
}
@ChadJPetersen
ChadJPetersen / InstallXapianOnWindowsWithRuby.sh
Last active October 24, 2023 21:39
After hours of slaving I finally got Xapian working on windows with a ruby binding (I use it for Redmine). I know this is far from the right way to do it, and is rather hacky. But it works! Also I found little starting points online when trying to compile Xapian on windows. So hoping this helps someone else a bit!
#In Powershell.
# Install chocolatey https://chocolatey.org/install to be the software package manager. Right now the following line is the installer. But it would be good to go grab the new command from the site provided.
#Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install git ghostscript xpdf-utils gnuwin 7zip cyg-get msys2 graphviz activeperl
choco install ruby --version=2.6.5.1
# This sets up ruby to be a dev kit
ridk install 1
cyg-get install catdoc unrtf unzip antiword xlsx2csv libvisio-tools
@ChadJPetersen
ChadJPetersen / circadian_lights.py
Last active July 8, 2018 03:14
A component for Home Assistant (home-assistant.io) that applies circadian changes to lights.
# An Home Assistant (home-assistant.io) service to component lights that accept RGB, XY or MIREDS color commands.
# v20170311 -- https://gist.github.com/xlcnd/01b2d8a28d9d77af901840072360a434
# Original by 2017 Alexandre Conde <xlcnd@outlook.com> https://gist.github.com/xlcnd/01b2d8a28d9d77af901840072360a434
# Edited by Chad Petersen July 2018
# Licensed under MIT
# INSTALL:
# 1. Create the file <config dir>/custom_components/circadian_lights.py and copy the code below to there.
# 2. In your <config dir>/configuration.yaml enter (adapt to your case):
# circadian_lights:
# calmdown: '22:00:00'
@ChadJPetersen
ChadJPetersen / UniqueColumnFinder
Created May 14, 2015 20:32
Get all the schema, table, and column name combinations in the database. Where all values in that column are unique (Microsoft T-SQL / Transact SQL)
CREATE TABLE #UniqueColumns (
schemaName NVARCHAR(MAX),
tableName NVARCHAR(MAX),
columnName NVARCHAR(MAX)
);
DECLARE @unique BIT,
@checkSQL NVARCHAR(MAX),
@sName NVARCHAR(MAX),
@tName NVARCHAR(MAX),
@cName NVARCHAR(MAX);
@ChadJPetersen
ChadJPetersen / RowOffsetScript.sql
Created April 2, 2015 21:12
script in Microsoft Transact SQL (T-SQL) that offsets the data in the given columns by a random amount (data obfuscate).
--Chad J Petersen
--April 2, 2015
--Microsoft TSQL (transact SQL) 2008 R2
--offset/scramble Selected rows in a DB by a random number.
--add values to the @dictionary values to scramble columns with that name everywhere in the DB.
--UNAVOIDABLE RESTRAINT:: WILL BREAK IF A TABLE THAT NEEDS SCRAMBLING HAS MORE THAN (9,023,372,036,854,775,807) ROWS;
--PARAMETERS