Consistency in naming makes reading and memory retrieval much, much easier. Conversely, changing rules and mixing conventions are very confusing and significantly increase cognitive load. Follow language, company, and project conventions for names, even if you don't like them.
This document is an attempt to pin down all the things you don't think about when quoting for a project, and hopefully provide a starting point for some kind of framework to make quoting, working and delivering small-medium jobs more predictable and less stressful.
type RGBA = [number, number, number, number]; | |
const rgb255 = (v: number) => (v < 255 ? (v > 0 ? v : 0) : 255); | |
const b1 = (v: number) => (v > 0.0031308 ? v ** (1 / 2.4) * 269.025 - 14.025 : v * 3294.6); | |
const b2 = (v: number) => (v > 0.2068965 ? v ** 3 : (v - 4 / 29) * (108 / 841)); | |
const a1 = (v: number) => (v > 10.314724 ? ((v + 14.025) / 269.025) ** 2.4 : v / 3294.6); | |
const a2 = (v: number) => (v > 0.0088564 ? v ** (1 / 3) : v / (108 / 841) + 4 / 29); | |
function fromHCL(h: number, c: number, l: number): RGB { | |
const y = b2((l = (l + 16) / 116)); | |
const x = b2(l + (c / 500) * Math.cos((h *= Math.PI / 180))); |
So there were a few threads going around recently about a challenge to write the longest sequence of keywords in Javascript:
- https://twitter.com/bterlson/status/1093624668903268352
- https://news.ycombinator.com/item?id=19102367
There are, however, a few problems:
When you create a npm package, remember it might be used in a browser or a server, or even a command line utility… For each package you create, please pay attention at what it will be used for:
- Is it going to be used as a dependency to a nodejs application that is not bundled? (e.g. command line utilities)
- Is it going to be used as a dependency to a nodejs application that is bundled? (e.g. AWS Lambdas)
- Is it going to be used as a dependency to a browser application (always bundled)?.
- In cases 2) and 3) you want to allow for tree shaking.
- In cases 1) and 2) you want to benefit from the "ES6"/"ES next" features supported natively by nodejs.
- In case 3) you also want to benefit from the native support of "ES6" from your browser.
/** | |
* Making promises | |
*/ | |
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok")); | |
/* Simpler promise creation for static values */ | |
Js.Promise.resolve("easy"); | |
Js.Promise.reject(Invalid_argument("too easy")); |
"use strict"; | |
const clamp = (num, min, max) => num < min ? min : num > max ? max : num; | |
/** Given a temperature (in Kelvin), estimate an RGB equivalent | |
* @param {number} tmpKelvin - Temperature (in Kelvin) between 1000 and 40000 | |
* @returns {{r:number, g:number, b:number}} - RGB channel intensities (0-255) | |
* @description Ported from: http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/ | |
*/ | |
exports.getRGBFromTemperature = function(tmpKelvin) { |
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' + | |
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' + | |
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' + | |
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));'; | |
try { | |
eval(str); | |
} catch(e) { | |
alert('Your browser does not support ES6!') | |
} |
Redux was developed to achieve hot reloading global state and state changing logic. To achieve that it was necessary for state changes to be run with pure functions and the state has to be immutable. Now you can change the logic inside your reducer and when the application reloads Redux will put it in its initial state and rerun all the actions again, now running with the new state changing logic.
Cerebral had no intention of achieving hot reloading. Cerebral was initially developed to give you insight into how your application changes its state, using a debugger. In the Redux debugger you see what actions are triggered and how your state looks after the action was handled. In Cerebral you see all actions fired as part of a signal. You see asynchronous behaviour, paths taken based on decisions made in your state changing flow. You see all inputs and outputs produced during the flow and you even