Skip to content

Instantly share code, notes, and snippets.

View jonrandy's full-sized avatar
✴️
Sentient

Jon Randy jonrandy

✴️
Sentient
View GitHub Profile
@jonrandy
jonrandy / fake_photos.md
Created August 13, 2026 08:19
Checking for Fake/AI Generated Photos

So you don't have to rely on instinct, always check in this order. Four letters, ISLP:

  • I, Iris. Round, no deformation. And read its reflection: it tells you what light was there. If that light makes no sense with the rest, the image is lying.
  • S, Skin. Real pores, not a suffocatingly clean uniformity or freckles laid down like a stencil.
  • L, Light and shadow. They must make sense in context. One sun for the whole scene. No shadow without a body to cast it.
  • P, Physics. The laws must hold. Blur that's gradual, not a 2D backdrop. Glasses with lenses, a bridge and arms. Optics and framing that could live together in a real camera.
@jonrandy
jonrandy / reference_links.md
Last active July 10, 2026 02:32
Markdown Reference Links
@jonrandy
jonrandy / return_submit_ime.js
Created July 3, 2026 03:55
How to handle 'enter' form submission WITHOUT breaking IME input (Korean, Japanese, Chinese etc.)
// put this in key event - key 229 is legacy (older browser send different 'key' for return while composing)
if (e.isComposing || e.keyCode === 229) return;
// safe to submit here if you want
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/isComposing
@jonrandy
jonrandy / promise-all.js
Created May 26, 2026 06:12
Promise.all Implementation in JS
const all = async arr => {
const results = []
for (p of arr) results.push(await p)
return results
}
@jonrandy
jonrandy / closure.js
Created September 6, 2025 08:44
Schroedinger's Closure
function makeFunction() {
let myVar = 123
return function (s) {
console.log(eval(s))
}
}
const func = makeFunction()
@jonrandy
jonrandy / hashmod.html
Created April 8, 2025 06:45
HTML Hash Modules (self contained JS modules in an HTML file)
<!doctype html>
<html lang="en">
<body>
<script type="hash-module" id="sum">
export const sum = (a, b) => a + b;
</script>
<!-- All hash modules need to go before this script. -->
<!-- This cant be a type="module", it must be executed immediately. -->
<script>
@jonrandy
jonrandy / range.js
Last active July 16, 2024 14:21
Range
const to = Symbol('number to')
// Number.prototype[to] = function to(end) {
// let [start, tend, rev] = (this>end) ? [end, this, true] : [this, end, false], arr = []
// for (let i=start; i<=tend; i++) arr.push(i)
// return rev ? arr.sort(_=>1) : arr
// }
Number.prototype[to] = function to(end, {step}={step:this<=end?1:-1}) {
let arr = [], i, d = end>this
@jonrandy
jonrandy / metho.js
Last active July 16, 2024 14:21
Add parameterised methods safely to prototypes etc.
function add(target, f, outerSyntax=false){
return f.length ?
outerSyntax ?
addProperty(target, f)
:
addWithParams(target, f)
:
addSimple(target, f)
}
@jonrandy
jonrandy / golf.js
Created October 25, 2021 02:50
JS Golfing Tips
var n = 53.73;
var rounded = n|0; //53
x|0 //Round x down
func`arg` //Call function with one string argument
getContext`2d`; // ^
`rgb(${r}, ${g}, ${b})` //Template literals
C //together with <canvas id=C> instead of document.getElementById("C");
1e3 //Shorter than 1000
1e-3 //Shorter than 0.001
@jonrandy
jonrandy / splitIntegerByRatios.js
Created May 31, 2022 03:33
Split integer by ratios
function allocateInt(amount, ratios) {
if (ratios.length == 1) {
return [amount]
} else {
const rs = [...ratios]
const divisor = rs.reduce((a,i)=>a+i)
const thisAmount = Math.round(amount*rs.shift()/divisor)
return [
thisAmount,
...allocateInt(amount-thisAmount, rs)