Skip to content

Instantly share code, notes, and snippets.

View DarrenSem's full-sized avatar

Darren Semotiuk DarrenSem

View GitHub Profile
@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
);
@DarrenSem
DarrenSem / fizzbuzz expanded - wordmod.js
Last active November 9, 2023 20:38
fizzbuzz expanded - wordmod( limit = 100, words = { 3: "Fizz", 5: "Buzz" }, sep = "\n" )
// FizzBuzz expanded - wordmod.js - because why not
// https://gist.github.com/DarrenSem/3a63b31542487bb1fd38e08976d8d215
let wordmod = ( limit = 100, words = { 3: "Fizz", 5: "Buzz" }, sep = "\n" ) => {
let results = [];
for (let i = 1; i <= limit; i ++) {
let result = "";
for ( let [divisor, word] of Object.entries(words) ) {
@DarrenSem
DarrenSem / mongodb-getDocumentArray.js
Last active November 2, 2023 22:12
MongoDB - function getDocumentArray( fnEachDocument, ...documents ) - returns cloned Array of passed documents (after running function on each)
// MongoDB - function getDocumentArray( fnEachDocument, ...documents ) - returns cloned Array of passed documents (after running function on each)
// Purpose: returns cloned Array of passed documents (after running function on each)
// Usage: const docArray = getDocumentArray( fnEachDocument, ...documents ); await coll.insertMany(docArray);
// see the docs for https://www.mongodb.com/docs/manual/reference/method/db.collection.insertMany
// esp. "_id Field" https://www.mongodb.com/docs/manual/reference/method/db.collection.insertMany/#_id-field
// ^ because DURING THE .insert[Many|One]() call, "_id" field is ADDED to the original document! (if missing)
const getDocumentArray = ( fnEachDocument, ...documents ) => (
fnEachDocument ||= ( document => document ),
@DarrenSem
DarrenSem / ytSubs.js
Last active March 26, 2024 20:28
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 bookmarklet = 4045 chars
javascript:void function(){"use strict";var a=String.fromCharCode;const b="",c=async a=>{try{if(globalThis.fetch){const b=await fetch(a),c=await b.text();return c}return new Promise((b,c)=>{const d=require(/^https/.test(a)?"https":"http").get(a,d=>{if(200>d.statusCode||299<d.statusCode)return c(Error(`${d.statusCode} ${d.statusMessage} ${a}`));const e=[];d.on("data",a=>e.push(a)),d.on("end",()=>b(e.join("")))});d.on("error",a=>c(a))})}catch(a){throw a}},d=a=>{try{a=(a||"")+"";const b=a.match(/"captionTracks":.*"isTranslatable"\:.*?}]/),c=JSON.parse(`{${(b||[""])[0]}}`).captionTracks||[],d=c.map(a=>{const b=a.name;return[g(b.simpleText||b.runs&&b.runs[0].text),a.baseUrl+"&fmt=json3"]});return d}catch(a){}},e=(a,b,c,d)=
@DarrenSem
DarrenSem / hostnameRoot.js
Created September 25, 2023 11:22
hostnameRoot.js -- returns URL/location.hostname with certain prefixes removed: m. mob. mobi. mobile. www. www[0-9]. ww[0-9].
// hostnameRoot.js -- returns URL/location.hostname with certain prefixes removed: m. mob. mobi. mobile. www. www[0-9]. ww[0-9].
const hostnameRoot = hostname => String(hostname ?? "")
.toLowerCase()
.replace(
/^(m(ob(i(le)?)?)?|ww(w?\d|w))\.(.+?\..+)/,
"$6"
);
console.log([