Skip to content

Instantly share code, notes, and snippets.

View tobie's full-sized avatar

Tobie Langel tobie

View GitHub Profile
@tobie
tobie / function-factory.js
Created May 24, 2013 12:41
Looking for a good name for that sort of pattern, and more specifically how to name the `sortBy` function to best convey what it does.
function sortBy(prop) {
return function(a, b) {
return a[prop].localeCompare(b[prop]);
}
}
[
{ foo: "some text", bar: "other text" },
{ foo: "hello", bar: "world" },
{ foo: "More text", bar: "MOAR" }
{
"DAHUT-TEST5": {
"aliasOf": "DC11"
},
"DC11": {
"authors": [
"Dublin Core metadata initiative"
],
"href": "http://dublincore.org/documents/dcmi-terms/",
"title": "Dublin Core metadata element set, version 1.1",
@tobie
tobie / original.js
Last active December 12, 2015 04:19 — forked from DavidBruant/original.js
function load(fixtures, onComplete) {
async.parallel(fixtures.map(function(fixture) {
return function(cb) {
store(fixture, function(err, result) {
cb(err, result);
});
};
}), onComplete);
}
@tobie
tobie / gist:4668636
Last active December 11, 2015 22:18
Test Framework Requirements
===========================
- Single URL to W3C Framework.
- Ability to use the framework to run the tests locally.
- Ability to define and run test suites for specific profiles.
- Single test run.
- Ability to run testharness.js, ref and manual tests.
- Reporting individual and aggregated results.
- Allow browser vendors to run the tests as part of their CI strategy.
@tobie
tobie / _readme.md
Created October 6, 2012 16:04
Webkit uncatchable security error when attempting to access property of the window object across origins.

On WebKit (can reproduce in both latest Chrome and Safari), a security error is displayed in the console when attempting to access the property of the window object hosted on a different origin:

Unsafe JavaScript attempt to access frame with URL http://localhost:8000/main.html from frame with URL http://localhost:8001/iframe.html. Domains, protocols and ports must match.

It seems this error isn't thrown as it is not catchable (see try...catch block in the example) and doesn't affect the program flow (statements below it still get executed).

As there aren't ways to find out if two windows share the same origin, it's impossible to avoid this warning.

// Query current usage and availability in Temporary storage:
navigator.temporaryStorage.getInfo(
function (info) {
// Continue to initialize local cache using the obtained
// usage and quota (availability) information.
initializeCache(info);
}, function (error) { log("Got error: ", error);
});
@tobie
tobie / gist:3383354
Created August 17, 2012 23:05
Implementing Function.prototype.call in terms of Function.prototype.apply
Function.prototype.call = function(obj) {
return this.apply(obj, Array.protoype.slice.apply(arguments, [1]));
};
+-----------------------------+-------------+--------------------+
| Event | Time (ms) | Frame rate (fps) |
+-----------------------------+-------------+--------------------+
| Timed button click | 100 | 10 |
+-----------------------------+-------------+--------------------+
| Minimal interactive frame | 50 | 20 |
+-----------------------------+-------------+--------------------+
| Smooth interactive frame | 33 | 30 |
+-----------------------------+-------------+--------------------+
| Hardcore gamers are happy | 16 | 60 |
@tobie
tobie / gist:2881982
Created June 6, 2012 13:52
Example manifest files transformed in JSON
// CACHE MANIFEST
// NETWORK:
// comm.cgi
// CACHE:
// style/default.css
// images/sound-icon.png
// images/background.png
{
"network": [
// Why you don't need arguments.callee:
var factorial = function callee(n) {
if (n === 0) {
return 1;
}
return n * callee(n - 1);
};
// In a standard compliant ES3 or ES5 implementation: