Skip to content

Instantly share code, notes, and snippets.

View itsMapleLeaf's full-sized avatar

Darius itsMapleLeaf

View GitHub Profile
@itsMapleLeaf
itsMapleLeaf / rules.txt
Created October 29, 2024 20:41
my personal cursor AI rules
- use friendly, casual language
- don't apologize for messing up, mistakes are natural!
- do not add comments that only explain what the code does, only add comments for complex or unclear logic that explains _why_ it's doing what it is
- do not change any other surrounding code unrelated to what was asked unless necessary. if you do need to change unrelated code, say so and explain why
- make sure your changes take into account the current state of the code, e.g. any changes or file moves/renames that I made in between queries
when writing JS or TS:
- use explicit file extensions in JS/TS import specifiers
- prefer for..of over forEach
- do not use `e` as a shorthand for `event`
@itsMapleLeaf
itsMapleLeaf / README.md
Last active August 26, 2024 04:52
Instant & Convex

Comparison between two modern BaaS services

Convex

Good:

  • Realtime
  • Alongside DB, also supports auth, file uploads, server functions, and background tasks
  • Experience from end to end is very typesafe
  • Backend is open-source
@itsMapleLeaf
itsMapleLeaf / server.js
Created March 27, 2024 17:44
more readable custom remix vite server
import { createRequestHandler } from "@remix-run/express"
import express from "express"
const app = express()
let build
if (process.env.NODE_ENV === "production") {
build = await import("./build/server/index.js")
app.use(express.static("build/client"))
} else {
@itsMapleLeaf
itsMapleLeaf / checks.yml
Created February 28, 2024 17:27
GitHub Node.js Workflow
name: Checks
on:
push:
branches:
- main
pull_request:
jobs:
check:
@itsMapleLeaf
itsMapleLeaf / it.ts
Created December 14, 2023 17:15
extended iterable
import type { Truthy } from "./types.ts"
class ExtendedIterable<T> implements Iterable<T> {
constructor(private iterable: Iterable<T>) {}
*[Symbol.iterator]() {
yield* this.iterable
}
apply<U>(fn: (iterable: ExtendedIterable<T>) => Iterable<U>) {
@itsMapleLeaf
itsMapleLeaf / example.tsx
Last active August 29, 2023 21:31
React useDebouncedCallback
import { useDebouncedCallback } from "./useDebouncedCallback"
export function Example() {
const searchDebounced = useDebouncedCallback((query: string) => {
// do something with query
}, 500)
return (
<input
onChange={(event) => {
@itsMapleLeaf
itsMapleLeaf / example.tsx
Last active November 14, 2024 18:34
React suspense with Convex
import { Suspense } from 'react'
import { api } from 'convex/_generated'
import { useQuerySuspense } from './useQuerySuspense'
function App() {
return (
<Suspense fallback="Loading...">
<TodoList />
</Suspense>
)
async function loop() {
let currentTime = performance.now()
while (true) {
const nextTime = await animationFrame()
const delta = nextTime - currentTime
// progress += delta
currentTime = nextTime
}
}
import { useCallback, useInsertionEffect, useRef } from "react"
export function useEffectEvent<Args extends unknown[], Return>(
callback: (...args: Args) => Return,
) {
const ref = useRef((..._args: Args): Return => {
throw new Error("Cannot call an event handler while rendering.")
})
useInsertionEffect(() => {
@itsMapleLeaf
itsMapleLeaf / why-i-still-like-react.md
Last active January 12, 2023 16:24
why I still like React

with React, I like being able to describe what my UI should be, top to bottom, depending purely on props and state

with Solid, conceptually, you describe what it starts out as and how it changes over time

in Solid, this manifests as needing to wrap computed values in functions, not being able to destructure props, not being able to use early returns, and so on. I know why it's this way, but it's a tradeoff nonetheless

there's some nice stuff there too though, like how JSX elements are just DOM elements, and there's no need for the "useRef useEffect" dance, and I appreciated that when I tried Solid

all that being said, I still prefer the "start over from scratch on each render" approach, as well as the separation of "UI description" and "imperative bullshit" zones that React gives me. Solid's ecosystem is big enough that I could realistically use it for a project, but ultimately, if rendering was a bottleneck for me, I'd either pick something more React-like, or not use JS/DOM at all 🤷