Skip to content

Instantly share code, notes, and snippets.

@maca134
maca134 / bigint.ts
Last active November 30, 2019 03:13
BigInt to Buffer and Buffer to BigInt Nodejs
function bigIntToBuffer(num: bigint, endian: 'be' | 'le') {
const bytes: number[] = [];
while (num > 0) {
bytes.push(Number(num & 0xffn));
num = num >> 8n;
}
return Buffer.from(endian === 'be' ? bytes.reverse() : bytes);
}
function bufferToBigInt(bytes: Buffer, endian: 'be' | 'le') {
@maca134
maca134 / WorkshopUploader.bat
Created April 20, 2021 15:46
Workshop Uploader
@ECHO off
SETLOCAL enableextensions enabledelayedexpansion
CD /D "%~dp0"
SET BASEPATH=%~dp0
REM =============================[CONFIG START]=============================
SET STEAMCMDPATH=.steamcmd
REM Steam login details, you may need to run this twice if you have Auth Guard enabled (which you should)
@maca134
maca134 / index.ts
Last active November 16, 2021 00:24
Get Chrome Extension ID in NodeJS
import { readFileSync } from 'fs';
import { parse } from 'protobufjs';
if (!process.argv[2]) throw new Error('no arg');
const file = readFileSync(process.argv[2]);
if (!file) throw new Error('no file');
const root = parse(`
package chromeextensionid;
@maca134
maca134 / NinjectBootstrapper.cs
Last active May 20, 2022 16:27
Caliburn.Micro/Ninject Bootstrapper
using System;
using System.Collections.Generic;
using System.Windows;
using Caliburn.Micro;
using Ninject;
namespace Maca134.Stuff
{
internal abstract class NinjectBootstrapper<TViewModel> : BootstrapperBase
{
@maca134
maca134 / redis-stream.ts
Created March 17, 2024 02:14
Redis Streams for Nodejs
import { Readable, Writable } from "stream";
import { commandOptions, createClient } from "redis";
export const createWriteStream = (client: ReturnType<typeof createClient>, key: string, opts?: { ttlMs?: number }) =>
new Writable({
objectMode: false,
construct: (callback) =>
client
.del(key)
.then(() => callback())