Skip to content

Instantly share code, notes, and snippets.

View bradyclifford's full-sized avatar

Brady Clifford bradyclifford

View GitHub Profile
@bradyclifford
bradyclifford / Event Naming.js
Created July 14, 2023 14:34
FullStory Examples
// Title case the bounded context and event name
FS?.event('Bounded Context/Event Name', { data... })
// 👎 Wrong way to name an event
FS?.event('Click page button to add household member', { data... })
// 👍 Right way to name an event
FS?.event('Shopping/Cart/Button/Add Household Member', { data... })
FS?.event('IFP/Assessment/Selected Silver Plan', { data... })
@bradyclifford
bradyclifford / gist:d1d5bcd49287f5a795e150798f8b5fcf
Created February 24, 2023 15:27
Lookup Typescript String Enum by key
export function getEnumValueLookup<T extends Record<keyof T, string>>(object: T) {
return Object.fromEntries(
Object.entries(object).map(([key, value]) => [value as string, key as keyof T])
);
}
@bradyclifford
bradyclifford / Simple Wrap Layout.jsx
Last active October 7, 2022 02:33
Layout Examples
// https://css-tricks.com/quick-whats-the-difference-between-flexbox-and-grid/
const Tile = styled.aside`
padding: 25px;
border: 2px solid #e4e4e4;
border-radius: 5px;
`;
// Flex
// https://css-tricks.com/snippets/css/a-guide-to-flexbox/#aa-background
const TileContainer = styled.section`
@bradyclifford
bradyclifford / AppInsightsExclude.js
Last active September 2, 2022 19:04
AppInsights: Exclude URL by path base route
// Only capture requests for a specific path based-route
excludeRequestFromAutoTrackingPatterns: [
new RegExp(
`^https?:\\/\\/([^\\/\\s]+\\/)(?!${escapeRegExp(removeSlashes(pathBase))}).+$`,
'i'
)
]
#!/bin/sh
JSON=$(<test.json)
for encodedPair in $(echo "${JSON}" | jq -r 'to_entries[] | @base64'); do
__jq() {
echo "${encodedPair}" | base64 --decode | jq -r ${1}
}
key=$(__jq '.key')
value=$(__jq '.value')
echo "::set-output name=${key}::${value}"
@bradyclifford
bradyclifford / session-refresh.js
Last active March 9, 2022 23:09
Session Keep alive on 3rd Party
// Function runs on an interval as the user is using the 3rd party site
function() {
return function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
console.debug('Refresh token response', xhr);
if (xhr.status >= 200 && xhr.status < 300) return;
@bradyclifford
bradyclifford / generate-import-from-tf-show.js
Last active March 2, 2022 19:27
Terraform Show to Terraform Import
// Run using node
// Output first before running this command terraform show -json > file.json
const tfShowOutput = require(process.argv.slice(2)[0]);
function parseChildModules(modules) {
for (const {address: parentAddress, child_modules : childModules, resources} of modules) {
if (childModules) parseChildModules(childModules);
@bradyclifford
bradyclifford / app-insights.ejs
Last active August 25, 2021 03:21
Application Insights
<% if (htmlWebpackPlugin.options.applicationInsightsInstrumentationKey) { %>
<!-- AppInsights -->
<!-- Intended to be blocking, don't defer or load async -->
<script type="text/javascript">
<%
// https://docs.microsoft.com/en-us/azure/azure-monitor/app/javascript
const {applicationInsightsInstrumentationKey: instrumentationKey, appInsights: props = {}} = htmlWebpackPlugin.options;
const { role, roleInstance, version, onInit, onAfterInit, cfg, ...rest} = props;
const getDomainWithoutSubdomain = hostname => {
const parts = hostname.split('.')
return parts
.slice(0)
.slice(-(parts.length === 4 ? 3 : 2))
.join('.')
}
@bradyclifford
bradyclifford / useSafeState.js
Last active November 5, 2020 15:41
Safe Unmounted React Hooks
import { useState, useRef, useEffect, useCallback } from 'react';
/*
* useSafeState prevents state from being updated if a component has been
* unmounted during an async process, thus preventing React from throwing errors
* around it.
*
* Usage is just like regular useState:
* const [myState, setMyState] = useSafeState("Initial state");
*/