Skip to content

Instantly share code, notes, and snippets.

View DarrenSem's full-sized avatar

Darren Semotiuk DarrenSem

View GitHub Profile
@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 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)=
@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 / 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 March 5, 2024 22:47
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
// FEAT: 05Mar2024 prompt skipped if isLocalFileMHT (but NOT for every "file:" === location.protocol) because MHT files apparently disables prompt() (even when from F12 -- since they won't run Bookmarklets)
// 3458 char javascript:void function(){"use strict";const a=((a,b,c,e,f,g,d,h)=>(b=new Date(a||Date()),[c,e,,f]=b.toLocaleTimeString().split(/\W/),[,,g,d]=b.toString().split(" "),h=b.toLocaleString().split("/")[0].padStart(2,0),`${c}${e}${(f||"").toLowerCase()} ${d}-${h}-${g}`))();let b=`${""} ${a}`;const c=top.document,d=location,e=(a,b)=>(b||c).querySelectorAll(a||null),f=(a,b,c)=>{let d,f,g;c?(d=e(b?"div>div>span.chat-message-role-text":"div",a)[0],f=b?d?.parentElement?.parentElement?.parentElement:a,g=f&&e("div>textarea.text-input",f)[0]):(f=e(":scope>div>div>div+div>div>div>div",a)[0],d=f&&f.parentElement.parentE
@DarrenSem
DarrenSem / contentsInNewWindow.js
Last active October 15, 2023 17:28
OpenInNewWindow(data, type) - F5-REFRESHABLE! - auto-UTF8 if type==="text"! - also ContentsInNewWindow(contents = '' or [], Title, type, delimToJoinArray = "\n\n")
// contentsInNewWindow.js - F5-REFRESHABLE! - with TITLE! - (contents = '' or [], title, type = 'octet-stream', array-joining-delim = '\n\n')
// const contentsInNewWindow=(c=[],T,t="octet-stream",d="\n\n")=>{const w=open(URL.createObjectURL(new Blob([[c].flat(1/0).join(d)],{type:"text"===t?t+"/plain;charset=utf-8":t})),"_blank");return w&&!w.closed&&(w.onload=()=>w.document.title=T),w};
const contentsInNewWindow = (contents = [], title, type = ["text", "octet-stream"][1], delim = "\n\n") => {
const win = open(
URL.createObjectURL(
new Blob([
[contents].flat(1/0).join(delim)
], {
// auto-UTF8 if type === 'text', to easily ensure visible emojis etc.
@DarrenSem
DarrenSem / download.js
Last active November 18, 2022 00:09
download.js: SAVE data TO file (aka 'export/download') plus openInNewWindow(data, type = "octet-stream")
/////// download.js: SAVE data TO file (aka 'export/download')...
//// const download_MIN=(d,f=`file-${+new Date}.txt`,t="octet-stream")=>{const h=URL.createObjectURL(new Blob([d].slice(void 0===d),{type:t})),s=null!==f;return Object.assign(document.createElement("a"),{href:h,[s&&"download"]:f,target:"_blank"}).click(),s&&URL.revokeObjectURL(h)};
const download = (
data
, filename = `file-${+new Date}.txt` // null means download: filename OMITTED = DISPLAY data in browser
, type = "octet-stream" // default is ~ "application/octet-binary"
) => {
const href = URL.createObjectURL(new Blob( // https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob
[data].slice(data === undefined)
@anuraghazra
anuraghazra / minimal-templating-engine.ts
Last active October 28, 2023 09:07
Minimal Templating Engine In Javascript
// magic!
function dom<Props extends Record<string, unknown>>(
str: TemplateStringsArray,
...args: string[] | ((props: Props) => string)[]
) {
const interleaved = args.flatMap((arg, index) => {
return [arg, str[index + 1]];
});
return (props?: Props) =>
@zedeus
zedeus / following.py
Created September 2, 2019 21:06
Fetch Twitter following list
import requests, re, sys
url = "https://mobile.twitter.com/{}/following"
cursor = ""
usernames = []
first = True
if len(sys.argv) < 2:
print("Usage: python followers.py <username>")
quit(1)
@gaearon
gaearon / index.html
Last active February 13, 2024 09:46
Multiple React components on a single HTML page
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Add React in One Minute</title>
</head>
<body>
<h2>Add React in One Minute</h2>
<p>This page demonstrates using React with no build tooling.</p>