Skip to content

Instantly share code, notes, and snippets.

@fitsum
fitsum / rm-FB-page-like-suggestions.js
Last active April 26, 2024 05:22
drop in console and remove like suggestions (in case I forget)
Array.from(document.querySelectorAll('[data-tooltip-content="Remove Suggestion"]')).forEach((each)=>{each.click()})
@bszwej
bszwej / echo.js
Last active April 26, 2024 05:22
Pure Node.js echo server, that logs all incoming http requests (method, path, headers, body).
const http = require('http');
const server = http.createServer();
server.on('request', (request, response) => {
let body = [];
request.on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
body = Buffer.concat(body).toString();
@fitsum
fitsum / practical-curry.js
Last active April 26, 2024 05:22
finally
const a = [1,2,3,4];
const checkType = (type, collection2check) => collection2check.every((each) => typeof each === type);
const curr = (collection) => {
return (actionOrType, actionFn) => {
return actionFn(actionOrType, collection) ? `all in ${collection} are ${actionOrType}s` : `few or none in ${collection} are ${actionOrType}s`;
};
}
const arr = curr(a);
console.log(arr('number', checkType))
@fitsum
fitsum / english-bibles-by-denom.js
Last active April 26, 2024 05:21
bible api stuffs
fetch('https://api.scripture.api.bible/v1/bibles', {headers: {'api-key': 'ace65b88c21bc3d190f3f95754e2eede'}})
.then((r) => r.json())
.then((j) => {
const worldenglish = j.data.filter(item => item.name.indexOf('World English Bible') !== -1 ).map((item) => {return {"name":item.name, "description": item.description}});
console.table(worldenglish);
});
// Feeling fine about using `indexOf`
// https://stackoverflow.com/a/54538979
@fitsum
fitsum / mouse-trace.js
Created February 7, 2020 18:42
getting mousemove direction for custom cursor
//TODO: add cursor bg and rotate script. can't tell what's happening without visual
let lastCoords = [];
const handleDir = e => {
let xDiff, yDiff, currCoords = [e.x, e.y];
if ( lastCoords.length !== 0 ){
xDiff = currCoords[0] - lastCoords[0];
yDiff = currCoords[1] - lastCoords[1];
}
@fitsum
fitsum / three.html
Created December 27, 2020 21:55 — forked from nasser/three.html
a three.js boilerplate scene in a single 30 line self-contained html file
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reset-css@5.0.1/reset.min.css">
<script type="module">
import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.124.0/build/three.module.js"
import { OrbitControls } from "https://cdn.jsdelivr.net/npm/three@0.124.0/examples/jsm/controls/OrbitControls.js"
var scene = new THREE.Scene()
var camera = new THREE.PerspectiveCamera(75)
camera.position.z = 4
@fitsum
fitsum / fizzBuzz-OCD.js
Last active April 26, 2024 05:20
Super accurate output
// getting the output to look exactly like what's here
// https://node-girls.gitbook.io/beginners-javascript/challenges/challenge-4-fizzbuzz
const fizzBuzz = ( start, end ) => {
const format = ( idx, output ) => {
let out = output || '';
outColors = {
true: 'color: #71a7ff',
false: 'color: orange'
}
@fitsum
fitsum / same-as-eval.js
Last active April 26, 2024 05:20
no more eval() I guess ...
(() => {return Function(`"use strict";return (${__f__})`)();}).call(null)()
// would normally do `eval(__f__)` where __f__ might be a stringified function
// name in an array
@fitsum
fitsum / selection-snippet.js
Last active April 26, 2024 05:20
styled output causes linebreaks in Chrome but not Firefox
// FIXME?
document.styleSheets[document.styleSheets.length - 1].addRule("::selection", "background: red; color: pink");
document.addEventListener('selectionchange', e => {
console.clear();
slice = document.getSelection().toString();
if (slice !== "") {
parent = document.getSelection().getRangeAt(0).commonAncestorContainer.textContent;
preSlice = parent.slice(0, parent.indexOf(slice));
postSlice = parent.slice(parent.indexOf(slice) + slice.length, parent.length - 1);
/*** The new CSS Reset - version 1.2.0 (last updated 23.7.2021) ***/
/* Remove all the styles of the "User-Agent-Stylesheet", except for the 'display' property */
*:where(:not(iframe, canvas, img, svg, video):not(svg *)) {
all: unset;
display: revert;
}
/* Preferred box-sizing value */
*,