Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Helping others get started

David Humphrey humphd

💭
Helping others get started
View GitHub Profile
@humphd
humphd / chimes.ino
Created Feb 12, 2022
Chimes Arduino Sketch
View chimes.ino
#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 / elastic.js
Created Feb 2, 2022
Elastic mock brainstorm
View elastic.js
const { Elastic } = require(...)
const { mock } = Elastic();
beforeEach(() => mock.clearAll())
test('..', async () => {
mock.add('.....');
await request.get('/serach?...')
@humphd
humphd / App.jsx
Created Jan 28, 2021
WEB422 Week 4 - React Events
View App.jsx
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 / restaurantDB.js
Created Jan 13, 2021
WEB422 - A1 model
View restaurantDB.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const restaurantSchema = new Schema({
address: {
building: String,
coord: [Number],
street: String,
zipcode: String
},
@humphd
humphd / index.js
Created Nov 19, 2020
Testing code that uses node-fetch using Jest
View index.js
// 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 Nov 19, 2020
Custom hook for Page Lifecycle API
View App.jsx
// Use it like this
import usePageLifecycle from './lib/use-page-lifecycle';
App() {
const isVisible = usePageLifecycle();
}
@humphd
humphd / globeandmail.html
Created Oct 16, 2020
WEB222 Week 6 Examples
View globeandmail.html
<!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.html
Created Oct 9, 2020
Experiments with HTML Elements
View index.html
<!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 / index.js
Created Oct 6, 2020
Promise example
View index.js
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
Created Oct 2, 2020
WEB222 Week 04
View index.js
/**
* 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