Skip to content

Instantly share code, notes, and snippets.

View thathurtabit's full-sized avatar

Stephen Fairbanks thathurtabit

View GitHub Profile
@thathurtabit
thathurtabit / .eslintignore
Created October 30, 2021 10:21 — forked from nnance/.eslintignore
Create React App with ESLint, TypeScript, Prettier
src/serviceWorker.ts
@thathurtabit
thathurtabit / useFetchWithAbort.tsx
Created June 29, 2021 09:33
React: Fetch Hook (with AbortController to avoid race conditions and memory leaks)
import { useState, useEffect } from "react";
/* H/T:
Avoiding Race Conditions and Memory Leaks in React useEffect
https://javascript.plainenglish.io/avoiding-race-conditions-and-memory-leaks-in-react-useeffect-2034b8a0a3c7
*/
interface IUseFetchWithAbortResponse {
fetchedData: unknown;
isLoading: boolean;
@thathurtabit
thathurtabit / TS-Generics.ts
Created May 1, 2021 17:15
TypeScript Generics Example (by @wesbos)
// This function takes a Generic of FoodType
function makeABunchOf<FoodType>(food: FoodType, howMany: number): FoodType[] {
const foodArray = Array.from({ length: howMany }, () => food);
return foodArray;
}
// Make our Food Types
interface Pizza { name: string; slices: number; }
interface Sandwich { name: string; veggie: boolean; }
// Make some Food
@thathurtabit
thathurtabit / getNumberSuffix.ts
Last active August 5, 2023 10:37
Get Number Suffix (-st, -nd, -rd, -th)
export const getNUmberSuffix = (number: number): string => {
const thExceptions = (number: number) =>
[11, 12, 13].some((exception) => exception === number);
const lastDigit = number % 10;
if (thExceptions(number) || lastDigit === 0 || lastDigit > 3)
return `${number}th`;
if (lastDigit === 1) return `${number}st`;
if (lastDigit === 2) return `${number}nd`;
return `${number}rd`;
@thathurtabit
thathurtabit / truncateText.js
Last active September 25, 2019 12:58
Truncate Text
export const truncateText = (text, characterLimit, addEllipsis = true) => {
if (text.length <= characterLimit) {
return text
} else {
const specialChars = ['.',',','!','?','-','—',' ']
let truncatedText = text.substring(0, characterLimit)
if (addEllipsis) {
const lastTruncatedChar = () => truncatedText.charAt(truncatedText.length - 1)
const hasSpecialLastChar = () => specialChars.includes(lastTruncatedChar())
{
"git.autofetch": true,
"editor.fontFamily": "Fira Code",
"editor.fontSize": 13,
"editor.fontLigatures": true,
"workbench.iconTheme": "vscode-icons",
"files.exclude": {
"**/node_modules": true,
"**/gems": true,
"**/._*": true,
@thathurtabit
thathurtabit / gist:18999c85dc52fd94b798
Created August 13, 2014 16:29
Grunt Bower Bootstrap
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
//Read the package.json (optional)
pkg: grunt.file.readJSON('package.json'),
// Metadata.
meta: {
@thathurtabit
thathurtabit / Gruntfile.js
Last active August 29, 2015 14:02
Bootstrap LESS setup with Bower Structure
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
//Read the package.json (optional)
pkg: grunt.file.readJSON('package.json'),
// Metadata.
meta: {
@thathurtabit
thathurtabit / Gruntfile.js for LESS only
Created February 6, 2014 12:02
Gruntfile.js for LESS only
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
}
},
@thathurtabit
thathurtabit / Gruntfile.js LESS
Last active December 19, 2015 02:29
Gruntfile.js for a small LESS-based project
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
//Read the package.json (optional)
pkg: grunt.file.readJSON('package.json'),
// Metadata.
meta: {