Skip to content

Instantly share code, notes, and snippets.

View prof3ssorSt3v3's full-sized avatar
🎯
Focusing

Steve Griffith prof3ssorSt3v3

🎯
Focusing
View GitHub Profile
@prof3ssorSt3v3
prof3ssorSt3v3 / app.js
Last active February 25, 2023 16:52
Code Sample for Saving an array of files in the cache and Retrieving an array of files from the cache
const names = ['sheldon', 'amy', 'penny', 'leonard', 'raj', 'buffy', 'howard', 'bernadette'];
const DEMO = {
cacheref: null,
cachename: 'gelatenous-cube',
cacheReady: false, //change to true after files are saved in the cache
init() {
//build a bunch of files and save them in the cache
//then read all the files from the cache
DEMO.addListeners();
@prof3ssorSt3v3
prof3ssorSt3v3 / index.html
Created February 23, 2023 23:17
inline vs inline-block
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
p {
padding: 1rem;
@prof3ssorSt3v3
prof3ssorSt3v3 / main.js
Created February 18, 2023 20:39
Code from video about Structured Clone method
// structuredClone( ) method
const log = console.log;
//objects with primitives
let obj1 = { prop1: 'abc', prop2: 123 };
//objects containing objects
let names = ['fred', 'velma', 'daphne', 'shaggy'];
let obj2 = { prop3: 'def', prop4: names };
//objects with non-serializable props
@prof3ssorSt3v3
prof3ssorSt3v3 / app.js
Created February 17, 2023 22:28
Code from video about the Random Data API
document.addEventListener('DOMContentLoaded', () => {
document.body.addEventListener('click', getData);
});
function getData(ev) {
//get some data from the random-data-api
const type = 'users'; // beers users credit_cards addresses
const url = new URL(`https://random-data-api.com/api/v2/${type}`);
let params = new URLSearchParams();
//size - number of records to return (default is 1)
@prof3ssorSt3v3
prof3ssorSt3v3 / index.html
Created February 17, 2023 19:06
Code from video about RoboHash Image Generation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RoboHash API</title>
<style>
html {
font-size: 20px;
@prof3ssorSt3v3
prof3ssorSt3v3 / main.js
Created February 16, 2023 17:13
Code from video about Weak References, WeakSet, and WeakMap
const log = console.log;
//Strong Ref and Reachability - the default state
let person = { id: 123, name: 'Shaggy' };
let list = [person];
person = null; //destroys one reference
//person list[0]
// log(list);
// log(person);
//Set - unique list of values, any datatype, strong ref
@prof3ssorSt3v3
prof3ssorSt3v3 / app.js
Created February 14, 2023 19:56
Start Building a SPA Navigation system
const APP = {
currentPage: 'home',
init() {
//page has loaded
},
addListeners() {
//add DOM listeners
},
navigate(page) {
//navigate to a new page
@prof3ssorSt3v3
prof3ssorSt3v3 / 404.html
Last active February 26, 2024 02:09
Code from Service Worker Review
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>404</title>
<link rel="stylesheet" href="main.css" />
<style>
html {
@prof3ssorSt3v3
prof3ssorSt3v3 / cache-review.md
Last active February 18, 2023 03:11
Cache reference markdown page

Cache API

How Do I???

So, for all these examples the assumed set up is a main.js file that imports a cache.js file. All the methods dealing with the cache(s) will be inside the cache.js file and will return a Promise. Here is an example of a function inside the main.js file that calls a function in cache.js and receives a Promise in return. The code in main.js uses a then() to wait for the completion of the code in cache.js.

//main.js
@prof3ssorSt3v3
prof3ssorSt3v3 / sw.js
Created February 9, 2023 22:53
service worker thur feb 9
const version = 6;
const cacheName = `HanShotFirst${version}`;
const cacheList = [
'./',
'./index.html',
'./css/main.css',
'./js/app.js',
'./manifest.json',
'./img/android-chrome-192x192.png',