Skip to content

Instantly share code, notes, and snippets.

import { randomBytes } from "node:crypto";
import { Readable as ReadableStream } from "node:stream";
import fs from "node:fs";
import bytes from "bytes";
function createRandomBytesReadableStream(sizeInBytes) {
return new ReadableStream({
read(readSize) {
readSize = Math.min(readSize, sizeInBytes);
import { buffer } from "node:stream/consumers";
import { randomBytes } from "node:crypto";
import { Readable as ReadableStream } from "node:stream";
import fs from "node:fs";
import http from "node:http";
import https from "node:https";
import path from "node:path";
import { program } from "commander";
import bytes from "bytes";
// Эмулятор бас-бочки для электронных барабанов от 2х сустейн педалей
// Сустейн педали выполняют роль кнопок, замыкая цепь, подключаются к KICK_1_PIN и KICK_2_PIN через какой-нибудь резистор
// Как симуляция удара по бочке (триггеру) генерируется ШИМ импульс на пине OUTPUT_KICK_PIN в течении KICK_WAVE_DURATION_MS (подается HIGH на цифровой пин)
// После нажатия на педаль (регистрирования замыкания цепи) до следующего нажатия этой же педали необходимо, чтобы прошло минимум KICK_TRIGGER_COOLDOWN_MS
// Джек для выхода сигнала на электронные барабаны подключается к OUTPUT_KICK_PIN и GND
// При регистрировании нажатия на педали на Ардуине так же дублировочно будет мигать светодиод L (т.к. он соединен с пином 13)
/*
Примитивный тестер с диодом
Схема
Из соседних GND и 13го пина - вставить диод
От GND около 13го пина любой резистор в 7й пин
Из 7го пина провод и из 5v провод
// Program infinite prints line 0000...00000 (120 width), and add 1 to this binary number representation
// You will see "live binary counter"
// 137 byte c++ code
#include<cstdio>
int w=120,b[120],k,i,t;int main(){for(;;)for(k=1,i=0;i<w;t=b[i],printf("\x1b[0;%dH%d",w-1-i,t),b[i++]=k?!t?k=0,1:0:t);}
import crypto from "node:crypto";
function gf(init) {
let r = new Float64Array(16);
if (init) {
for (let i = 0; i < init.length; ++i) { r[i] = init[i]; }
}
return r;
}
import fs from "node:fs";
import path from "node:path";
const autioLibraryFolder = process.argv[2];
const useParts = Boolean(process.argv.find(arg => arg === "-p"));
if (!fs.existsSync(autioLibraryFolder)) throw new Error("Folder does not exist");
const compareStrings = (a, b) => a.localeCompare(b);
import crypto from "crypto";
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
modulusLength: 512,
publicKeyEncoding: {
type: "spki",
format: "pem"
},
privateKeyEncoding: {
type: "pkcs8",
@lis355
lis355 / MongoDBObjectId.js
Created November 20, 2024 12:27
Generate MongoDB-style ObjectId
let processUnique = Buffer.allocUnsafe(5);
for (let i = 0; i < processUnique.length; i++) processUnique[i] = Math.floor(Math.random() * 0xff);
let index = Math.floor(Math.random() * 0xffffff);
const buffer = Buffer.allocUnsafe(12);
function getInc() {
return (index = (index + 1) % 0xffffff);
}
@lis355
lis355 / ffmpegSplit.js
Created March 11, 2024 22:40
Split long mp3 into tracks
import { spawn } from "node:child_process";
import ndapp from "ndapp";
import filenamifyLibrary from "filenamify";
async function executeShellCommand(cmd) {
return new Promise((resolve, reject) => {
const child = spawn(cmd, { shell: true });
child.stdout.on("data", data => console.log(data.toString()));