Skip to content

Instantly share code, notes, and snippets.

View wlib's full-sized avatar
🔙
delete all code

Daniel Ethridge wlib

🔙
delete all code
View GitHub Profile
@wlib
wlib / primes.mjs
Last active March 12, 2023 01:54
Javascript prime number generator function
function * primes(max = 1_000) {
const isComposite = []
for (let i = 2; i <= max; i++) if (!isComposite[i]) {
yield i
for (let j = i**2; j <= max; j += i)
isComposite[j] = true
}
}
@wlib
wlib / consolePuzzle.mjs
Created April 19, 2021 18:43
Play a 15 puzzle (or any other number) in the browser's devtools js console.
const { pipe } = await import("https://unpkg.com/bruh@1.0.18/src/util/index.mjs")
const { listen, map, filter, forEach, tap } = await import("https://unpkg.com/bruh@1.0.18/src/util/iterable/async.mjs")
const makePuzzle = (n = 4) => {
const solvedPuzzle =
[...Array(n)]
.map((_, rowI) =>
[...Array(n)].map((_, colI) => rowI * n + colI + 1)
)
solvedPuzzle[n - 1][n - 1] = null
@wlib
wlib / LICENSE
Last active April 30, 2024 17:07
Run a shell script with bash, line-by-line, prompted on each command. Useful for running unknown scripts or debugging. Not a secure substitute for understanding a script beforehand.
MIT License
Copyright (c) 2021 Daniel Ethridge
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@wlib
wlib / bruh.ogg.datauri
Last active February 26, 2021 14:57
Super small bruh sound as data uri
data:audio/ogg;base64,T2dnUwACAAAAAAAAAADFVwH2AAAAAPid/iQBE09wdXNIZWFkAQE4AYC7AAAAAABPZ2dTAAAAAAAAAAAAAMVXAfYBAAAA+2xiXQE+T3B1c1RhZ3MNAAAATGF2ZjU4LjQ1LjEwMAEAAAAdAAAAZW5jb2Rlcj1MYXZjNTguOTEuMTAwIGxpYm9wdXNPZ2dTAACAuwAAAAAAAMVXAfYCAAAAF6YmxTIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDSTs9TkxBSUBERElGQkRCP0JBQDtBQEEsLPj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//vj//ngL5QtGqtuEn/os6qNWLtN0+6mJ+QtRNy+8k7Z+K3ClKyD+yOXUrsFdj5v//gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB4grU3ETE+ivMH/IxJJjrIWQAneFkU+65/K35PEGNsMJnSh2RNy8xdRCyaF41RV1fWbrD+S+t9bU7vH3iDABIwT5oh6a8xpe8251fEFv77OI2QsbO0vQtyZc1dd30i5EZr647kYhWq5HRbdixE3Dw0NQreisfyVW14q9ZBY4yC10V4l9XohOlCB5PABWmj0Yu59X9DZsYwEl2RdckXrr9apKtQxOUbS3fnTVqZozZa7+JrG1bgJIQ5B0BR16L6pAPpVTRASyt4sfvolrRCgMCnpIU/QoJ3U2qlPis6eNQr47r4kklWKLGEsMLnDqWu06Jgw18XImW+ODORJX332FiNNqiZdK7OEHiiDwKrh0YJC06XeLPJYYlIztj3WR4Nq+1Nafr6eY8MxPmOvYtU9y0shFOvBR0yn9JgimfAC9uO8bJk9DLZ3/v97XyMu244mLy/apd4tEuPmc4oNAQu1GgHptAr6yP8GM6Vc7hI1/nKb0gTterk0lssjrcHvXuAzsBlQBCBt3
@wlib
wlib / gintama.js
Last active August 17, 2020 18:49
const https = require("https")
const pageHTMLHandler = html => {
const videoURL = html.match(/https:\/\/vidstreaming\.io\/load\.php\?id=.*?SUB/)[0]
require("child_process").exec(`open "${videoURL}"`)
}
const requestHandler = HTMLHandler => response => {
let html = ""
response.on("data", chunk => html += chunk)
const data = [...document.querySelectorAll("#scoreTable > tbody tr")]
.filter(a => a.cells.length > 1)
.map(a => {
const score = a.cells[10].innerText
const [earned, possible] = score.split("/").map(n => parseFloat(n))
return {
category: a.cells[1].innerText,
earned, possible
}
})
@wlib
wlib / jsconsole.js
Last active March 31, 2019 20:58
Ultra simple js console for when devtools are blocked
window.jsConsoleState = {
lines: ["This is a JavaScript console.\nTo clear history, run clear()\nTo exit, run exit()"],
isLooping: true
}
const jsConsole = () => {
// Show the previous lines above the prompt
const input = prompt(window.jsConsoleState.lines.join("\n"))
// Push user input for next prompt
window.jsConsoleState.lines.push(input)
{
"politics": [
{
"title": "Heligoland–Zanzibar Treaty\n",
"image": "https://histography.io/images/2562.jpg",
"link": "https://en.wikipedia.org/wiki/Heligoland–Zanzibar_Treaty"
},
{
"title": "Treaty of Madrid \n",
"image": "https://histography.io/images/2563.jpeg",
@wlib
wlib / task.js
Last active March 8, 2019 21:23
Super simple Task implementation. Lazy evaluation of anything sequentially.
const Task = run => ({
// (a -> e) -> (a -> r) -> Task(a) // Might be inaccurate idk
run,
// undefined -> undefined
log: () =>
run(console.error)
(console.log),
// (a -> b) -> Task(b)
@wlib
wlib / curry.js
Last active December 10, 2018 18:29
curry a js function
function _isPlaceholder(a) {
return a != null &&
typeof a === 'object' &&
a['@@functional/placeholder'] === true;
}
function _arity(n, fn) {
/* eslint-disable no-unused-vars */
switch (n) {
case 0: return function() { return fn.apply(this, arguments); };