Skip to content

Instantly share code, notes, and snippets.

View pvdz's full-sized avatar

Peter van der Zee pvdz

View GitHub Profile
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Prototypal inheritence</title>
</head>
<body>
<form>
<div><button onclick="animal.speak();return false;">animal.speak()</button></div>
<div><button onclick="dog.speak();return false;">dog.speak()</button></div>
@pvdz
pvdz / LICENSE.txt
Created September 8, 2011 07:17 — forked from binarymax/LICENSE.txt
isSubset
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Max Irwin http://www.binarymax.com/
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Not intended to be fast.
var WebVTTCueTextParser = (function(){ // this will return just the WebVTTCueTextParser function and not leak anything else
// local scope:
var
NEWLINE = /\r\n|\r|\n/,
SPACE = /[\u0020\t\f]/,
NOSPACE = /[^\u0020\t\f]/
// the case:
// runner.js
module.exports = {
arr: [],
fetch: function(str){ this.arr.push(str); }
};
// mod1.js
module.exports = function(){
@pvdz
pvdz / gist:1745582
Created February 5, 2012 13:27
ZeParser syntax highlighter
var parser = ZeParser.createParser(value);
parser.tokenizer.fixValues();
var ide = parser.tokenizer.wtree.map(function(t){
if (t.name == 14) ta.className = 'error';
return '<span class="t'+t.name+'">'+(t.name==13?'\u29e6':(t.name==14?'\u292c':t.value))+'</span>';
});
div.innerHTML = ide.join('');
var parser = ZeParser.createParser(ta.value);
parser.tokenizer.fixValues();
var wtree = parser.tokenizer.wtree;
ta.className = '';
var ide = wtree.map(function(t){
if (t.name == 14) ta.className = 'error';
return '<span class="t'+t.name+'">'+(t.name==13?'\u29e6':(t.name==14?'\u292c':t.value)).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')+'</span>';
});
@pvdz
pvdz / nca.js
Created May 29, 2012 12:38
NCA fallback library
var NCA = function(type, version, compiler){
this.type = type;
this.version = version;
// compiler must have interface method "compile",
// which accepts a string as single argument
this.compiler = compiler;
};
NCA.prototype = {
queue: [],
fetching: false,
@pvdz
pvdz / gist:2830474
Created May 29, 2012 20:22
ZeParser tagliteral post to DOM syntax
// requires ZeParser (see repo)
// input is a string, your js input with tagliterals
function compile(input){
var tree = [];
var tokenizer = new Tokenizer(input);
tokenizer.tagLiterals = true; // enable tag literals in the engine
var parser = new ZeParser(input, tokenizer, tree);
parser.parse();
tokenizer.fixValues();
var ordered = pieces.slice(i).sort(function(a,b){
var pa = this.distanceBetween(p,a);
var pb = this.distanceBetween(p.b);
if (pa < pb) return -1;
if (pa > pb) return 1;
return 0;
}.bind(this));
@pvdz
pvdz / gist:3878890
Created October 12, 2012 12:02
ace get linear caret position wot?
getCharPos1: function() {
// Get cursor position
var charPos = 0;
var cursorPos = this.editor.getCursorPosition();
for (var i=0; i<cursorPos.row; i++){
charPos += this.editor.session.$rowLengthCache[i]; // +1 for newline
}
charPos += cursorPos.column + cursorPos.row; // Add row count to compensate for newlines
return charPos;