Skip to content

Instantly share code, notes, and snippets.

View SwadicalRag's full-sized avatar
👨‍⚕️
working :)

swadical SwadicalRag

👨‍⚕️
working :)
View GitHub Profile
@SwadicalRag
SwadicalRag / statistics.ts
Last active March 1, 2024 04:48
AUROC / AUPRC / binary classifier statistics in typescript
import * as fs from "fs";
/**
* Class representing evaluation metrics for a binary classifier system.
* This class is designed to calculate and analyze the performance of a binary classifier
* as its discrimination threshold is varied, including ROC curve analysis and Precision-Recall curve analysis.
*/
export class BinaryClassifierStatistics {
/** Sorted array of unique thresholds from the scores in descending order */
thresholds: number[] = [];
@SwadicalRag
SwadicalRag / augmentedplayer.user.js
Last active September 11, 2023 01:28
HTML5 player augment
// ==UserScript==
// @name Augmented HTML5 Video Player
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adds volume boost to 400% and player speed control to 4x and changes skip forward/backward duration to 2s
// @author swadical
// @match https://*/*
// @include *
// @grant none
// @run-at document-end
@SwadicalRag
SwadicalRag / synctcp.ts
Last active June 29, 2023 02:39
A class for synchronous TCP using Worker threads and SharedArrayBuffer in node.js
// Node.js worker threads and networking libraries
import { Worker, isMainThread, parentPort, workerData } from "node:worker_threads";
import net from "net";
const _DEBUG = true;
function log(...args: any) {
if(_DEBUG) console.log.apply(this, args);
}
// Define the size of the shared buffer. 16MB
@SwadicalRag
SwadicalRag / clipboard.ts
Created June 25, 2023 09:32
ffi-napi / ref-napi based typescript library to interact with the system clipboard using WinAPI
import * as ffi from "ffi-napi"
import * as ref from "ref-napi"
export enum ClipboardFormat {
TEXT = 1,
BITMAP = 2,
METAFILEPICT = 3,
SYLK = 4,
DIF = 5,
TIFF = 6,
@SwadicalRag
SwadicalRag / obj2obj.js
Last active June 12, 2023 08:34
Obj2Obj for message passing between electron/node
/**
* @typedef {(EncodedValue|EncodedDate|EncodedArray|EncodedMap|EncodedSet|EncodedObject|EncodedReference)} EncodedObj
*/
/**
* @typedef {{type: "string"|"number"|"boolean"|"undefined", val: string|number|boolean|undefined}} EncodedValue
*/
/**
* @typedef {{type: "date", val: string, ref: number}} EncodedDate
@SwadicalRag
SwadicalRag / twowayweakmap.js
Last active June 3, 2023 12:01
Two way weak map in TypeScript
class TwoWayWeakMap {
constructor() {
this.keyToValue = new WeakMap();
this.valueToKey = new WeakMap();
this.keys = new Set();
this.values = new Set();
}
set(key, value) {
const weakValue = new WeakRef(value);
@SwadicalRag
SwadicalRag / fuzzy.lua
Created December 24, 2022 05:41
Fuzzy substring match in lua
function fuzzySubstringMatch(str,match,maxDiscrepancies)
local minIdx
local minDiscrepancies = 1 / 0
for idx=1,#str do
local curIdx = idx
local discrepancies = 0
local matchIdx = 1
while matchIdx <= #match do
local srcChar,srcCharNext = str:byte(curIdx + matchIdx - 1,curIdx + matchIdx)
local matchChar,matchCharNext = match:byte(matchIdx,matchIdx + 1)
@SwadicalRag
SwadicalRag / panasonic_trc_vm1_decoder.lua
Last active December 30, 2021 09:21
Panasonic Voice Recorder Triple Rate Codec Decoder (for VM1 files) - uses LuaJIT FFI to call native code
-- saved at 12000Hz, 16 bit PCM, little endian
local vcName = "SD_VC001"
local folder = "SD_VOICE/"..vcName
ffi=require'ffi'
ffi.cdef [[
void vInitDecoder(void);
void vDecode(uint8_t* param_1,uint8_t *param_2);
@SwadicalRag
SwadicalRag / insulin.lua
Last active June 21, 2021 07:14
SALHN Basal Bolus Insulin Protocol
-- for use by doctors only, always clinically correlate
-- don't use this for yourself
-- you shouldn't trust strangers on the internet with your blood sugars
print("insulin calculator 3000")
local function roundEven(n,noZero)
local frac = n % 1
local base = math.floor(n)
@SwadicalRag
SwadicalRag / NTMLL.md
Last active February 21, 2021 21:06
Machine Readable National Tall Man Lettering List (ASCQHC, Dec 2020)