Skip to content

Instantly share code, notes, and snippets.

View RavenHursT's full-sized avatar
💭
Currently Job Searching. Please reach out if you might have something!

Matthew Marcus RavenHursT

💭
Currently Job Searching. Please reach out if you might have something!
View GitHub Profile
@RavenHursT
RavenHursT / maxAnagrams.ts
Created January 22, 2024 15:54
Compare and find anagrams in an array of strings
const wordsAreAnagrams = (a: string, b: string) =>
a.split("").sort().join("") === b.split("").sort().join("")
const findAnagram = (word: string, compareList: string[]) => {
let result = null
compareList.every((w: string) => {
if (wordsAreAnagrams(word, w)) {
result = w
return false
}
@RavenHursT
RavenHursT / arraySample.util.ts
Created November 5, 2022 06:49
arraySample: An TS/JS array util when you want an evenly distributed sample of values from an array
const arraySample = (array: any[], targetSampleLength: number): any[] => {
const currentLength = array.length
if (currentLength <= targetSampleLength) {
return array
}
const lastIndex = array.length - 1
const increment = Math.ceil(currentLength / targetSampleLength)
let newArray = []
@RavenHursT
RavenHursT / array-mutation-utils.ts
Created August 23, 2022 08:23
Array mutation utility methods
export const replaceItemInList = (
item: unknown,
list: unknown[],
index: number
) => [
...list.slice(0, index),
item,
...list.slice(index + 1)
]
@RavenHursT
RavenHursT / react.memo.function-props.md
Created April 29, 2022 05:34
Using React.memo w/ function props from a HOC

I've created a very simple example here..

https://codesandbox.io/s/react-memo-with-function-props-09fgyo

As you can see, ComponentB renders just as many times as ComponentB.. even though it's wrapped in memo and isn't receiving counter as a prop.

If you open up the app in it's own page (https://09fgyo.csb.app/) and then use React DevTools to profile the page, you'll see that it's reporting it's cause for rendering is because the onClick prop changes:

image

@RavenHursT
RavenHursT / proposed_currency_fields_format.json
Created May 1, 2021 20:12
Proposed currency fields format
{
"value": 20.50,
"currency": "USD"
}
@RavenHursT
RavenHursT / proposed_vet_status_property.json
Last active May 3, 2021 17:30
Proposed vet_status techProfile property
{"status": true, "dd214_url": "https://url.to.cloud.storage/item/id"}
@RavenHursT
RavenHursT / proposed_working_hours_property.json
Last active May 1, 2021 20:09
Proposed Working Hours Property
// Each index in the array corrisponds to a day of the week.
// Let the consumer of the API decide what each day should be labelled as, based on their L18N/I18N implementation.
// Z-07:00:00 is EST. Z-offset should be set by the client to reflect the TZ of the user that set the value.
{
"working_hours": [
["09:00:00Z-07:00:00", "17:00:00Z-07:00:00"],
["09:00:00Z-07:00:00", "17:00:00Z-07:00:00"],
["09:00:00Z-07:00:00", "17:00:00Z-07:00:00"],
["09:00:00Z-07:00:00", "17:00:00Z-07:00:00"],
["09:00:00Z-07:00:00", "15:00:00Z-07:00:00"],
function flatten(source, k, keyPath = [], result = {}) {
if(typeof source !== `object` || source === null) {
result[keyPath.join('.')] = source
return result
}
let iterationResult
for (k in source) {
keyPath.push(k)
iterationResult = flatten(source[k], k, keyPath, result)
@RavenHursT
RavenHursT / fpkill.sh
Created July 13, 2018 15:30
OSX Bash function/alias To Find a Process Listening on a Port and Kill It.
fpkill() {
lsof -i tcp:$1 | awk 'NR!=1 {print $2}' | xargs kill -9
}
@RavenHursT
RavenHursT / main-app.client.js
Last active September 30, 2022 03:10
React .renderToStaticNodeStream() example w/ redux and react-router
import ReactDOM from 'react-dom'
import { createStore, applyMiddleware } from 'redux'
import getRootEpic from '../../store/epics/root.epic'
import {createEpicMiddleware} from 'redux-observable'
import reduxLogger from 'redux-logger'
import { Provider } from 'react-redux'
import MainApp from './main-app.component'
import { BrowserRouter } from 'react-router-dom'
import appReducers from '../../store/reducers'
import { CookiesProvider } from 'react-cookie'