Skip to content

Instantly share code, notes, and snippets.

View raganwald's full-sized avatar

Reg Braithwaite raganwald

View GitHub Profile
let Person = (() = > {
let firstNameProperty = Symbol('firstName'),
lastNameProperty = Symbol('lastName'),
renameMethod = Symbol('rename');
return class Person {
constructor (first, last) {
this[renameMethod](first, last);
}
fullName () {
@raganwald
raganwald / javascript-allonge-kindle.md
Last active August 29, 2015 14:21
Sending JavaScript Allongé to a Kindle

Reading JavaScript Allongé on Kindle

JavaScript Allongé has over 400 pages and many photographs. For this reason, the .mobi version of the book is too big to be sent to your Kindle via email.

Send to Kindle

If you wish to read JavaScript Allongé on your Kindle, please:

  1. Download it to your PC or Mac.
  2. Use Send to Kindle for PC or Send to Kindle for Mac to send it to the Kindle.
@raganwald
raganwald / ring.es6
Created May 23, 2015 14:06
Secret Decoder Ring
const SecretDecoderRing = {
encode: function (plaintext) {
return plaintext
.split('')
.map( char => char.charCodeAt() )
.map( code => code + 1 )
.map( code => String.fromCharCode(code) )
.join('');
},
decode: function (cyphertext) {
@raganwald
raganwald / invoke.md
Last active February 16, 2016 08:27
Why I’m Rewriting JavaScript Allongé in ES-6

Because combinators like this:

var __slice = Array.prototype.slice;

function invoke (fn) {
  var args = __slice.call(arguments, 1);
  
  return function (instance) {
 return fn.apply(instance, args)
@raganwald
raganwald / infinity.md
Last active December 21, 2022 03:12
Infinity to the power of infinity

(from Hilbert's Grand JavaScript School)


day six

Bertie goes home, exhausted, and dreams that having graduated everyone at the end of Day Five, things are busier than ever. In his dreams he imagines an infinite number of galactic superclusters, each containing an infinite number of galaxies, each containing an infinite number of stars, each containing an infinite number of worlds, each containing an infinite number of oceans, each containing an infinite number of aircraft carriers, each containing an infinite number of buses, each containing an infinite number of students.

He awakens and reasons that what he is dealing with are powers of infinity. A simple infinity is infinity to the first power. Two infinities (buses and students) is infinity to the second power. Three infinities (aircraft carriers, buses, and students) is infinity to the third power. And so forth up to galactic superclusters, infinity to the eighth power.

@raganwald
raganwald / if-as-expression.coffee
Last active August 29, 2015 14:19
The way I usually format if-as-expressions
something = if condition
value-if-truthy
else
value-if-falsy
@raganwald
raganwald / left-variadic.md
Created April 1, 2015 19:21
leftVariadic in ECMAScript 2015

In JavaScript, you can make a right-variadic function by gathering parameters. For example:

const abccc = (a, b, ...c) => {
  console.log(a);
  console.log(b);
  console.log(c);
};

abccc(1, 2, 3, 4, 5)
@raganwald
raganwald / any-partial-application.js
Created April 1, 2015 15:02
anyPartialApplication
const div = (verbed, numerator, denominator) =>
`${numerator} ${verbed} ${denominator} is ${numerator/denominator}`
div('divided by', 1, 3)
//=> 1 divided by 3 is 0.3333333333333333
const anyPartialApplication = (() => {
const placeholder = {},
anyPartialApplication = (fn, ...template) => {
let remainingArgIndex = 0;
@raganwald
raganwald / flip-flop-merge-sort.js
Last active April 27, 2016 04:38
Merge Sort in JavaScript
const sorted = arr => {
const length = arr.length;
let unsorted = new Array(length),
sorted = new Array(length);
const destructiveSort = (unsorted, sorted, offset, length) => {
if (length === 1) {
sorted[offset] = unsorted[offset];
}
const arrayIterator = (array) => {
let i = 0;
return () => {
const done = i < array.length;
return {
done,
value: done ? undefined : array[i++]
}