Skip to content

Instantly share code, notes, and snippets.

View raganwald's full-sized avatar

Reg Braithwaite raganwald

View GitHub Profile
@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 / 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 / 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 / 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.
let Person = (() = > {
let firstNameProperty = Symbol('firstName'),
lastNameProperty = Symbol('lastName'),
renameMethod = Symbol('rename');
return class Person {
constructor (first, last) {
this[renameMethod](first, last);
}
fullName () {
# See https://twitter.com/fogus/status/623312803345117184
def meth a, b, c
[yield(a), yield(b), yield(c)]
end
meth(1, 2, 3) { |x| x * x }
# => [1, 4, 9]
arr = [1962, 6, 14, lambda { |x| x.to_s }]

Many an idea or concept not only looks, but is good in its infancy, yet turns destructive later in life. Scaling and maturation are not the obvious processes they appear to be because they take so much time that the accumulated effort is easy to overlook.

To be successful, they must also be very carefully guided by people who can envision the end result, but that makes it appear to many as if it merely "happens." Take a good idea out of its infancy, let it age without guidance so it does not mature, and it generally goes bad.

Erik Naggum on XML

@raganwald
raganwald / even-stevens.es6
Created August 10, 2015 13:02
evenStevens is read-only
const evenStevens = (n) => {
if (n === 0) {
return true;
}
else if (n == 1) {
return false;
}
else {
n = n - 2;
return evenStevens(n);
@raganwald
raganwald / gist:1653890
Created January 21, 2012 20:27 — forked from panicsteve/gist:1641705
Form letter template for open source abandonware
Dear soon-to-be-former user,
We've got some fantastic news! Well, it's great news for us anyway. You, on
the other hand, are fucked.
We've just been acquired by:
[ ] Facebook
[ ] Google
[ ] Twitter
@raganwald
raganwald / gist:3932975
Created October 22, 2012 17:56
Discrepancy between CoffeeScript on Node and "Try CoffeeScript"
This CoffeeScript:
name = 'clyde'
do ->
"Hello #{name}" for name in ['algernon', 'sabine', 'rupert', 'theodora']
name
Complies to this on CoffeeScript under Node:
(function() {