Skip to content

Instantly share code, notes, and snippets.

View arleighdickerson's full-sized avatar
🇺🇲
✡️

Arleigh Dickerson arleighdickerson

🇺🇲
✡️
View GitHub Profile
@arleighdickerson
arleighdickerson / AttributeChangeEmitter.java
Created February 28, 2024 18:28
A WebSocketSessionDecorator to listen for attribute changes
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.WebSocketSessionDecorator;
import java.util.Map;
import java.util.Objects;
@arleighdickerson
arleighdickerson / preact-layout.tsx
Last active August 19, 2024 23:50
Preact Layout -- Patched for V10
// @ts-nocheck
// ¯\_(ツ)_/¯
import { ComponentChildren, ComponentType, Context, h, toChildArray } from 'preact';
function getChildren(node) {
return ((node || {}).props || {}).children;
}
function getComponentType(node) {
return (node || {}).type;
import { Component, ReactNode } from 'react';
interface Props {
loading: ReactNode;
ready: PromiseLike<any>;
beforeMount?: () => any;
afterLift?: () => any;
}
interface State {
import { CSSProperties, PropsWithChildren } from 'react';
import * as colors from 'tailwindcss/colors';
export interface ContentProps {
header?: string;
message?: string;
}
export enum Variant {
SPINNING,
import { validate } from 'validate.js';
import _ from 'lodash';
interface AnyObject {
[key: string]: any;
}
type ValidationErrors = AnyObject | undefined;
export interface ApiError {
export namespace idUtil {
export function create() {
let str = '';
for (let i = 0; i < 16; i += 1) {
const base = 'abcdefghijklmnopqrstuvwxyz234567'; //a-z, 2-7
const array = new Int32Array(1);
window.crypto.getRandomValues(array);
const j = array[0];
str +=
base[(j >>> 27) & 0x1f] +
@arleighdickerson
arleighdickerson / safe-invoke.ts
Created July 9, 2023 16:33
safeInvoke(obj, path[], ...args[])
import _ from 'lodash';
const invoke = new Proxy(_.invoke, {
apply(target, thisArg, argArray: any[]): any {
try {
return Reflect.apply(target, thisArg, argArray);
} catch (e) {
if (process.env.NODE_ENV === 'development') {
console.debug('[safe-invoke] discarding exception', e, ...argArray);
}
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;
@arleighdickerson
arleighdickerson / ActiveField.tsx
Last active July 9, 2023 17:54
a reusable "active field" to display validation errors in react-final-form
import { createRef, PureComponent, RefObject } from 'react';
import { Field, RenderableProps, UseFieldConfig } from 'react-final-form';
import { ExclamationCircleIcon } from '@heroicons/react/24/outline';
import _ from 'lodash';
export interface ActiveFieldProps {
attribute: string;
label?: string;
type?: string;
component?: RenderableProps<any>['component'];
@arleighdickerson
arleighdickerson / preact-reactstrap-patch.js
Created December 12, 2022 19:26
a script to make node_modules/reactstrap compatible with preact
// ============================================================================
// patches node_modules/reactstrap for compatibility with preact
// ============================================================================
const glob = require('glob');
const fs = require('fs');
function resolvePath(moduleId = 'reactstrap') {
try {
const resolved = require.resolve(moduleId);