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
Declarative programming: Expresses the logic of a computation without describing its control flow. (e.g., no loops) | |
e.g., SQL, RegExp, Markdown | |
example: SELECT * FROM table; | |
Imperative programming: Uses statements that change a program's state. Consists of commands for the computer to perform. | |
e.g., OpenGL, Canvas, Turtle, GCode, ASM, FORTRAN, SVG | |
example: while (true): up(1); right(2); stroke(); done(); | |
Procedural programming: Derived from structured programming, based upon the concept of the procedure call. | |
Procedures, also known as routines, subroutines, or functions (not to be confused with mathematical functions, |
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
// LOL! Look at this... | |
// This class syntax is very shorthand, inline, and anonymous. | |
// However I'm skeptical that the runtime interpreter is able to optimize it | |
// like traditional class semantics. | |
// class | |
const State = () => ({ | |
// constructor | |
object: {}, | |
array: [], |
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
; Ctrl-Shift-O | |
^!o:: | |
; wait 2 seconds | |
Sleep, 2000 | |
; type out clipboard contents | |
sendraw %clipboard% |
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
// render .styl to .css every request; skips output file to local disk | |
app.use((req, res, next) => { | |
const stylus = require('stylus'); | |
const join = require('path').join; | |
const src = join(__dirname, '/../public'); | |
const url = require('url'); | |
const fs = require('fs'); | |
if ('GET' !== req.method && 'HEAD' !== req.method) return next(); | |
const path = url.parse(req.url).pathname; | |
if (!/\.css$/.test(path)) return next(); |
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
Array.prototype.flatMap || (Array.prototype.flatMap = function () { // shim for draft proposal | |
return this.reduce(((acc,v)=>(acc.push(...v),acc)),[]); }); |
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
// e.g., when you want parameters passed in a pre-sorted order, but you don't want to impose on the developer | |
{ // shadow to avoid mutating input | |
// three examples computing Math.min() just once, though two assignments: | |
const toZero = Math.min(a,c), a = a - toZero, c = c - toZero; // toZero still in scope by EOL (wasteful?) | |
with({toZero:Math.min(a,c)}) const [a,c] = [a-toZero,c-toZero]; // toZero out of scope by EOL (discouraged in "use strict" mode) | |
const [a,c] = [a,c].map((toZero=>v=>v-toZero)(Math.min(a,c))); // toZero out of scope by EOL | |
const [a,c] = (()=>{ const toZero = Math.min(a,c); return [a-toZero,c-toZero]; })(); // toZero out of scope by EOL (long-winded) | |
} |
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 crossJoin = (...args) => { | |
const m = args.reduce((acc,a)=>{ | |
acc.push(0 === acc.length ? | |
a.length : | |
(acc[acc.length-1] * a.length)); | |
return acc; | |
},[]); | |
const o = []; | |
for (const [i,letters] of args.entries()) { |
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 sortBy = (...k) => (a,b) => ((k)=> (null==k || a[k]===b[k]) ? 0 : a[k]<=b[k] ? -1 : 1 )(k.find(_k=>a[_k]!==b[_k])); |
OlderNewer