This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { html } from 'lit-element'; | |
import { PageViewElement } from '../components/page-view-element.js'; | |
import markdown from '../markdown/background-tasks.js'; | |
import backgroundTasksStyles from '../styles/background-tasks-styles'; | |
function createFallbackRequestIdleCallback(handler) { | |
const startTime = Date.now(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creation of DOM elements, to be added to the DOM later. | |
logTaskHandler(data) { | |
this.log('<strong>Running task #' + this.currentTaskNumber + '</strong>'); | |
for (let i = 0; i < data.count; i += 1) { | |
this.log((i + 1).toString() + '. ' + data.text); | |
} | |
} | |
log(text) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// requestIdleCallback's callback. | |
runTaskQueue(deadline) { | |
console.info(`This round of JS begins at ${this.currentTaskNumber}.`); | |
while (deadline.timeRemaining() > 0 && this.taskList.length) { | |
// deadline.timeRemaining() runs repeatedly, until it is equal | |
// to 0. It slowly decreases... 12.465 -> 11.26 -> etc. | |
const task = this.taskList.shift(); | |
this.currentTaskNumber++; | |
// This creates the DOM elements but does not log them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adds to task queue. | |
enqueueTask(taskHandler, taskData) { | |
this.taskList.push({ | |
// taskHandler is this.logTaskHandler | |
handler: taskHandler, | |
/* | |
An object as so: | |
{ | |
count: 104, | |
text: "This text is from task number 90 of 100" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
startBackgroundTasks() { | |
console.info('Background Tasks have begun.'); | |
// Subtlety: Data is reset if start is clicked multiple times repeated clicks. | |
this.totalTaskCount = 0; | |
this.currentTaskNumber = 0; | |
this.updateDisplay(); | |
// Create a bunch of tasks. | |
const n = this.getRandomIntInclusive(200, 400); | |
for (let i = 0; i < n; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<picture> | |
<source type="image/webp" srcset="path/to/image.webp" /> | |
<source type="image/jp2" srcset="path/to/image.jp2" /> | |
<source type="image/jxr" srcset="path/to/image.jxr"> | |
<img src="path/to/image.jpg" alt="alt description" /> | |
</picture> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Create the folder to store Next Gen images | |
mkdir ./Images/JP2Files | |
mkdir ./Images/WebPFiles | |
mkdir ./Images/JXRFiles | |
# Go into Image directory for easier understanding | |
cd Images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Create the folder to store Next Gen images | |
mkdir ./Images/JP2Files | |
mkdir ./Images/WebPFiles | |
mkdir ./Images/Placeholders | |
# Go into Image directory for easier understanding | |
cd Images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const findDeep = (data, pathArr, fallback) => { | |
const len = pathArr.length | |
for (let i = 0; i < len; i++) { | |
let path = pathArr[i] | |
if ( | |
Array.isArray(data[path]) || | |
findDeep.isObject(data[path]) || | |
typeof data[path] === 'string' | |
) { | |
if (i === len - 1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def moveTower(n, source, dest, temp): | |
if n == 1: | |
print("Move disk from", source, "to", dest+".") | |
else: | |
moveTower(n-1, source, temp, dest) | |
moveTower(1, source, dest, temp) | |
moveTower(n-1, temp, dest, source) | |
def hanoi(n): | |
moveTower(n, "A", "C", "B") |
NewerOlder