Skip to content

Instantly share code, notes, and snippets.

View jonrandy's full-sized avatar
✴️
Sentient

Jon Randy jonrandy

✴️
Sentient
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Basic HTML5 Template</title>
<link href="stylesheets/style.css" rel="stylesheet" type="text/css" media="screen" />
<script src="example.js"></script>
</head>
<body>
@jonrandy
jonrandy / programming-as-theory-building.md
Created June 7, 2020 07:08 — forked from onlurking/programming-as-theory-building.md
Programming as Theory Building - Peter Naur

Programming as Theory Building

Peter Naur

Peter Naur's classic 1985 essay "Programming as Theory Building" argues that a program is not its source code. A program is a shared mental construct (he uses the word theory) that lives in the minds of the people who work on it. If you lose the people, you lose the program. The code is merely a written representation of the program, and it's lossy, so you can't reconstruct

@jonrandy
jonrandy / load_images.js
Created February 28, 2021 04:42
Load Images in JS, do something when loaded
function loadImage(url) {
return new Promise((resolve, reject) => {
let img = new Image();
img.addEventListener('load', e => resolve(img));
img.addEventListener('error', () => {
reject(new Error(`Failed to load image's URL: ${url}`));
});
img.src = url;
});
}
@jonrandy
jonrandy / decorate.js
Last active February 28, 2021 04:42
Function Decoration Idea in JS
// function decorating in JS
function ___(wrapper) {
return function wrap(f) {
let a = { [f.name] : function(...args) {return wrapper.call(this, f, ...args)} }
return this[f.name] = a[f.name]
}
}
function $__(inner) {
@jonrandy
jonrandy / zxspec-y.js
Created February 28, 2021 08:22
Speccy Memory Y-coordinates
// Speccy memory addresses for y-coords on screen (first byte)
let list = [], third, midblock, fine, i;
for (i=0;i<192;i++) {
third = i&192 ;
midblock = (i&56)>>3 ;
fine = (i&7)<<3 ;
list.push(midblock+third+fine)
}
@jonrandy
jonrandy / getFlagEmoji.js
Created April 9, 2021 11:26
Two letter country code to Flag Emoji
const getFlagEmoji = countryCode=>String.fromCodePoint(...[...countryCode.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt(0)))
@jonrandy
jonrandy / numberSpread.js
Last active September 13, 2021 05:28
Spreading Numbers
Number.prototype[Symbol.iterator] = function* () {
for (let i = 1; i <= this; i++) yield i
}
[...5] // [1,2,3,4,5]
@jonrandy
jonrandy / isValidCSSColour.js
Created January 5, 2022 04:09
isValidCSSColour
const isValidCSSColour = str => {
const s = new Option().style
s.color = str
return s.color != ''
}
@jonrandy
jonrandy / isPrimeRegex.js
Last active May 31, 2022 03:34
isPrime using regex
const isPrime = x=>!'1'.repeat(x).match(/^1?$|^(11+?)\1+$/)