A set of python demos, you can import them using gistimporter
:
# pip install gistimporter
Then, run a Python session and do:
import gistimporter
load([ | |
{"task":"HTML I","done":true}, | |
{"task":"CSS","done":true}, | |
{"task":"Responsive design","done":true}, | |
{"task":"Git","done":true}, | |
{"task":"JavaScript I","done":true}, | |
{"task":"JavaScript II","done":false} | |
]); |
function fPromise(timeout, result, error) { | |
return new Promise(function(fulfill, reject) { | |
setTimeout(function () { | |
if (!error) fulfill(result); | |
else if (error instanceof Error) throw error; | |
else reject(error); | |
}, timeout); | |
}); | |
} |
function retry(target, keepTrying) { | |
var retryCount = 1; | |
var fulfill, reject; | |
var promise = new Promise(function (f, r) { | |
fulfill = f; | |
reject = r; | |
}); | |
realRetry(); |
Function.prototype.retryWhile = function(keepTrying) { | |
var target = this; | |
var retryCount = 1; | |
var fulfill, reject; | |
var promise = new Promise(function (f, r) { | |
fulfill = f; | |
reject = r; | |
}); | |
function PromiseChain() { this._current = null; } | |
PromiseChain.prototype.add = function (task) { | |
if (this._current === null) { | |
this._current = task(); | |
} | |
else { | |
var next = function () { return task(); }; | |
this._current = this._current.then(next, next); | |
} |
A set of python demos, you can import them using gistimporter
:
# pip install gistimporter
Then, run a Python session and do:
import gistimporter
window.onkeypress = function(event) { | |
console.log(event.which || event.keyCode); | |
}; |
alert('Hello!'); |
var canvasX, canvasY; | |
theCanvas.onmousemove = transformIntoCanvasRelative; | |
function transformIntoCanvasRelative(evt) { | |
var canvas = evt.target; | |
var rect = canvas.getBoundingClientRect(); | |
canvasX = evt.clientX - rect.left; | |
canvasY = evt.clientY - rect.top; | |
} |
/* | |
Used to include another JS file. | |
*/ | |
FIB_URL = 'https://gist.githubusercontent.com/lodr/6879872/raw/1dd7315fbac1194abf40406331cf825f74b71ccb/fib.js'; | |
importScripts(FIB_URL); | |
/* | |
This is used to receive data from the parent. | |
*/ | |
onmessage = function(evt) { |