Skip to content

Instantly share code, notes, and snippets.

@lemlac
lemlac / self-replicate.js
Created October 9, 2025 17:17
Self replicating program in JavaScript. Run: `node self-replicate.js | node`
let s = "let s = %s;\nconsole.log(s, JSON.stringify(s));";
console.log(s, JSON.stringify(s));
@lemlac
lemlac / bsky-dormant-accounts.js
Last active October 9, 2025 17:14
Find accounts that your following on Bluesky which have not posted in a while.
// Import required modules for handling user input, streams, and Bluesky API
import { createInterface } from 'node:readline';
import { Writable } from 'node:stream';
import { BskyAgent } from '@atproto/api';
// Create a readline interface to get user input from the terminal
const rl = createInterface({
input: process.stdin,
output: process.stdout,
});
@lemlac
lemlac / bouncing-pictures.html
Last active October 24, 2024 20:30
HTML page that bounces images around inside of a canvas.
<body><style>
html, body, canvas {
padding: 0;
margin: 0;
overflow: hidden;
background-color: black;
width: 100vw;
height: 100vh;
}
pre {
@lemlac
lemlac / percent.rs
Created July 12, 2024 04:20
percent.rs
type Byte = i8;
type Word = i16;
const SIZE: Byte = 8;
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd)]
pub struct Percent(Byte);
impl Percent {
pub const MAX: Percent = Percent(Byte::MAX);
pub const MID: Percent = Percent(Byte::MAX / 2);
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 {
@lemlac
lemlac / randomstring.js
Created June 17, 2024 15:15 — forked from lac5/randomstring.js
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 (
@lemlac
lemlac / global.js
Created June 17, 2024 15:14 — forked from lac5/global.js
/*
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`