Skip to content

Instantly share code, notes, and snippets.

View fitsum's full-sized avatar
💭
npx fitsum

ፍፁም fitsum

💭
npx fitsum
View GitHub Profile
@fitsum
fitsum / leaflet-darkmode.md
Created August 21, 2024 22:04 — forked from BrendonKoz/leaflet-darkmode.md
Automatic Dark Mode for Leaflet.js
// Leaflet JS - note the *className* attribute
// [...]

L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
    className: 'map-tiles'
}).addTo(map);

// [...]
@fitsum
fitsum / trinket-pro-arduino-cli-sample.md
Last active March 3, 2024 05:16
sample cli command for compiling and uploading to trinket pro with required args|props|...

commands

  • arduino-cli compile --fqbn adafruit:avr:protrinket5 [project name]
  • arduino-cli upload -P usbtinyisp --fqbn adafruit:avr:protrinket5 [project name]

pre-reqs

  • arduino-cli core install adafruit:avr
  • (linux) arduino-cli core install arduino:avr
  • (linux, maybe) install udev rules for trinket pro + restart udev
@fitsum
fitsum / stream-pdf-from-nodejs.js
Created January 25, 2024 10:42 — forked from InsilicoSoft/stream-pdf-from-nodejs.js
Stream local pdf file from nodejs (restify) server to client
server.get('/downloadPdf/:fileData', function (req, res) {
// config
var fileData = Buffer.from(req.params.fileData, 'base64');
var menuData = JSON.parse(fileData.toString());
var userName = menuData.userName;
var menuName = slug(menuData.menuName);
var fileName = userName + "-" + menuName + PDF_EXT;
var filePath = PDF_PATH + fileName;
// process headers
@fitsum
fitsum / trump-ga-19-charges.js
Last active April 26, 2024 05:18
Extract a nice JSON of Trump, his 18 co-conspirators and what they're charged with from CNN's post
// Go here - https://www.cnn.com/interactive/2023/08/georgia-indictment-defendants-list-dg/
// Open dev tools and paste what's below in Console tab
// Option 1: uncomment and run the first 'getEm' function for an unnumbered list of charges per defendant
// Option 2: uncomment and run the second 'getEm' function for an numbered list of charges per defendant
const getEm = ( numbered ) => {
const addNumberIfNumbered = index => numbered ? `${index + 1 + '. '}` : ''
return $$( '.charges-container' ).map( ( container, idx ) => {
const header = container.parentElement.querySelector( '.header' )
const name = header.querySelector( '.name' ).textContent
@fitsum
fitsum / speak-english.js
Last active April 26, 2024 05:18
speaks english voices in given browsers
speakEnglish = () => { voices = speechSynthesis.getVoices(); voices.filter(voice => voice.lang === "en-US" ).forEach(voice => {
const utterance = new SpeechSynthesisUtterance("What's poppin, bitches?")
utterance.voice = voice;
// default volume !== 1
utterance.volume = 1;
speechSynthesis.speak(utterance);
// next line causes function not to fire on first invocation 🤷🏾‍♂️
utterance.addEventListener('start',()=>{console.log('voice name:', voice.name)})
}) }
speakEnglish()
@fitsum
fitsum / remove-youtube-likes.js
Last active April 26, 2024 05:19
removing likes from youtube clips until YT baffles the effort
// https://www.youtube.com/playlist?list=LL
let currentLike = 1,
// should allow time for menu open and click
removeDelay = 150,
// should be double remove delay
countDelay = removeDelay*2,
// get current total from stats section
totalLikes = parseInt(document.querySelector('#stats yt-formatted-string').textContent);
const countLikes = setInterval(()=>{
/*** 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 */
*,
@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);
@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 / 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'
}