Skip to content

Instantly share code, notes, and snippets.

View DarrenSem's full-sized avatar

Darren Semotiuk DarrenSem

View GitHub Profile
@DarrenSem
DarrenSem / console.save.js
Created September 7, 2024 17:07
console.save.js -- download your JavaScript objects from your web browser's F12 Dev Tools console! (also Bookmarklet click defaults to saving current selection or body.innerText as `DL-[date].md`)
// console.save.js -- download your JavaScript objects from your web browser's F12 Dev Tools console! (also Bookmarklet click defaults to saving current selection or body.innerText as `DL-[date].md`)
// javascript:void function(){let a=Object,b=document,c=(c,d,e)=>{let f=URL,g=f.createObjectURL(c=new Blob([c],{type:e||c?.type||"application/octet-stream"}));a.assign(b.createElement("a"),{href:g},!0===d?{target:"_blank"}:{download:d||""}).click(),f.revokeObjectURL(g)},d=a=>a,e=()=>{if(b.onselectstart&&b.onselectstart!==d)return b.onselectstart=d,alert("Text selecting was disabled!\n\nTry again, it is now enabled...");let a=b.getSelection(),c=a&&"Range"===a.type&&a.getRangeAt(0),e=c&&b.createElement("div"),f=e?(e.appendChild(c.cloneContents()),e.innerText):"";return f},f=a.assign(console,{save:(a,d,f)=>{a==null&&(a=e(),""===a.trim()&&(a=b.body.innerText));let g="object"==typeof a;g&&(a=JSON.stringify(a,0,4));c(a,d||`DL-${+new Date}.${g?".json.txt":"md"}`,f||(g?"application/json":"octet-stream"))}});f.save()}();
@DarrenSem
DarrenSem / VueJS-ChatGPT-Playground.html
Last active June 21, 2024 21:31
VueJS-ChatGPT-Playground (minimal, proof of concept direct API fetch) - Pinia for state management, CTRL+ENTER = send, CTRL + UP/DOWN = prompt history
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatGPT Playground (starting up)</title>
<style>
.byline {
font-family: Verdana;
font-size: 80%;
@DarrenSem
DarrenSem / MarkDownLivePreview.com-resizer.js
Last active September 22, 2024 15:43
MarkDownLivePreview.com-resizer.js -- bookmarklet to add [Toggle Editor] (and also horizontal resizer)
// MarkDownLivePreview.com-resizer.js -- bookmarklet to add [Toggle Editor] (and also horizontal resizer) - instead of waiting for repo update using <script defer src="resizer.js"></script>
// 1710 char javascript:void function(){if(!document.getElementById("resizer")){let a=location,b="markdownlivepreview.com";if(a.hostname!=b)a.href="https://"+b;else{let a=document,b=b=>a.getElementById(b),c=b("container"),d=b("edit"),e=b("preview"),f=!1,g=b("copy-button");a.head.insertAdjacentElement("afterBegin",Object.assign(a.createElement("style"),{id:"resizer.css",innerHTML:"\n body {\n margin: 0;\n height: 100vh;\n overflow: hidden;\n }\n #container {\n display: flex;\n width: 100%;\n height: 100%;\n overflow: hidden;\n }\n #edit, #preview {\n flex-grow: 1;\n overflow: auto;\n transition: flex 0.3s ease;\n }\n #resizer {\n width: 4px;\n background-color: green;\n cursor: col-resize;\n flex-shrink: 0;\n }\n #toggle-button {\n margin-left: 16px;\n }\n .shrunk {\n
@DarrenSem
DarrenSem / chatgpt-lite.js.cs.md
Last active April 25, 2024 19:59
chatgpt-lite.js equivalent in Csharp is... not nearly as minimal (ChatGPT results, MarkDown) (1st comment = final C# version, 2nd comment = Java version)

SYSTEM:

You are an expert at JavaScript and C#

. You must format indents using 2 spaces, and you must wrap strings using doublequotes " instead of '.

Let's think step by step.

@DarrenSem
DarrenSem / ytSubs.js
Last active September 15, 2024 16:41
ytSubs.js - YouTube subtitles - English (auto-generated) CC (closed captions) - Usage: node ytSubs.js videoIdOrUrl, or Web browser BOOKMARKLET into a new window
// ytSubs.js (SEE DISCLAIMER) - via @DarrenSem https://gist.github.com/DarrenSem (22Mar2024)
// YouTube subtitles - English (auto-generated) CC (closed captions)
// Usage: node ytSubs.js videoIdOrUrl
// or Web browser BOOKMARKLET (contents open in a new window)
// ES6 clickable Bookmarklet = 3923 chars:
//javascript:void function(){"use strict";var e=String.fromCharCode;const n=!1,d=globalThis,{process:i}=d,t=console,u=async(e,n,d="text")=>fetch(e,n).then(e=>e[d]()),a=e=>{try{e=(e||"")+"";const n=e.match(/"captionTracks":.*"isTranslatable"\:.*?}]/),d=JSON.parse(`{${(n||[""])[0]}}`).captionTracks||[],i=d.map(e=>{const n=e.name;return[l(n.simpleText||n.runs&&n.runs[0].text),e.baseUrl+"&fmt=json3"]});return i}catch(n){}},r=e=>{e=new Date(e);let n=e.getDate();return isNaN(n)?null:`${(n+"").padStart(2,"0")}${e.toLocaleString("default",{month:"short"})}${e.getFullYear()}`},f=e=>{e="string"!=typeof e&&e?new URL(e):{href:e||""};const n=e&&e.href.trim()||"",d=n.replace(/(https?:\/\/)?\/*(.+?)\/?$/,"https://$2"),i=d
@domenic
domenic / generate-urltestdata.js
Created December 30, 2022 09:53
urltestdata.json generator using jsdom/whatwg-url
"use strict";
const { URL } = require(".");
const inputs = [
"https://\u0000y",
"https://x/\u0000y",
"https://x/?\u0000y",
"https://x/?#\u0000y"
];
@DarrenSem
DarrenSem / store.js
Created November 26, 2022 22:26
store.js ALL-IN-ONE function: () = dump Storage, (keyOrNS, value OTHER THAN undefined) = return value after setting it, (keyOrNS) = return value - UNDEFINED if missing, (null, keyOrNS) = removeItem(keyOrNS) then return keyOrNS
// store.js ALL-IN-ONE function: () = dump Storage, (keyOrNS, value OTHER THAN undefined) = return value after setting it, (keyOrNS) = return value - UNDEFINED if missing, (null, keyOrNS) = removeItem(keyOrNS) then return keyOrNS
// let store=(k,d,s=localStorage,z=s.getItem(k))=>null==k?null==d?s:(s.removeItem(d),d):void 0===d?null==z?void 0:JSON.parse(z):(s.setItem(k,JSON.stringify(d,0,"\t")),d);
let store = (
keyOrNS,
data,
storage = [localStorage, sessionStorage][0],
_z = storage.getItem(keyOrNS)
) => {
@DarrenSem
DarrenSem / Math.sum [ , Math.avg , Math.max , Math.sum ] .js
Created November 24, 2022 18:06
Math.sum.js and Math.avg (average) and Math.max and Math.sum -- ALL will automatically flatten (all, args, passed, [[even, [, Arrays]]])
// Math.sum.js and Math.avg and Math.max and Math.sum -- ALL will automatically flatten (all, args, passed, [[even, [, Arrays]]])
console.log(Math.sum);
// undefined
console.log(Math.avg);
// undefined
console.log(Math.max);
// ƒ max() { [native code] }
@DarrenSem
DarrenSem / randomWithSeed.js
Last active December 21, 2023 18:07
randomWithSeed.js - use rnd() after rnd = createRandomWithSeed( seed [0+] = Date.now() ) - Math.random is less than 2x faster than this 'good enough' SEED-able version
// randomWithSeed.js - use rnd() after rnd = createRandomWithSeed( seed [0+] = Date.now() ) - Math.random is less than 2x faster than this 'good enough' SEED-able version
let createRandomWithSeed = seed => {
seed = Math.abs(isNaN(seed) ? Date.now() : seed);
return () => {
seed = (seed * 9301 + 49297) % 233280;
return seed / 233280;
};
};
// R=s=>(s=Math.abs(isNaN(s)?Date.now():s),_=>(s=(9301*s+49297)%233280,s/233280));
@DarrenSem
DarrenSem / innerText.js
Last active October 18, 2024 00:30
innerText.js bookmarklet for mobile (to show webpage text contents OR html) (including PARTIAL source of SELECTION)
// innerText.js bookmarklet for mobile (to show webpage text contents OR html) (including PARTIAL source of SELECTION)
// https://gist.github.com/DarrenSem/7e1216bda80e6269ad53b43d90603158
// 17Oct2024 BUGFIX: now missing EVERY section INCLUDING "System instructions"... UNLESS wide enough to show 3rd column (the one with Model info/sliders)
// 4874 char javascript:void function(){"use strict";const e=[]._,n=((e,t,i,a,n,l,d,r)=>(t=new Date(e||Date()),[i,a,,n]=t.toLocaleTimeString().replace(/(a|p)\.(m)\./i,"$1$2").split(/\W/),[,,l,d]=t.toString().split(" "),r=t.toLocaleString().replace(/(\d+)-(\d+)-(\d+)/,"$2/$1/$3").split("/")[0].padStart(2,0),`${i}${a}${(n||"").toLowerCase()} ${d}-${r}-${l}`))(),t=`${""} ${n}`,d=top.document,i=location,a=(e,n)=>(n||d).querySelectorAll(e||null),l=(n,t)=>{const d=n?.[t?"value":m],i=d==e?e:t?d:d.replace(/\n{3,}/g,"\n\n\n").replace(/\n\n/g,"\n");return i},r=e=>e.trim(),u=e=>(e??"").replace(/\nSYNC$/i,"").replace(/ INSTRUCTIONS$/i,""),o=e=>(e??"").toUpperCase(),p=(n,t,d,i,p)=>{l