Skip to content

Instantly share code, notes, and snippets.

@plugnburn
plugnburn / chromium-flags.conf
Last active February 8, 2023 18:37
How to enable dark mode preference for the web page CSS queries in Ungoogled Chromium (put this into your ~/.config/chromium-flags.conf)
--force-dark-mode
--enable-features=WebUIDarkMode
@plugnburn
plugnburn / picoluhn.js
Last active January 10, 2023 19:18
An attempt to get a Luhn implementation as small as possible
// Input: a string of digits (w/o the check digit)
// Output: the check digit
// Universal algo - smallest option so far (67 chars after the assignment):
luhn=s=>(10-[...s].reverse().reduce((a,v,i)=>a+v*(i&1?1:2.2)|0,0)%10)%10
// IMEI version (14-digit or any other even-digit input) - smallest option so far (57 chars after the assignment):
luhnImei=s=>(10-[...s].reduce((a,v,i)=>a+v*(i&1?2.2:1)|0,0)%10)%10
// Credit card version (15-digit or any other odd-digit input) - smallest option so far (57 chars after the assignment):
@plugnburn
plugnburn / telememer.js
Created January 5, 2023 20:24
Telememer: a JS library to encode/decode information to/from Casio module 2747/5574 Telememo 30 format
// Telememer: a JS library to encode/decode information to/from Casio module 2747/5574 Telememo 30 format
// Supports up to 378 bytes of raw binary data
// Requires BigInt support in the browser's or other JS engine
// Created by Luxferre in 2023, released into public domain
// Made in Ukraine
Telememer = (params => {
var nameAlphabet = params[0],
digitAlphabet = params[1],
indexAlphabet = params[2],
@plugnburn
plugnburn / olc.js
Last active November 8, 2023 03:39
TinyOLC - smallest Open Location Code implementation in JS
/**
* TinyOLC - Open Location Code for smallest applications
* Differences from Google's open-source JS implementation:
* - less than 600 bytes minified (as opposed to over 4.5 KB from Google)
* - only 2 methods exposed - encode (lat, lng => str) and decode (str => [lat, lng])
* - only floating point degrees accepted as encoding input (positive as N and E, negative as S and W)
* - no short code resolution
* - no area encoding, only points with 11-digit resolution
* - assuming the block lower left corner only when decoding a low-res code
* - no validation checks
@plugnburn
plugnburn / usbio.js
Last active February 1, 2022 11:10
USBIO.js: a convenient wrapper class for WebUSB interaction (for further mobile toolkits)
//USB I/O class for WebUSB
//(c) Luxferre 2020-present
class USBIO {
//Possible devFilter fields: classCode, subclassCode, protocolCode, vendorId, productId, serialNumber (not recommended)
constructor(devFilter = {}) {
this.requestDeviceObject = {filters:(devFilter ? [devFilter] : [])}
this.devFilter = devFilter
@plugnburn
plugnburn / mtphreak-6572.lua
Created June 16, 2020 22:16
MTPhreak-6572: sKai-specific MP0B_001 file modifier
-- MTPhreak IMEI changer and randomizer for MediaTek NVRAM
-- This version is adapted specifically for the Sigma sKai and other MT6572 based phones
-- Usage: lua mtphreak-6572.lua NVRAMfile [imei1 [imei2]]
-- If no IMEIs are passed, they are randomized (with respect to Luhn checksum)
function parseImei(imeistr) -- imei string to 12-byte table
local imeiTbl = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
for i = 1, 15 do
local digit = tonumber(imeistr:sub(i,i))
@plugnburn
plugnburn / mtk-bootseq.py
Created June 15, 2020 20:55
MTK Bootseq: enter alternative boot modes in MediaTek-based smartphones
#!/usr/bin/env python3
# Simple script to enter the necessary boot mode in the MT6572-based (etc) phones
# Depends on pyserial, otherwise fully cross-platform
# Usage: python3 mtk-bootseq.py [MODECMD] [port]
# e.g. python3 mtk-bootseq.py FASTBOOT /dev/tty.usbmodem14200
# and then connect the cable and repeatedly short-press the power on key
# Supported commands depend on the device and its preloader. Here's the list for Sigma S3500 sKai:
@plugnburn
plugnburn / theme_descriptor.xml
Created February 13, 2020 21:22
Example NTH theme descriptor file for Nokia 8800 Classic and Special Edition - public tutorial
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE theme PUBLIC "-//NOKIA//DTD THEME 1.1//EN" "theme.dtd">
<!--
This is an example theme_descriptor.xml for Nokia 8800 Classic/Special (not Sirocco or Arte)
that can be used freely as a complete reference template to create other themes
Compilation: cd theme_dir && zip -9 ../MyExampleTheme.nth ./*
Note: all resource files MUST be present in the archive's root, no subdirectories!
-->
<theme name="MyExampleTheme" version="1.1">
<!-- (all icons and wallpapers hereafter can be of JPEG, PNG, BMP or GIF format, including animations) -->
@plugnburn
plugnburn / Novocarina.scad
Last active October 13, 2019 23:02
Novocarina: 3D-printable customizable English pendant style ocarina
This file has been truncated, but you can view the full file.
/**
* Novocarina: a fully 3D-printable ocarina with a side pendant loop and customizable inside bottom branding
* Optimized PLA settings: 20% infill, 0.3mm layer height, 10mm brim
*
* Key: C
*
* It has some differences from a standard 4-hole English pendant system ocarina:
* due to the nature of 3D printing in PLA, some tones actually have different keying
* (don't believe your musical tuners since they can't pick up any overtones,
* and these overtones play a very important role in shaping final pitch here).
@plugnburn
plugnburn / stl2scad.js
Last active October 11, 2019 19:10
STL2SCAD.js - Optimizing decompiler of a binary STL into the OpenSCAD source
/**
* Optimizing decompiler of a binary STL into the OpenSCAD polyhedron module
* @license Unlicense
*
* @param {ArrayBuffer} stl STL file contents (binary flavor)
* @param {string} optional custom name for OpenSCAD object (if none passed then 'object{NumTriangles}' will be used)
* @returns {string} ready OpenSCAD script
*/
function STL2SCAD(stl, optModName = null) {
var totalTriangles = new Uint32Array(stl.slice(80, 84))[0], //triangle amount is LE uint at byte 80