Skip to content

Instantly share code, notes, and snippets.

View olov's full-sized avatar

Olov Lassus olov

  • Linköping, Sweden
View GitHub Profile
d8 --shell shaper.js
V8 version 3.3.1 [console: readline]
d8> var hello = Shaper.parseExpression("document.getElementById('hello')")
d8> var templ = Shaper.parseExpression("$.getElementById($$)")
d8> Shaper.match(templ, hello)
1
@olov
olov / references.rb
Last active September 25, 2015 17:58
Jekyll markdown references plugin by Olov Lassus: Keep all your markdown reference-style link definitions in one file (_references.md)
# references.rb has moved to https://github.com/olov/jekyll-references
@olov
olov / gist:1320163
Created October 27, 2011 17:10
Pygments DartLexer for syntax highlighting. Example and installation instructions: <http://blog.lassus.se/2011/10/dart-syntax-highlighting.html>
class DartLexer(RegexLexer):
"""
For `Dart <http://dartlang.org/>`_ source code.
"""
name = 'Dart'
aliases = ['dart']
filenames = ['*.dart']
mimetypes = ['text/x-dart']
@olov
olov / gist:2731048
Created May 19, 2012 14:36
the Bash mp3 links
http://dl.dropbox.com/u/283098/the%20Bash/the%20Bash%20-%20Cashkeeper.mp3
http://dl.dropbox.com/u/283098/the%20Bash/the%20Bash%20-%20Come%20on.mp3
http://dl.dropbox.com/u/283098/the%20Bash/the%20Bash%20-%20Join%20the%20bash.mp3
http://dl.dropbox.com/u/283098/the%20Bash/the%20Bash%20-%20Tears%20and%20smiles%20%28edit%29.mp3
http://dl.dropbox.com/u/283098/the%20Bash/the%20Bash%20-%20To%20it%20%28now%29.mp3
http://dl.dropbox.com/u/283098/the%20Bash/the%20Bash%20-%20Una%20mas%20%28edit%29.mp3
http://dl.dropbox.com/u/283098/the%20Bash/the%20Bash%20-%20Where%27s%20your%20mind.mp3
Would you be OK with your internet bank saying "our position is
that we recommend a private connection over HTTPS but you can
always scrap that and send your private login credentials in
clear text directly in the URL instead. Over HTTP of course, if
you find that convenient. Choice is good and we want to make you
happy"?
I wouldn't, because it would tell me that they are clueless about
security or that they don't care about their user's money and/or
privacy.
@olov
olov / nan.js
Created June 14, 2013 13:43
Which arithmetic operators in JS can yield a NaN given non-NaN (numeric) operands:
"use strict";
const vals = [
0,(-0),1,-1,Infinity,-Infinity,
];
const binops = [
"&", "|", "^", ">>", "<<", ">>>",
"+", "-", "*", "/", "%",
"&&", "||"
@olov
olov / ES6 consts
Last active December 21, 2015 05:18
[:~/projects/js] % cat const.js
"use strict"; // required to opt-in ES6 block scope in V8 for now
console.log("const assignment error is caught at parse-time so this doesn't get printed");
const limit = 100;
limit = 200;
console.log(limit);
[:~/projects/js] % node --harmony const.js
/Users/olov/projects/js/const.js:4
limit = 200;
Lot's of good stuff from Ariya as always and expected! :) I wanted to chime in with a couple of comments regarding ES6 block scope, const in particular. It's kind of a pet-peeve of mine (I'm the author of the defs transpiler).
The article describes Mozilla-JS const, not ES6 const. Mozilla-JS const is not block scoped and is silent on reassignment. ES6 const is block scoped and reassignment is a static error found at parse time (see https://gist.github.com/olov/6255863) before program execution. Do note that you have to opt-in to using ES6 const in v8/node via strict mode, otherwise you'll get Mozilla-const semantics. Prepend a "use strict"; to the example and re-run it - *boom* you're now in the beautiful world of ES6 const. :)
Also, while not an error, my humble opinion is that we're missing out big time by teaching that "the major use case for const is to safeguard important constants". While that may have been true in a Mozilla-JS const world, in ES6 const means that the variable binding won't change - a
@olov
olov / gist:6443290
Created September 4, 2013 21:45
es6 loop variable bindings
// will this example
let arr = [];
for (let x = 0; x < 5; x++) {
x++;
arr.push(function() { return x; });
}
// ..be semantically equivalent to this?
let arr = [];
@olov
olov / alternate.js
Last active December 22, 2015 08:18
funny little ES6 for (let;;) example
// according to my guesses of what is to come in future ES6 specs:
// the loop should execute five times so the program should print five numbers at the end
// the fresh-per-iteration x is captured in a closure (that will increment it by 3),
// then executed (for side-effects only) in the cond-expr and post-expr.
// it will never ever modify the outer x thus five loop iterations
(function() {
let arr = [];
let fn = null;
let cnt = 0;
for (let x = 0; (fn && fn()), x < 5; (fn && fn()), x++) {