Skip to content

Instantly share code, notes, and snippets.

use std::fmt;
use std::error::Error;
type Buffer = Vec<u8>;
pub trait ReadU24BE {
fn read_u24_be(&self, pos: usize) -> Result<u32, OutOfRangeError>;
}
impl ReadU24BE for Buffer {
@lac5
lac5 / randomstring.js
Last active June 17, 2024 15:15
randomstring.js
const letters = 'abcdefghijklmnopqrstuvwxyz'
function randomString(max, min = 1) {
let length = Math.floor(Math.random()*(max+2-min)+min);
let word = '';
while (word.length < length) {
word += letters[Math.floor(Math.random()*letters.length)];
}
return word;
}
export default function randomBigInt(max) {
const segment = Number.MAX_SAFE_INTEGER;
const bigSegment = BigInt(segment);
const maxArray = [];
for (let bigMax = BigInt(max), zero = 0n; bigMax > zero; bigMax /= bigSegment) {
maxArray.unshift(Number(bigMax % bigSegment));
}
const superSum = (a, b) => a * bigSegment + b;
return function() {
let unlimited = false;
import { getOptions } from 'loader-utils';
import CSS from 'css';
import XRegExp from 'xregexp';
export default function cssPrefixLoader(content) {
const { prefix, ...options } = getOptions(this);
let ast = CSS.parse(content);
import { getOptions } from 'loader-utils';
import XRegExp from 'xregexp';
import toSource from 'tosource';
export default function ejsLoader(content) {
let options = getOptions(this);
let [source, ...imports] = compileEjs(content, options);
return (
/*
This script reads the nearby global.d.ts file and exports a list of imports as
an object. Imports need to follow the same structure as the example below. This
script only works with default exports but could be modified to use named
exports instead.
Example:
`global.d.ts`
@lac5
lac5 / zip.js
Created November 27, 2019 20:07
function zipMin(...iterators) {
let done = iterators.length === 0;
iterators = iterators.map(iterator => iterator[Symbol.iterator]());
return {
[Symbol.iterator]() {
return this;
},
next(...args) {
let value = [];
for (let i = 0, length = iterators.length; i < length; i++) {
@lac5
lac5 / autotts.meta.js
Last active June 19, 2024 00:39
Automatically reads messages in a chatroom page. (i.e. Picarto, Twitch, Youtube, etc.)
// ==UserScript==
// @name Auto TTS
// @namespace larryc5
// @version 0.1
// @description Automatically reads messages in a chatroom page. (i.e. Picarto, Twitch, Youtube, etc.)
// @author Larry Costigan <[email protected]>
// @match https://picarto.tv/chatpopout/*/public
// @require https://code.jquery.com/jquery-latest.min.js
// @grant GM_setValue
// @grant GM_getValue
export default function floorMod(a, b) {
return a - Math.floor(a / b) * b;
}
@lac5
lac5 / rnmd5.js
Last active June 17, 2024 15:06
Renames files to their md5 value of their content.
const path = require('path');
const fs = require('fs').promises;
const md5 = require('md5');
const uuid = require('uuid/v5');
const argv = require('yargs')
.strict()
.usage('$0 <files...>', 'Rename files to their md5 value.', (yargs) => {
yargs.positional('files', {
describe: 'The files that will be renamed.',
type: 'array'