Skip to content

Instantly share code, notes, and snippets.

@101arrowz
101arrowz / README.md
Last active April 23, 2024 16:40
MSync for Wine 9.0
@101arrowz
101arrowz / oracle-ldap.ts
Created March 11, 2024 19:08
TNS lookup with LDAP for Oracle Database
import ldap from 'ldapjs';
const makeLDAPURL = (server: string) => {
const [domain, mainPort, altPort] = server.split(':');
return [mainPort, altPort].map(port => `ldap://${domain}:${port}`);
}
// Finds a TNS string from the LDAP source
// Adapted from https://github.com/oracle/python-oracledb/discussions/71#discussioncomment-3918181
@101arrowz
101arrowz / qsieve.js
Created October 18, 2023 03:29
Quadratic Sieve
// Writing this in JavaScript was a mistake.
const B = 10000;
const N = 9329629409n * 2315959301n;
console.time('exec');
const bigintSqrt = (v, ceil = false) => {
if (v < 2n) return v;
let iter = v >> 1n;
@101arrowz
101arrowz / dwt.py
Last active March 27, 2023 08:50
Le Gall 5/3 Discrete Wavelet Transform
# Lifting scheme version of the discrete wavelet transform in JPEG 2000
# The approximation and detail coefficients are interleaved in the output of dwt (even
# indices for approx, odd for detail). In practice you may need to separate them afterwards
# idwt is esentially reversing the order of the lifting scheme steps in dwt and
# flipping the sign of operations(i.e. addition becomes subtraction and vice versa)
# approx_len = approximation coefficients length = ceil(total_series_len / 2)
# detail_len = detail coefficients length = floor(total_series_len / 2)
@101arrowz
101arrowz / polymul.js
Created February 22, 2023 06:40
Slow Fast Fourier Transform
// Cooley-Tukey FFT implementation in JS
// My DSP is very shaky so this probably has some bugs...
const N_TRIG = 4096;
const HALF_N_TRIG = N_TRIG >> 1;
const COS = new Float64Array(N_TRIG);
const SIN = new Float64Array(N_TRIG);
for (let i = 0; i < N_TRIG; ++i) {
const rad = 2 * Math.PI * i / N_TRIG;
@101arrowz
101arrowz / index.js
Created June 14, 2021 21:01
Generate Zstandard table representation from frequencies
// Will be used in fzstd if the default distributions ever update
// Not fast because it's meant to be run once for precomputation
// accuracy log
const al = 5;
// distribution
const dist = [1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1];
const out = new Uint8Array(1000);
@101arrowz
101arrowz / crc32.js
Last active November 16, 2023 10:08
Fast CRC32 in JavaScript
/**!
* Fast CRC32 in JavaScript
* 101arrowz (https://github.com/101arrowz)
* License: MIT
*/
// If you use this code, please link this gist or attribute it somehow.
// This code uses the Slice-by-16 algorithm to achieve performance
// roughly 2x greater than all other JS CRC32 implementations (e.g.
@101arrowz
101arrowz / index.ts
Last active December 17, 2020 17:49
Shared React state
import { useEffect, useState } from 'react';
type Subscribable<T> = {
trigger(newValue: T): void;
subscribe(listener: (value: T) => unknown): number;
unsubscribe(ind: number): void;
};
const createSubscribable = <T = void>(): Subscribable<T> => {
const subs: ((value: T) => unknown)[] = [];
@101arrowz
101arrowz / README.md
Created September 25, 2020 01:14
How FFlate works

FFlate is the fastest, smallest, and most effective JavaScript compressor/decompressor currently; to create it, I used a variety of modified or optimized algorithms.

Part 1: The DEFLATE spec

The core of most popular compressed file formats is DEFLATE, or RFC1951. GZIP data, Zlib data, .zip files, PNG images, and more all use some variant of DEFLATE under the hood. At its core, the DEFLATE format is actually not too complex: it's merely a combination of Huffman coding and LZ77 compression.

If you don't understand either of these concepts, feel free to read the following subsections, or skip to Part 2 if you already know what these are and just want to get to implementation details.

Section I: Huffman Coding

Computers think of basically everything as numbers. The smallest unit of information in a computer is a single bit, which can only be either a 0 or a 1. When multiple bits are stringed together, they can be interpreted as a ba

@101arrowz
101arrowz / index.js
Last active September 24, 2020 17:08
Tiny Object.fromEntries Polyfill
Object.fromEntries = function(entries) {
return entries.reduce(
function(a, v) { a[v[0]] = v[1]; return a; },
{}
);
};
// ES6
Object.fromEntries = entries => entries.reduce((a, v) => (a[v[0]] = v[1], a), {});