Skip to content

Instantly share code, notes, and snippets.

View jaames's full-sized avatar
🐳
~

James jaames

🐳
~
  • UK, '97
  • 00:11 (UTC +01:00)
View GitHub Profile
@jaames
jaames / compileTemplate.ts
Created June 7, 2021 23:05
Tiny Typescript string template compiler
// makes use of tagged template literals
const compileTemplate = (strings: TemplateStringsArray, ...expr: string[]) => {
return (replacements: Record<string, any>) => {
// convert ${'whatever'} instances to array of values
const values = expr.map(key => replacements[key] ?? key);
// rebuild string with replaced values
return strings.reduce((result, part, i) => result + part + (values[i] ?? ''), '');
}
}
@jaames
jaames / Sha256.ts
Created May 11, 2021 10:03
Tiny Typescript implementation of Sha256
/**
* // hash content
* // content must be an uint8 typed array
* const hash = new Sha256();
* hash.update(content)
* // get digest as uint8 typed array
* const digest = hash.digest();
* // or get digest as hex string
* const hex = hash.hexDigest();
*/
@jaames
jaames / Crc32.ts
Last active June 14, 2021 20:01
Tiny Typescript implementation of CRC32
const POLYNOMIAL = -306674912;
let crc32_table: Int32Array = undefined;
export function Crc32(bytes: Uint8Array, crc=0xFFFFFFFF) {
if (crc32_table === undefined)
calcTable();
for (let i = 0; i < bytes.length; ++i)
crc = crc32_table[(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8);
return (crc ^ -1) >>> 0;
@jaames
jaames / Sha1.ts
Last active May 11, 2021 10:02
Tiny Typescript implementation of Sha1
/**
* // hash content
* // content must be an uint8 typed array
* const hash = new Sha1();
* hash.update(content)
* // get digest as uint8 typed array
* const digest = hash.digest();
* // or get digest as hex string
* const hex = hash.hexDigest();
*/
@jaames
jaames / decode_kwz_filename.php
Last active February 1, 2021 11:28
Example PHP script to decode a KWZ filename
<?php
function decode_filename(string $filename)
{
$bytes = base32_decode($filename);
// Convert to byte string
$bin = join('', array_map('chr', $bytes));
// Unpack data
// Hex FSID (9 bytes, 18 chars) | Creation timestamp (uint32) | Modified timestamp (uint32)
return unpack('H18fsid/Vcreated/Vmodified', $bin);
@jaames
jaames / fonts.md
Last active February 13, 2024 14:53
Cool free/cheap font foundries
@jaames
jaames / ppm_filename_checksum.py
Last active July 21, 2020 15:26
Implementation of PPM filename checksum used when Flipnotes are saved into storage
checksum_dict = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def calc_check_digit(filename):
sumc = int(filename[0:2], 16)
for i in range(1, 16):
char = ord(filename[i])
sumc = (sumc + char) % 256
return checksum_dict[sumc % len(checksum_dict)]
def set_check_digit(filename):
@jaames
jaames / colors-beta-guide.md
Last active May 25, 2022 22:58
Colors Live Windows beta guide

Troubleshooting

Missing MSVCP140.dll or VCRUNTIME140.dll errors

If you get a message warning you about missing DLLs MSVCP140.dll or VCRUNTIME140.dll when starting the app, you will need to install vc_redist.x64.exe from this page: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

Missing dcomp.dll

This will show up if you try running Colors Live on an older version of Windows. Windows 10 is the only version currently supported, however support for older versions may be added eventually.

@jaames
jaames / saz.py
Created June 25, 2020 18:38
Redownload content from a given .saz Fiddler dump
import zipfile
import re
import urllib.request
from pathlib import Path
from sys import argv
if len(argv) < 3:
print('usage:')
print('python3 sazrip.py < input.saz > < output dir >')
exit()
@jaames
jaames / dnslog.js
Last active June 25, 2020 11:46
Crappy NodeJS DNS logger for debugging (plus response overrides!)
const dnsServer = require('dnsd');
const { Resolver } = require('dns').promises;
const overrides = [
{ name: 'game-prod.indreams.me', type: 'A', addresses: [`52.213.80.7`, `54.194.121.14`, `34.251.37.65`] }
];
const resolver = new Resolver();
resolver.setServers(['1.1.1.1']);