Skip to content

Instantly share code, notes, and snippets.

View jmuzsik's full-sized avatar
⏲️

Jerry jmuzsik

⏲️
View GitHub Profile
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();
// 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) {
// 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.
// 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"
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++) {
@jmuzsik
jmuzsik / picture.html
Last active July 9, 2019 21:00
picture.html
<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>
@jmuzsik
jmuzsik / imagemagick.sh
Last active July 9, 2019 20:59
imagemagick.sh
#!/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
@jmuzsik
jmuzsik / ConvertFiles.sh
Created July 9, 2019 19:01
ConvertFiles.sh
#!/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
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) {
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")