Skip to content

Instantly share code, notes, and snippets.

View humphd's full-sized avatar
💭
Helping others get started

David Humphrey humphd

💭
Helping others get started
View GitHub Profile
@humphd
humphd / index.js
Created October 2, 2020 21:18
WEB222 Week 04
/**
* Week 3 - A Larger Example (String, Array, RegExp):
*
* Write a series of functions to accomplish the following, building a larger program as you go:
*
* 1. Split the string into an `Array` of separate rows (i.e., an `Array` with rows separated by `\n`).
* Bonus: how could we deal with data that includes both Unix (`\n`) and Windows (`\r\n`) line endings?
*
* 2. Each row contains information user info: `ID`, `Name`, `Phone Number`, and `Height` info all separated by commas.
* Split each row into an `Array` with all of its different fields. You need to deal with extra and/or no
@humphd
humphd / App.jsx
Created January 28, 2021 16:23
WEB422 Week 4 - React Events
import { useState } from 'react';
import ClickCounter from './ClickCounter';
import ClickHeading from './ClickHeading';
function App() {
// State: held by the parent
const [numClicks, setNumClicks] = useState(0);
const onClickHandler = (e) => setNumClicks(numClicks + 1);
@humphd
humphd / index.js
Created November 19, 2020 01:42
Testing code that uses node-fetch using Jest
// Simple module that uses fetch to do a HEAD request
const fetch = require('node-fetch');
module.exports.fn = async (url) => {
try {
const response = await fetch(url, { method: "HEAD" });
return response.ok;
} catch(err) {
return false;
}
@humphd
humphd / App.jsx
Created November 19, 2020 01:29
Custom hook for Page Lifecycle API
// Use it like this
import usePageLifecycle from './lib/use-page-lifecycle';
App() {
const isVisible = usePageLifecycle();
}
@humphd
humphd / globeandmail.html
Created October 16, 2020 20:43
WEB222 Week 6 Examples
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Globe And Mail</title>
</head>
<body>
<header>
Menu | Logo | TRAVEL | <button>SUBSCRIBE</button> | LOG IN | Search
@humphd
humphd / index.js
Created October 6, 2020 23:08
Promise example
function makeCalls() {
return Promise.all(
linkArr.map(async link => {
try {
const response = await fetch(link, { method: "HEAD" });
if (response.status == 200) { // good
console.log(`${link} was good! status: ${response.status}`.green);
} else if (response.status == 404 || response.status == 401) { // bad
console.log(`${link} was bad! status: ${response.status}`.red);
allGood = false;
@humphd
humphd / index.js
Last active September 30, 2020 04:07
How do I download multiple things at once?
// Imagine we have a bunch of URLs we need to check (download and check their status code)
const urls = [
// Most of these are known to be good...
'https://damontui.blogspot.com/feeds/posts/default?alt=rss',
'https://dev.to/feed/henryzerocool/',
'https://danielsirkovich.blogspot.com/feeds/posts/default?alt=rss',
'https://abdulosd.blogspot.com/feeds/posts/default?alt=rss',
'http://palak-chawla.blogspot.com/feeds/posts/default?alt=rss',
'http://zjjiang2.blogspot.com/feeds/posts/default/-/categorylabel?alt=rss',
'https://dev.to/feed/phast184',
@humphd
humphd / practice.js
Created September 23, 2020 17:57
WEB222 Week 03
/**
* Week 3 - A Larger Example (String, Array, RegExp):
*
* Write a series of functions to accomplish the following, building a larger program as you go:
*
* 1. Split the string into an `Array` of separate rows (i.e., an `Array` with rows separated by `\n`).
* Bonus: how could we deal with data that includes both Unix (`\n`) and Windows (`\r\n`) line endings?
*
* 2. Each row contains information user info: `ID`, `Name`, `Phone Number`, and `Height` info all separated by commas.
* Split each row into an `Array` with all of its different fields. You need to deal with extra and/or no
@humphd
humphd / regexp.txt
Created September 23, 2020 15:50
WEB222 Week 3 RegExp
name@server.com
web222@gmail.ca
(\w+)@([\w.]+)
491 5050
(416) 491 5050
(416) 491-5050
416-491-5050
416 491 5050
@humphd
humphd / arrays.js
Created September 22, 2020 19:52
WEB222 Week 3 - Arrays
let words = ['one', 'two', 'three', 'four', 'five'];
// version 1 - for loop
for(let i = 0; i < words.length; i++) {
let word = words[i];
console.log(word);
}
// version 2 - for-of loop
for(let word of words) {