Skip to content

Instantly share code, notes, and snippets.

View ycmjason's full-sized avatar
😆

YCM Jason ycmjason

😆
View GitHub Profile
@ycmjason
ycmjason / merge_sort.js
Last active April 24, 2019 15:32
Merge sort
const mergeSort = (xs) => {
if (xs.length <= 1) return xs;
const midIndex = Math.trunc(xs.length / 2);
return merge(
mergeSort(xs.slice(0, midIndex)),
mergeSort(xs.slice(midIndex)),
);
}
const merge = (xs, ys) => {
<div ref="container">
<Card v-for="(card, i) of cards" ref="cards">
<IntersectionObserver :getTarget="() => this.$refs.cards[i]" @intersect="liftCard" @disintersect="unliftCard" />
...
</Card>
</div>
<!-- vs -->
<div ref="container">
export const requestAnimationFrameRecursive = (
fn: (
highResTimestamp: DOMHighResTimeStamp,
additionalInfo: {
stop: () => void;
totalTimelapse: DOMHighResTimeStamp;
timelapseSinceLast: DOMHighResTimeStamp;
},
) => void,
o?: {
@ycmjason
ycmjason / BASIC_CONFIG.md
Last active October 1, 2019 10:57
Basic Configs

This file contains some config files.

@ycmjason
ycmjason / removeKeyRecursive.ts
Created November 26, 2020 17:11
removeKeyRecursive.ts
type OmitRecursive<T extends object, O extends string> = Omit<
{ [K in keyof T]: T[K] extends object ? OmitRecursive<T[K], O> : T[K] },
O
>
const removeKeysRecursive = <T extends object, K extends readonly string[]>(
object: T,
keys: K,
): OmitRecursive<T, K[number]> => {
@ycmjason
ycmjason / machine.js
Created January 19, 2023 12:09
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@ycmjason
ycmjason / groupBy.ts
Created March 23, 2023 23:23
A beautiful implementation of groupBy in typescript
export const groupBy = <X, K extends PropertyKey>(
getKey: (x: X) => K,
xs: readonly X[],
): { readonly [k in K]?: readonly (X | undefined)[] } => {
const grouped: { [k in K]?: (X | undefined)[] } = {};
for (const x of xs) {
const key = getKey(x);
grouped[key] ??= [];
// we have initialised ^ so grouped[key] won't be undefined
@ycmjason
ycmjason / AppLink.vue
Last active April 4, 2023 22:22
A totally over-engineered way to make a """type-safe""" `AppLink` with vue-router
@ycmjason
ycmjason / example-usage.ts
Created April 11, 2023 06:36
A fancy way to type your react router config
const routes = [
{
path: '/',
element: <App />,
errorElement: <CircularProgress />,
children: [
{
index: true,
element: <LandingPage />,
},
@ycmjason
ycmjason / README.md
Created April 16, 2023 08:42
Reasons to hate safari as a frontend developer / Why Safari is the new IE

Reasons to hate safari as a frontend developer / Why Safari is the new IE

This is an on-going list of things that I constantly find missing in Safari, (and possibly ways to work around them)

RegExp Positive/Negative Lookbehind

I cannot believe my eyes when positive/negative lookbehind is still not available on safari. Here is how you can work around it:

Instead of