Skip to content

Instantly share code, notes, and snippets.

@tomjamesallen
tomjamesallen / country-flags.json
Created July 11, 2024 10:47
Country flags map
{"ac":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1e8.svg","ad":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1f4.svg","ae":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1ea.svg","af":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1eb.svg","ag":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1ec.svg","ai":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1ee.svg","al":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1f1.svg","am":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1f2.svg","aq":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1f6.svg","ar":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1f7.svg","as":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1f8.svg","at":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1f9.svg","au":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1fa.svg","aw":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1fc.svg","ax":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1fd.svg","az":"https://twemoji.maxcdn.com/2/svg/1f1e6-1f1ff.svg","ba":"https://twemoji.maxcdn.com/2/svg/1f1e7-1f1e6.svg","bb":"https://twemoji.maxcdn.com/2/svg/1f1e7-1f1e7.svg","bd":"https://t
@tomjamesallen
tomjamesallen / client.ts
Created February 7, 2024 10:20
@/libs/config
import * as z from "zod";
import { merge } from "ts-deepmerge";
import { universalConfig, PartialDeep } from "./universal";
const clientConfigSchema = z.object({});
export const clientConfig = clientConfigSchema.parse(
{} satisfies PartialDeep<z.input<typeof clientConfigSchema>>
);
@tomjamesallen
tomjamesallen / getSizes.ts
Last active December 21, 2023 12:27
Get sizes property from breakpoint map and tw screens config
type BaseSize = string;
type BreakpointName = string;
type WidthAtBreakpoint = string;
type BreakpointSize = [BreakpointName, WidthAtBreakpoint];
type TailwindScreens = Record<string, string>;
export type GetSizesBreakpointMap = [BaseSize, ...BreakpointSize[]];
export const getSizes = (
tailwindScreens: TailwindScreens,
@tomjamesallen
tomjamesallen / post.md
Created August 17, 2023 14:23
Type Guards with Zod

Handy helper to make a TS Type Guard from any Zod schema.

TS docs on Type Guards | Zod docs

export const typeGuardFromZodSchema = <TSchema extends z.Schema>(
  schema: TSchema
) => {
  return (value: unknown): value is z.infer<TSchema> => {
    return schema.safeParse(value).success;
if ("parentIFrame" in window) {
window.parentIFrame.sendMessage({submitted: true});
}
/*! iFrame Resizer (iframeSizer.contentWindow.min.js) - v4.3.2 - 2021-10-18
* Desc: Include this file in any page being loaded into an iframe
* to force the iframe to resize to the content size.
* Requires: iframeResizer.min.js on host page.
* Copyright: (c) 2021 David J. Bradshaw - dave@bradshaw.net
* License: MIT
*/
!function(c){if("undefined"!=typeof window){var i=!0,o=10,r="",a=0,u="",s=null,d="",l=!1,f={resize:1,click:1},m=128,h=!0,g=1,n="bodyOffset",p=n,v=!0,y="",w={},b=32,T=null,E=!1,O=!1,S="[iFrameSizer]",M=S.length,I="",N={max:1,min:1,bodyScroll:1,documentElementScroll:1},A="child",C=!0,z=window.parent,k="*",R=0,x=!1,e=null,L=16,F=1,t="scroll",P=t,D=window,j=function(){re("onMessage function not defined")},q=function(){},H=function(){},W={height:function(){return re("Custom height calculation function not defined"),document.documentElement.offsetHeight},width:function(){return re("Custom width calculation function not defined"),document.body.scrollWidth}},B={},J=!1;try{var U=Object.
@tomjamesallen
tomjamesallen / cloudSettings
Last active January 7, 2021 12:38
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-01-07T12:37:55.732Z","extensionVersion":"v3.4.3"}
import * as React from 'react';
import { fileAbsolute } from 'paths.macro';
import styled from 'styled-components/macro';
import {
makeAndDefineMessages,
generateFormFieldMessages,
localiseApolloError,
preProcessI18nPrefix,
} from 'bww-kit/src/helpers';
@tomjamesallen
tomjamesallen / getPlainTextFromRaw.ts
Created May 31, 2019 11:47
Convert RawDraftContentState to plain text
import { convertFromRaw, RawDraftContentState } from 'draft-js';
const getPlainTextFromRaw = (raw: RawDraftContentState | null): string => {
if (raw === null) {
return '';
}
return convertFromRaw(raw).getPlainText();
};
@tomjamesallen
tomjamesallen / CustomButton.tsx
Last active May 22, 2019 18:00
Customising deeper elements in MUI components with styled components
// https://material-ui.com/guides/interoperability/#deeper-elements
// https://www.styled-components.com/docs/api#using-custom-props
import * as React from 'react';
import styled, { css } from 'styled-components/macro';
import Button, { ButtonProps } from '@material-ui/core/Button';
export const CustomButton = styled<React.FC<ButtonProps>>(props => (
<Button {...props} classes={{ label: 'label' }} />