Skip to content

Instantly share code, notes, and snippets.

View pvande's full-sized avatar

Pieter van de Bruggen pvande

View GitHub Profile
var hasOwn = {}.hasOwnProperty;
export default function classNames() {
var result = '';
var seen = new Object(null);
var pending = [ arguments ];
while (pending.length) {
var list = pending.pop();
var len = list.length;

We must strive to understand that accidents don’t happen because people gamble and lose. Accidents happen because the person believes that what is about to happen is not possible, or what is about to happen has no connection to what they are doing, or that the possibility of getting the intended outcome is well worth whatever risk there is.

  • Erik Hollnagel
# Casual Grammar
/{{\s*\W?\s*\w+\s*}}|{{!.*?}}|{{{\s*(\w+)\s*}}}/g
# Informal Grammar
<template> ::= (<static-content> <tag>)* <static-content>
<static-content> ::= <text>+
<tag> ::= "{{" <whitespace>* [<tag-type>] <whitespace>* <tag-name> <whitespace>* "}}" |
@pvande
pvande / gist:3814296
Created October 1, 2012 20:43
CoffeeScript Raytracer
class Vector
constructor: (@x, @y, @z) ->
@times: (k, {x,y,z}) -> new this(k * x, k * y, k * z)
@minus: (a, b) -> new this(a.x - b.x, a.y - b.y, a.z - b.z)
@plus: (a, b) -> new this(a.x + b.x, a.y + b.y, a.z + b.z)
@dot: (a, b) -> a.x * b.x + a.y * b.y + a.z * b.z
@mag: ({x,y,z}) -> Math.sqrt(x * x + y * y + z * z)
@norm: (v) -> @times(1.0 / @mag(v), v)
@cross: (a, b) -> new this(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x)
<error>
Batman.SimpleHash.SimpleHash.hasKey:1037
Batman.SimpleSet.SimpleSet.add:1226
Batman.Event.Event.addHandler:300
(anonymous function):519
(anonymous function):527
Batman.SimpleSet.SimpleSet.forEach:1258
Batman.SimpleHash.SimpleHash.forEach:1115
Batman.SimpleHash.SimpleHash.forEach:1118
Batman.SimpleSet.SimpleSet.forEach:1257
class Batman.Controller.WithLayout extends Batman.Controller
@contentFor: 'action'
@beforeFilter 'renderLayout'
renderLayout: ->
@layout = new Batman.View(source: @get('controllerName') + '.html')
Batman.currentApp?.prevent 'ready'
@layout.contexts.push this
@layout.on 'ready', =>
Batman.DOM.replace 'main', @layout.get('node')
@pvande
pvande / index.js
Created May 17, 2011 09:47 — forked from 140bytes/LICENSE.txt
Calculate the distance in days
function(d,n){d=(n=(d=~~((new Date-d)/8.64e7))<0)?-d:d;return d?d+' day'+(d>1?'s ':' ')+['ago','from now'][n+0]:'today'}
multiline
partial
with some
existing
indentation
@pvande
pvande / gist:881504
Created March 22, 2011 16:21
Ruby Gripe List
# Qualified constant names are broken
class X
def self.const_missing(name)
raise "Nope!"
end
end
X::String # => ::String
X::Object # => ::Object
::X::Kernel # => ::Kernel
@pvande
pvande / gist:854178
Created March 4, 2011 04:41
Some benefits come from writing the Mustache spec as YAML...
# Run with a recent version of Mustache
# Run from the root of a clone of https://github.com/mustache/spec
ruby -rubygems -ryaml -e 'require "mustache"' \
-e 'tmpl = "**{{file}}**\n\n{{overview}}\n{{#tests}} * {{desc}}\n{{/tests}}\n\n"' \
-e 'ARGV.map { |f| puts Mustache.render(tmpl, YAML.load_file(f).merge(:file => f)) }' -- specs/*.yml