Skip to content

Instantly share code, notes, and snippets.

View cassidoo's full-sized avatar
⌨️
sleepy

Cassidy Williams cassidoo

⌨️
sleepy
View GitHub Profile
@cassidoo
cassidoo / keybase.md
Created August 16, 2018 18:33
keybase proof

Keybase proof

I hereby claim:

  • I am cassidoo on github.
  • I am cassidoo (https://keybase.io/cassidoo) on keybase.
  • I have a public key ASCfRIH3z01WTOl7Efc5SFuF7eGVKuu-OUbdsHiw16kOsAo

To claim this, I am signing this object:

@cassidoo
cassidoo / customWhitespaceMatcher.js
Last active February 21, 2023 20:12
A custom matcher for when you want to compare strings in Jest and ignore whitespace
// Modified version of this Stack Overflow response:
// https://stackoverflow.com/a/48459005/1950503
// (Removes ramda dependency, adds .trim() to string replacer, adds it to Jest global var instead of exporting)
// To use:
// Put `<rootDir>/path/to/customWhitespaceMatcher.js` in your Jest config under setupFiles
// Call it in your tests like this:
// expect(
// customMatchers.whitespaceMatcher(receivedResult, expectedResult).pass
// ).toBeTruthy();
import time
print "..."
time.sleep(1)
print "..."
print "..."
print "..."
print "..."
time.sleep(1)
print "..."
@cassidoo
cassidoo / cities.js
Created April 9, 2020 00:20
Name a city. It's in there.
const cities = [
{
city: "Abbeville",
state: "Louisiana",
},
{
city: "Aberdeen",
state: "Maryland",
},
{
@cassidoo
cassidoo / useMedia.jsx
Last active October 27, 2022 16:13
An example of checking on a media query with React Hooks
function useMedia(query) {
const [matches, setMatches] = useState(window.matchMedia(query).matches)
useEffect(() => {
const media = window.matchMedia(query)
if (media.matches !== matches) {
setMatches(media.matches)
}
const listener = () => {
setMatches(media.matches)
@cassidoo
cassidoo / ref.jsx
Last active April 23, 2020 23:43
forwardRef example
export const SomeButton = forwardRef(
(
{ children, onSelect, ...props },
forwardedRef
) => {
return (
<button
{...props}
onClick={onSelect}
ref={forwardedRef}
@cassidoo
cassidoo / useLocal.js
Created April 23, 2020 23:42
An example of a local storage hook
import { useEffect } from "react";
import { useAppReducer } from "../AppContext";
export default function useLocal() {
const dispatch = useAppReducer();
useEffect(() => {
dispatch({
type: "GET_FROM_LOCAL_STATE",
somePieceOfState: localStorage.getItem("some_state") || "defaultvalue",
@cassidoo
cassidoo / wizeline.js
Created May 22, 2020 00:28
Wizeline webinar on hooks
import React, { useState, useEffect, useReducer, useMemo } from 'react'
import ReactDOM from 'react-dom'
// let text = 'hellllooooo'
// I AM REACT
// let domTable = {}
// let element = Counter // state = 0
// commit(element, domTable)
export default function usePromise(api) {
const [state, dispatch] = useReducer(
(state, action) => {
switch (action.type) {
case 'LOADING':
return { ...state, loading: true }
case 'RESOLVED':
return { ...state, loading: false, response: action.response, error: null }
case 'ERROR':
return { ...state, loading: false, response: null, error: action.error }