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 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.html
Created October 9, 2020 19:38
Experiments with HTML Elements
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Experiments with HTML Elements</title>
</head>
<body>
<h1>Main Title of Document</h1>
<h2>Embed</h2>
@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 / 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 / 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 / restaurantDB.js
Created January 13, 2021 15:18
WEB422 - A1 model
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const restaurantSchema = new Schema({
address: {
building: String,
coord: [Number],
street: String,
zipcode: String
},
@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 / elastic.js
Created February 2, 2022 20:14
Elastic mock brainstorm
const { Elastic } = require(...)
const { mock } = Elastic();
beforeEach(() => mock.clearAll())
test('..', async () => {
mock.add('.....');
await request.get('/serach?...')
@humphd
humphd / chimes.ino
Created February 12, 2022 20:13
Chimes Arduino Sketch
#include <Adafruit_NeoPixel.h>
#include <HTTPClient.h>
#include <WiFi.h>
// Define a pixel strip of 1 pixel
Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
// Wifi
char ssid[] = "...";
char password[] = "...";
@humphd
humphd / sum.js
Created July 23, 2023 14:56
ChatCraft sum function
/**
* Example Function Module. Each function needs you to define 4 things:
*/
/* 1. Name of your function */
export const name = "sum";
/* 2. Description of function, used to describe what it does to an LLM */
export const description = "Adds all numbers passed to it, returning the total.";