Skip to content

Instantly share code, notes, and snippets.

import { useCallback, useState, useMemo } from 'react';
/**
* Custom React hook to manage state with clearable functionality.
*
* @template ValueType The type of the state value.
* @template ClearType The type representing the cleared value.
*
* @param {ValueType | ClearType} initialValue - The initial value of the state.
* @param {ClearType} clearValue - The value to which the state will be cleared.
@treyhoover
treyhoover / useStatus.ts
Last active July 26, 2023 19:19
Hook for automatically creating helpers to
import { useState, useMemo } from "react";
// Usage example (booleans)
const userActivity = useStatus([true, false]);
userActivity.status; // true
userActivity.toggle();
userActivity.setTrue();
userActivity.setFalse();
userActivity.reset();
@treyhoover
treyhoover / words.json
Created January 25, 2022 22:47
Wordle words
[
"aahed",
"aalii",
"aargh",
"aarti",
"abaca",
"abaci",
"aback",
"abacs",
"abaft",
const dictionary = require("./words.json");
class Wordle {
static DEFAULT_ALPHABET = Array.from({ length: 26 }, (_, i) => String.fromCharCode(i + 97));
static DEFAULT_DICTIONARY = [];
static DEFAULT_SIZE = 5;
static calcLetterFrequency(words = []) {
return words.reduce((freqs, word) => {
for (const letter of word) {
[{
"title": "Like a Rolling Stone",
"artist": "Bob Dylan",
"album": "Highway 61 Revisited",
"released": "1965-08-30",
}
{
"title": "(I Can't Get No) Satisfaction - Mono Version",
"artist": "The Rolling Stones",
# Hide
defaults write com.apple.finder CreateDesktop false; killall Finder
# Show
defaults write com.apple.finder CreateDesktop true; killall Finder
@treyhoover
treyhoover / dnsmasq OS X.md
Last active March 20, 2018 19:40 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

To setup your computer to work with *.test domains, e.g. project.test, awesome.test and so on, without having to add to your hosts file each time.

Requirements

Install

@treyhoover
treyhoover / error.js
Last active June 12, 2018 18:31
api error responses
{
error: {
message: "One or more fields appear to be incorrect", // this is the main error message to show users (e.g. at the top of the form)
developer_message: "This is a message for developers to help diagnose the problem", // optional
reasons: [
{
param: "email",
message: "Please enter a valid email address",
},
{
export default withPassThroughProps({
whiteList: false, /* blacklist these props */
propNames: [...brands, ...sizes],
})(SomeComponent);
# Ensure current directory is the script directory
WORKDIR=`dirname "$0"`
cd ${WORKDIR}