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 / Vue 3 CRUD Example using IndexedDB.html
Created June 24, 2024 04:05
Vue 3 CRUD Example using IndexedDB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue 3 CRUD Example using IndexedDB</title>
<script src="https://unpkg.com/vue/dist/vue.global.js"></script>
<script src="https://unpkg.com/idb/build/umd.js "></script>
@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 / TriCon-set-9reps-3tempos.md
Last active April 20, 2024 19:41
TriCon set: 9 reps, 3 different rep cadences within that 9 reps...

"TRI CON" System (yt:Live Anabolic) 3 reps EXPLOSIVE concentric 3 reps 10-second ISOmetric• HOLD 3+ reps 4-4 [super]slow CONTROL'd •where the MOST TENSION (mid-range? fully contracted?)

^ via "Lift Less Weight Gain More Muscle (TRICON TRAINING WORKOUT!)" (04Jun2020) https://www.youtube.com/watch?v=JcDySxe9qSg&ab_channel=LiveAnabolic

...

@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 / OpenAIPlaygroundShowPresets.js
Last active March 17, 2024 16:13
OpenAIPlaygroundShowPresets.js -- Bookmarklet to fix March 2024 CSS regressive bug (~"GM_addStyle" but without TamperMonkey or GreaseMonkey)
// OpenAIPlaygroundShowPresets.js -- Bookmarklet to fix March 2024 CSS regressive bug (~"GM_addStyle" but without TamperMonkey or GreaseMonkey)
// by Darren Semotiuk, see: https://community.openai.com/t/playground-recent-ui-changes-broke-mobile-experience/687130
// BOOKMARKLET* for those of us not running TamperMonkey or GreaseMonkey
// *Simply add the one-liner below as a Favorite/Bookmark in your browser, no extensions required!
javascript:void function(){globalThis.GM_addStyle=globalThis.GM_addStyle||function(a){let b=document,c=b.head||b.body,d=b.createElement("style");d.type="text/css",d.innerText=a,c&&c.appendChild(d)},GM_addStyle("@media(max-width:500px){.pg-header-actions,.pg-header-section-settings,.pg-preset-select-container{display:block !important}}")}();
@DarrenSem
DarrenSem / replaced.js
Last active February 10, 2024 18:01
replaced.js ( v, ...rules [ ArrayOf[ pattern, replaceWith, optionalRegExpFlags] ] ) -- flexible multiple string replacements (Flags default = "g")
// replaced.js ( v: any, ...rules: Array of [pattern: any, replaceWith: string | function, optionalRegExpFlags: string | null | undefined] )
const replaced = (v, ...rules) => {
return rules.reduce( (acc, rule) => (
acc.replace(
RegExp( rule[0], rule[2] == null ? "g" : rule[2] ),
rule[1]
)
), String( v ?? "" ) );
};
@DarrenSem
DarrenSem / MHT Saver - minimal code for Chrome extension.md
Created February 2, 2024 15:22
MHT Saver - minimal code for Chrome extension to Save As MHT

I want to write a Chrome extension. I need the most minimal code for the V3 manifest and worker.js to trigger a download prompt of a data url generated by btoa() of the capture as mhtml function. Use only async await and arrow functions instead of promises and callbacks wherever possible. Use blob.text() instead of FileReader. Image128 .png and no popups or content scripts.

(02Feb2024 806am)

BOT:

To create a minimal Chrome extension that triggers a download prompt of a captured page in MHTML format using Manifest V3, you need to include the following files in your extension:

  1. manifest.json: The metadata file, which includes information about the extension like its name, version, permissions, and which script to run as the service worker.
@DarrenSem
DarrenSem / range(size, optionalEachFunction, optionalMapFunction).js
Last active February 7, 2024 16:13
range.js (arraySize, optionalMapFunction, optionalEachFunction)
// range(arraySize, optionalMapFunction, optionalEachFunction).js
// https://gist.github.com/DarrenSem/bc0403bcdad09912eb298e6d3b4824fe
const range = ( arraySize, fnMapIndex, fnEachIndexFirst, _indexes ) => (
_indexes = Array.from( Array(arraySize | 0).keys() ), // because [...Array(arraySize | 0).keys()] triggers TypeScript/VSC error: Type 'IterableIterator' is not an array type or a string type.
fnEachIndexFirst && _indexes.forEach( index => fnEachIndexFirst(index) ),
fnMapIndex && ( _indexes = _indexes.map( index => fnMapIndex(index) ) ),
_indexes
);