Skip to content

Instantly share code, notes, and snippets.

View LeeCheneler's full-sized avatar

Lee Cheneler LeeCheneler

  • Enzyme Software
  • UK
  • 22:42 (UTC)
View GitHub Profile
@LeeCheneler
LeeCheneler / page.tsx
Last active April 25, 2024 19:00
tailwind palette plugin
interface PaletteExampleProps {
palette: "light" | "dark";
}
const PaletteExample = (props: PaletteExampleProps) => {
return (
<div
className={`palette-${props.palette} bg-palette-paper text-palette-ink p-10`}
>
Palette {props.palette}
@LeeCheneler
LeeCheneler / replace-symlinks.sh
Created September 28, 2023 09:44
replace symlinks
@LeeCheneler
LeeCheneler / sanitize.ts
Last active December 8, 2023 13:43
Sanitize keys in an object
import crypto from "crypto";
export const sanitize = (object: Record<string, unknown>, keysToHash: string[]): Record<string, unknown> => {
if (!object) {
return object;
}
const result: Record<string, unknown> = {};
Object.entries(object).forEach(([key, value]) => {
#!/bin/bash
# get directory of script
CONFIGS_DIR="$(git rev-parse --show-toplevel)/configs"
# get command to execute and the args to forward args
COMMAND="$1"
shift
@LeeCheneler
LeeCheneler / providers.tsx
Created March 4, 2023 17:21
Mantine working with Next 13 app dir
"use client";
import React from "react";
import { CacheProvider } from "@emotion/react";
import createCache from "@emotion/cache";
import { MantineProvider } from "@mantine/core";
import { defaultTheme } from "@opsnoir/mantine-theme";
import { useServerInsertedHTML } from "next/navigation";
import { trpc } from "../utils/trpc";
@LeeCheneler
LeeCheneler / use-outside-click.ts
Created May 26, 2022 18:37
use-outside-click
import React from "react";
export const useOutsideClick = (
refs: React.MutableRefObject<any>[],
callback: () => void
) => {
React.useEffect(() => {
const handleClick = (e: MouseEvent) => {
if (
refs.every(
@LeeCheneler
LeeCheneler / __mocks__use-pagination-trigger.ts
Last active February 4, 2022 11:21
React hook to track whether an element is on the screen
import "jest";
import React from "react";
let externalSetShouldLoadMore = null;
export const usePaginationTrigger = () => {
const [shouldLoadMore, setShouldLoadMore] = React.useState(false);
externalSetShouldLoadMore = setShouldLoadMore;
@LeeCheneler
LeeCheneler / wait-for-server.sh
Last active January 12, 2022 14:05
Wait for server to respond, useful in pipeline to wait for service or app to start
#!/bin/sh
START=$(date '+%s')
TIMEOUT=$(($START + 30))
echo "Waiting for server $1 to start..."
until $(curl --output /dev/null --silent --head --insecure $1); do
NOW=$(date '+%s')
@LeeCheneler
LeeCheneler / gist:404069487014cef3d01b5d8948b14be2
Created October 6, 2021 09:37
Publish testcafe JSON report to confluence page
/* eslint-disable import/no-unresolved */
import axios from 'axios';
import prettyMs from 'pretty-ms';
import report from './report.json';
const assertEnvVar = (name: string) => {
if (!process.env[name]) {
throw new Error(`Environment variable ${name} is not set`);
}
@LeeCheneler
LeeCheneler / find-keys-with-numeric-value.js
Created December 4, 2020 13:45
find key paths in object with numeric value
const findKeysWithNumericValue = (obj, keyPath = "") => {
const keys = Object.keys(obj)
const numericKeys = []
const preKey = keyPath.length > 0 ? `${keyPath}.` : ""
for (let k of keys) {
const value = obj[k]
if (typeof value === "number") {
numericKeys.push(`${preKey}${k}`)
} else if (typeof value === "object") {