Skip to content

Instantly share code, notes, and snippets.

@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,
type DropFirst<T extends unknown[]> = T extends [any, ...infer U] ? U : never;
type ResolveQueue <T> = (output :T[]) => void;
type RejectQueue = (error :any) => void;
type InitQueueParams<T> = [ResolveQueue<T>, RejectQueue];
type InitQueue <T> = (...args :InitQueueParams<T>) => any;
type Enqueued <T> = () => Promise<T>;
export class Queue<T> extends Promise<T[]> {
private max :number;
private waiting :Array<Enqueued<T>>;
@Hashbrown777
Hashbrown777 / repairBrokenXML.js
Last active May 20, 2021 10:10
Fixes improper close order in XML
//build regexes without worrying about
// - double-backslashing
// - adding whitespace for readability
// - adding in comments
const clean = (piece) => (piece
.replace(/((^|\n)(?:[^\/\\]|\/[^*\/]|\\.)*?)\s*\/\*(?:[^*]|\*[^\/])*(\*\/|)/g, '$1')
.replace(/((^|\n)(?:[^\/\\]|\/[^\/]|\\.)*?)\s*\/\/[^\n]*/g, '$1')
.replace(/\n\s*/g, '')
);
const regex = ({raw}, ...interpolations) => (
let bob = () => {
let count = 0;
for (let e of Array.from(document.querySelectorAll('.NotificationItem__clearIconButton___3pU15'))) {
e.click();
++count;
}
if (count)
setTimeout(bob, 5000);
};
bob();
@Hashbrown777
Hashbrown777 / ServerCheck.ps1
Last active April 12, 2021 04:06
Give a detailed report on the ping and tcp status of servers.
#recognised protocols
$protocols=@{
http =80 ;
https=443;
}
$names=@{
teratext='Content Server';
smb ='Network share' ;
ssh ='Remote shell' ;
rdp ='Remote desktop';