Skip to content

Instantly share code, notes, and snippets.

View n4bb12's full-sized avatar

Abraham Schilling n4bb12

View GitHub Profile
@builder.io/sdk-react
@n4bb12
n4bb12 / pagePropsContext.ts
Created January 28, 2023 08:15
Next.js PageProps Context
import { createContext, useContext } from "react"
import { RootLayoutData } from "src/data/types"
export const pagePropsContext = createContext({})
export const PagePropsProvider = pagePropsContext.Provider
export function usePageProps<T>() {
return useContext<T & RootLayoutData>(pagePropsContext as any)
}
@n4bb12
n4bb12 / docusaurus-infima.css
Created January 20, 2023 04:03
Infima CSS Variables
:root {
--ifm-color-scheme: light;
/* Colors. */
--ifm-dark-value: 10%;
--ifm-darker-value: 15%;
--ifm-darkest-value: 30%;
--ifm-light-value: 15%;
--ifm-lighter-value: 30%;
--ifm-lightest-value: 50%;
@n4bb12
n4bb12 / awesome-tech.md
Last active February 18, 2023 15:10
Awesome Tech
@n4bb12
n4bb12 / serverComponent.ts
Last active May 3, 2023 21:50
Next.js 13 async server component wrapper
import { ReactElement } from "react";
export type RenderResult<P> = ReactElement<P, any> | null;
export function serverComponent<P = {}>(fn: (props: P) => RenderResult<P> | Promise<RenderResult<P>>) {
return fn as unknown as (props: P) => RenderResult<P>;
}
// or
@n4bb12
n4bb12 / download.ts
Last active January 16, 2023 05:12
Download a in-memory content with a specific file type
export function download({
filename,
content,
contentType,
}: {
content: string
contentType: string
filename: string
}) {
const a = document.createElement("a")
@n4bb12
n4bb12 / ResetButton.tsx
Last active January 16, 2023 05:14
Simple React localization pattern
export const ResetButtonExample: FC = () => {
const T = useLocalizedText({ de, en })
return (
<button>{T.reset}</button>
)
}
const de = {
reset: "Zurücksetzen",
@n4bb12
n4bb12 / kind
Last active January 16, 2023 05:15
Notes for using `kind`
# kind
- Install go — https://go.dev/doc/install
- Install kubectl — https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/
- Install kind — https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries
```
kind create cluster --name playground
kind get clusters
kubectl cluster-info --context kind-playground
slugify () {
echo "$@" | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z
}
@n4bb12
n4bb12 / .gitignore
Last active March 22, 2023 12:46
yarn-3.sh
# yarn
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions