Skip to content

Instantly share code, notes, and snippets.

View raganwald's full-sized avatar

Reg Braithwaite raganwald

View GitHub Profile
@raganwald
raganwald / gist:5334010
Created April 8, 2013 03:18
Looking for raganwald?
I searched Google for "raganwald." The top link was:
https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&sqi=2&ved=0CC8QFjAA&url=https%3A%2F%2Ftwitter.com%2Fraganwald&ei=pDZiUYORKMSi2wXM8YH4CQ&usg=AFQjCNHRVgeFXjNcWtJ8_I6Yc69RrXckWg&sig2=vcrLpvJwepPmFC2aNPOCZg&bvm=bv.44770516,d.b2I
I shit you not.
@raganwald
raganwald / bound.js
Last active December 18, 2015 12:29 — forked from seidtgeist/bound.js
function bound(object, fn) {
return object[fn].bind(object);
}
@raganwald
raganwald / All.js
Last active December 18, 2015 14:59
I may not be able to define the List Monad, but I know it when I see it...
function mapConcat (choices) {
return function (list) {
return _.map(choices, function (choice) {
return list.concat([choice])
})
}
}
function flatMapWith (fn, list) {
return _.reduce(list, function (acc, element) {
@raganwald
raganwald / wtf.js
Last active December 18, 2015 23:08
This morning's "I made my very own WTF!?"
// I'm in the middle of a method, and I decide that I'll use an
// Immediately Invoked Function Expression ("IIFE") to create a new
// block scope so that I don't have to pollute the entire thing with
// resultJSON and contentJSON variables that would otherwise get
// hoisted.
//
// The current object DOES have a toJSON method, and so does the object called content.
// _.isFunction(this.toJSON) ==> true
// _.isFunction(content.toJSON) => true
@raganwald
raganwald / multiple-dispatch.js
Last active August 13, 2019 11:20
Multiple dispatch in JavaScript
function isType (type) {
return function (arg) {
return typeof(arg) === type;
};
}
function instanceOf (clazz) {
return function (arg) {
return arg instanceof clazz;
};
@raganwald
raganwald / p.jsredicate-dispatch
Last active August 29, 2015 14:02
Faking Predicate Dispatch in JavaScript
function nameAndLength(name, length, body) {
var abcs = [ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l',
'z', 'x', 'c', 'v', 'b', 'n', 'm' ],
pars = abcs.slice(0, length),
src = "(function " + name + " (" + pars.join(',') + ") { return body.apply(this, arguments); })";
return eval(src);
}
@raganwald
raganwald / record.js
Last active August 29, 2015 14:03
Records, Values, and Structs
function Record (template) {
if (Record.prototype.isPrototypeOf(this)) {
var struct = this;
Object.keys(template).forEach(function (key) {
Object.defineProperty(struct, key, {
enumerable: true,
writable: true,
value: template[key]
});
@raganwald
raganwald / better.md
Last active August 29, 2015 14:06
A "better web experience"

Some people have told me that they WANT companies knowing their preferences to create a "better web / inter webs experience"

--Alan Armstrong

Typically, people assume that if companies have lots of information about them, the Internet will be pretty-much the same as it is today except the ads will all be for things they like. Win-win!

But that's not how it works. It's not just the ads that will change. Reality as you perceive it will change. When friends post complaints about products, you will see less of those complaints on Facebook and Twitter, and you'll see more positive reviews, because that's what encourages you to click on ads and buy things.

What they know about you will affect what you see on social media like Facebook or Twitter, what news stories will appear when you go to a "newspaper" like torontostar.com, and what products you will find when you do a search on Google, within Amazon, or on eBay.

@raganwald
raganwald / keybase.md
Created September 20, 2014 14:25
keybase.md

Keybase proof

I hereby claim:

  • I am raganwald on github.
  • I am raganwald (https://keybase.io/raganwald) on keybase.
  • I have a public key whose fingerprint is EE3E ACF3 8CA5 C802 06D8 6267 D0F0 5DF6 75DD 151D

To claim this, I am signing this object:

@raganwald
raganwald / mtb.md
Last active August 29, 2015 14:08
My Mountain Bike Blues

MTB Blues

I've been riding a geared, full-suspension 26er mountain bike for three months now. It is not ridiculously heavy. It is not lightening fast. It has nine different gears, which are eight more than a singlespeed, and two fewer than the latest trick componentry. Its suspensions is around 140mm, which can handle most trail things but not, I imagine, massive hucking. It seems from my inexperienced view to be a competent but uninspiring machine.

Despite its stolid capabilities, I struggle to feel comfortable with it.

my mountain bike

My new bike has 26" wheels. A few die hards laugh and say a good rider can ride anything, but this logic is obviously flawed: Yes, the fittest rider in any group can ride the lowest-performing bike, but we can't all be the fittest rider: Most of us have to be clustered around the mean. That's science, folks. If I'm in pretty-much the same shape as everyone else, and if I'm working 3% harder than everyone els