Skip to content

Instantly share code, notes, and snippets.

@marcandrewb
marcandrewb / lazy.tsx
Created March 21, 2024 19:14
Lazy Load
import { ComponentProps, ComponentType, lazy, Suspense, useMemo } from "react";
type Props<C extends ComponentType<any>> = {
loader: () => Promise<{
default: C;
}>;
} & ComponentProps<C>;
function LazyLoad<C extends ComponentType<any>>({
loader,
@marcandrewb
marcandrewb / GlobalStateProvider.tsx
Created January 19, 2023 20:40 — forked from evgeniyPP/GlobalStateProvider.tsx
XState global state machine hook
import { createContext } from 'react';
import { InterpreterFrom } from 'xstate';
import { useInterpret } from '@xstate/react';
import { someMachine } from './someMachine';
export const GlobalStateContext = createContext({ someService: {} as InterpreterFrom<typeof someMachine> });
export const GlobalStateProvider = (props: React.PropsWithChildren) => {
const someService = useInterpret(someMachine);

Awesome Personalization

A curated list of hand-picked resources about personalization inspired by the awesome-* trend on GitHub.

The goal is to build a categorized, community-driven collection of excellent resources on the topic. I've been on a steep learning curve on personalization since I founded Croct, so I tried to catalog my resources to help others.

Want to contribute to growing or improving this? Sharing, suggestions, and contributions are always welcome! Please take a look at the contribution guidelines first.

Basics (Start Here)

export function isElementInView(container: HTMLElement, element: HTMLElement, partial: boolean) {
if (!container || !element) {
return false;
}
const containerBounds = container.getBoundingClientRect();
const elementBounds = element.getBoundingClientRect();
const containerBoundsLeft = Math.floor(containerBounds.left);
const containerBoundsRight = Math.floor(containerBounds.right);
const elementBoundsLeft = Math.floor(elementBounds.left);
const elementBoundsRight = Math.floor(elementBounds.right);
@marcandrewb
marcandrewb / tab-hidden.js
Created April 2, 2019 14:08
fire an event when a user makes another tab or window active
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
// the page has been hidden
} else {
// the page has become visible
}
});
@marcandrewb
marcandrewb / cron.md
Last active March 3, 2024 17:51
cron syntax

cron syntax

* * * * *  command to be executed
- - - - -
| | | | |
| | | | +----- Day of the week (0 - 7) (Sunday is 0 or 7)
| | | +------- Month (1 - 12)
| | +--------- Day of the month (1 - 31)
| +----------- Hour (0 - 23)
+-------+-----------+----------------------------------------+
| stage | name | mission |
+-------+-----------+----------------------------------------+
| 0 | strawman | Present a new feature (proposal) |
| | | to TC39 committee. Generally presented |
| | | by TC39 member or TC39 contributor. |
+-------+-----------+----------------------------------------+
| 1 | proposal | Define use cases for the proposal, |
| | | dependencies, challenges, demos, |
| | | polyfills etc. A champion |
// `ontouchstart` check works on most browsers
// `maxTouchPoints` works on IE10/11 and Surface
export function isTouchDevice() {
if (!window) return false;
return 'ontouchstart' in window || navigator.maxTouchPoints;
}
@marcandrewb
marcandrewb / visual-code-cheatsheet.md
Last active December 30, 2019 15:03
Visual Code Cheatsheet

⌘ - Cmd
⌥ - Option
⇧ - Shift

Key Description
F12 Peek at definition
Move line down
Move line up
⌘ Enter when opening a file via quick open (⌘ P): Opens file in new split editor