Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<body>
<script>
assert(document.readyState === 'loading');
document.addEventListener("DOMContentLoaded", function() {
assert(document.readyState === 'interactive'); // <--
setTimeout(function() {
assert(document.readyState === 'complete');
}, 0);
[
{ "avatarUrl" : null,
"email" : "hi@personal.ro",
"firstName" : "Emery",
"id" : "105288343523146387",
"invitationPending" : false,
"lastName" : "Stafford",
"password" : "yggFjgBNLBN43wkyhKhOu41A67tNV4gw",
"passwordResetToken" : null,
"passwordResetTokenDate" : null
[
{
"document": {
"title": "Neuromancer",
"year": 1984,
"isbn": "0441569595",
"authors": [
"William Gibson"
]
},
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
function createDummyNullable(target) {
return new Proxy(target, {
CancellablePromise.sequence = function(values) {
var children = [];
return new A.CancellablePromise(
function(resolve, reject) {
if (!A.Lang.isArray(values)) {
reject(new TypeError('CancellablePromise.sequence expects an array of values or promises'));
return;
}
@eduardolundgren
eduardolundgren / CancellablePromise.js
Last active August 29, 2015 13:57
CancellablePromise.all
/**
* Cancellable promise.
*
* @class CancellablePromise
* @constructor
* @extends {Promise}
* @param {Function} fn A function where to insert the logic that resolves this
* promise. Receives `fulfill` and `reject` functions as parameters. This
* function is called synchronously.
* @param {Function} opt_errorCallback Optional error callback to be fired
@eduardolundgren
eduardolundgren / cancellable_promise.js
Created March 25, 2014 20:51
Y.CancellablePromise
/**
* Error used as a rejection reason for canceled Promises.
*
* @class Promise.CancellationError
* @constructor
* @extends {Error}
* @param {String} opt_message An optional debugging message for describing the
* cancellation reason.
*/
function CancellationError(opt_message) {
@eduardolundgren
eduardolundgren / Y.App.js
Created March 5, 2014 21:54
Y.App rendering each view in a different element
Y.HeaderView = Y.Base.create('header', Y.View, [], {
ATTRS: {
container: { value: '#header' }
}
});
Y.BodyView = Y.Base.create('body', Y.View, [], {
ATTRS: {
container: { value: '#body' }
}
function writeTempFile(content, opt_callback) {
tmp.file({ postfix: '.html' }, function(err, tmpHtmlPath) {
if (!err) {
grunt.file.write(tmpHtmlPath, content);
}
opt_callback && opt_callback(err, tmpHtmlPath);
});
}
function html2pdf(path, outputPath, opt_callback) {
phantom.create(function(ph) {
ph.createPage(function(page) {
page.set('paperSize', {
format: 'A4',
orientation: 'portrait'
});
page.open(path, function() {