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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getFlagEmoji = countryCode=>String.fromCodePoint(...[...countryCode.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt(0))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number.prototype[Symbol.iterator] = function* () { | |
for (let i = 1; i <= this; i++) yield i | |
} | |
[...5] // [1,2,3,4,5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add(target, f, outerSyntax=false){ | |
return f.length ? | |
outerSyntax ? | |
addProperty(target, f) | |
: | |
addWithParams(target, f) | |
: | |
addSimple(target, f) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer