const timeIt = (label, fn) => {
console.time(label);
fn();
console.timeEnd(label);
}
Quokka.js is a rapid prototyping playground for JavaScript and TypeScript. It runs your code immediately as you type and displays various execution results in your code editor.
This file contains hidden or 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
// 5 * 4 * 3 * 2 * 1 | |
const factorial = (n) => { | |
//base case | |
if (n === 1) return 1; | |
// logic | |
return n * factorial(n-1); | |
} | |
console.log(factorial(5)) |
This file contains hidden or 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
const dbPromise = idb.open('post-store', 1, function(db) { | |
if (!db.objectStoreNames.contains('posts')) { | |
db.createObjectStore('posts', {keyPath: 'id'}); | |
} | |
}); | |
// service worker implementation | |
... | |
event.respondWith(fetch(event.request) | |
.then(res => { |
This file contains hidden or 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
<img src="/src/images/main-image.jpg" | |
srcset="/src/images/main-image-lg.jpg 1200w", | |
"/src/images/main-image.jpg 900w", | |
"/src/images/main-image-sm.jpg 480w" | |
alt="Explore the city" | |
class="main-image" /> |
This file contains hidden or 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
// show cache version first and fetch new data, then swap out the new data with the cached ones | |
caches.match('/very-important-data.json') | |
.then(response => { | |
return response.json(); | |
}).then(data => { | |
if (!didWeReceiveFreshNetworkData) { | |
doSomethingWithData(data); | |
} | |
}).catch(() => { |
This file contains hidden or 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
function copy(object) { | |
var output, value, key; | |
output = Array.isArray(object) ? [] : {}; | |
for (key in object) { | |
value = object[key]; | |
output[key] = (typeof value === 'object') ? copy(value) : value; | |
} | |
return output; | |
} |
This file contains hidden or 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
# meta tag for apple | |
<link href="https://placehold.it/152" | |
sizes="152x152" | |
rel="apple-touch-icon"> | |
# square dimension for home screen icons for the diff devices | |
size device | |
57 iPhone1, 2 | |
72 ipad1,2 |
This file contains hidden or 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
# Clients | |
Clients are computer programs that connect to servers | |
initiate a connection | |
Any computer can be a client |
This file contains hidden or 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
git ls-files | xargs wc -l |