Skip to content

Instantly share code, notes, and snippets.

View ChaseH88's full-sized avatar

Chase Harrison ChaseH88

View GitHub Profile
@ChaseH88
ChaseH88 / Camel Case and Remove Whitespace
Created December 2, 2021 22:08
Simple script to camel case and remove whitespace on any string
"Some String Here".trim()
.toLowerCase()
.replace(/([^A-Z0-9]+)(.)/ig,
function(match) {
return arguments[2].toUpperCase();
}
);
@ChaseH88
ChaseH88 / buildJSONFromTable.js
Last active November 11, 2021 02:59
buildJSONFromTable - Builds a JSON object with a given table selector from a confluence page.
$('#content-body table').each(function(i) {
$('<button class="json-table">JSON</button>').insertBefore($(this));
$(this).attr('id', 'json-table-' + i)
});
$(document).on('click', 'button', function() {
if ($(this).is('.json-table')) {
buildJSONFromTable('#' + $(this).next().attr('id'))
}
})
@ChaseH88
ChaseH88 / useDimensions.ts
Created October 11, 2021 11:57
Hook to set the dimension on an element
import {
useState,
useCallback,
useLayoutEffect
} from "react";
interface DimensionObject {
width: number;
height: number;
top: number;
@ChaseH88
ChaseH88 / async-handler.ts
Created September 21, 2021 21:52
TypeScript function to handle try/catch statements for promises
/**
* Handles try/catch for promises
* @param {Promise<any>} prom
* @returns {Promise<[T | null, any]>} Fulfilled or unfulfilled promise
*/
async function asyncHandler<T>(
prom: Promise<T>
): Promise<[T | null, any]> {
try {
return [await prom, null];
@ChaseH88
ChaseH88 / deploy.js
Last active March 2, 2022 11:50
A script to handle deployment of AWS Lambda functions from within your editor. You must have the AWS CLI setup and configured before this script will work.
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const fs = require('fs');
// The func
const functionName = 'LAMBDA FUNCTION NAME';
/**
*
*/
(async () => {
@ChaseH88
ChaseH88 / formatIntToIP.ts
Created September 13, 2021 09:10
Converts a number to an IPv4 string
/**
* Converts a number into an IPv4 address.
* @param int Number to be converted
* @returns {string} - formatted value
* @example let ipAddress = formatIntToIP(167772160)
*/
const formatIntToIP = (int: number): string => (
`${(int>>>24)}.${(int>>16 & 255)}.${(int>>8 & 255)}.${(int & 255)}`
);
import dynamic from 'next/dynamic';
const NoComponent = () => (
<p>No Component Exist</p>
);
/**
* Helper function to dynamically import components
* @param path Path to the component
* @returns React Component
import { useEffect, useState, useCallback, useRef } from 'react';
const defaultOptions = {
cancelOnUnmount: true,
};
/**
* An async hook that accepts a callback function and a delay time (in milliseconds), then delays the
* execution of the given function by the defined time.
*/
@ChaseH88
ChaseH88 / useMemoExample.ts
Last active May 6, 2021 09:32
This is a quick example of how you can use the useMemo hook on a child component. I realize this component is technically incomplete, but you get the idea..
import React, { FC, useMemo } from "react";
interface MyComponentInterface {
text: string
}
export const MyComponent: FC<MyComponentInterface> = ({ text }) => {
const MemoizedComponent = useMemo(() => (
<Component
@ChaseH88
ChaseH88 / memo.ts
Created May 3, 2021 16:23
Memo Function for React
import { memo as m, NamedExoticComponent } from "react";
import { isEqual } from "./lodash";
/**
* React memo utility function. Uses the Lodash 'isEqual' function to compare
* by default. You may also create and pass in your own compare function.
* @param component Your React Component
* @param areEqual Optional: Pass your own compare function.
* @example memo(<Component />, areEqual)
*/