Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Hashbrown777 / baka_deluge.js
Last active January 22, 2022 13:53
Update deluge's total uploaded byte tally via `state/torrents.fastresume`
(async () => {
const output = open().document;
//generate a script to run over your deluge state file
output.write(
`<pre>#!/bin/bash
mkdir _
cd _
#split up the file and name them correctly, disregard the byte-counts
awk \\
'BEGIN { RS="[de]40:"; ORS=FS=":" } { if ($1 != "") { for (i = 2; i <= NF; i++) print $i > substr($1, 0, 40) } }' \\
&{ Param($hostname, $port)
try {
$tmp = [Net.Sockets.TcpClient]::new($hostname, $port)
$tmp.Connected
$tmp.close()
return
}
catch [System.Net.Sockets.SocketException] {
$Error[0].Exception | Out-Host
}
@Hashbrown777
Hashbrown777 / 1_sort.js
Created December 7, 2021 12:45
Non-comparative sorting with flexible chunking
function sort(array, radix, getDigit) {
const counts = new Uint32Array(radix);
const jobs = [{start:0, end:array.length, offset:0}];
while (jobs.length) {
const {start, end, offset} = jobs.pop();
counts.fill(0);
counts[null] = start;
const sorting = array.slice(start, end);
for (let index = 0; index < sorting.length; ++index) {
(async () => {
const ignore = /^http:\/\/waltercosand.com\/CosandScores\/Composers%20[^/]+\//;
const urls = [
'http://waltercosand.com/CosandScores/Composers%20A-D/',
'http://waltercosand.com/CosandScores/Composers%20E-K/',
'http://waltercosand.com/CosandScores/Composers%20L-P/',
'http://waltercosand.com/CosandScores/Composers%20Q-Z/'
].reverse();
const skip = [
'http://waltercosand.com/CosandScores/Composers%20L-P/Mozart,%20W.%20A/Mozart%20-%20Complete%20Works%20for%20Piano/'
@Hashbrown777
Hashbrown777 / bytesTransfer.js
Created September 28, 2021 13:27
Convert buffers of one word-length to another
function transferBytes(inputBuffer, inputLength, inputWordSize, wordSize, create) {
inputWordSize |= 0;
const inputBytes = inputLength * inputWordSize;
const inputBitsize = inputWordSize << 3;
wordSize |= 0;
const bytes = (inputBytes - 1 & -wordSize) + wordSize;
const bitsize = wordSize << 3;
const buffer = create(bytes, bytes / wordSize);
pnmcat -jleft -tb \
<(pngtopnm image139.png) \
<(pngtopnm image73.png) \
| pnmtopng \
-alpha <(pnmcat -black -jleft -tb \
<(pngtopnm -alpha image139.png) \
<(pngtopnm -alpha image73.png) \
) \
>test.png
gci `
| %{
("`n", $_.Name, @($_ | gci -File).Length) -join "`t"
$_ `
| gci -File `
| %{
(
$_.CreationTime.ToString('yyyy-MM-dd'),
$_.Length,
$_.Name
Param($file)
$file = Get-Item $file
mkvinfo $file.FullName `
| &{
Begin {
$current = $NULL
}
Process {
if (!$current) {
}
@Hashbrown777
Hashbrown777 / png2jls.js
Created June 25, 2021 07:54
testing jpeg-ls compression rates
const fs = require('fs');
const child_process = require('child_process');
const charls = new Promise((resolve) => {
const charlsJS = require('./charlsjs.js'); //https://github.com/chafey/charls-js/raw/master/dist/charlsjs.js
//in same directory: https://github.com/chafey/charls-js/blob/master/dist/charlsjs.wasm?raw=true
charlsJS.onRuntimeInitialized = () => { resolve(charlsJS); };
});
(async () => {
const file = 'image5.png';
import {Worker, TransferListItem, MessagePort, parentPort} from 'worker_threads';
interface MessagePair<T extends any, U extends any> {
//THESE SHOULD BE PRIVATE
//only present in the interface as a contract BETWEEN APPLICABLE (parameterised) parties
//not ALL PUBLIC PARTIES
//as they should use the IMPLEMENTATION'S EXPOSED METHODS
message :(value :T) => void;
postMessage :(
value :U extends MessagePair<infer V, this> ? V : never,