Skip to content

Instantly share code, notes, and snippets.

View nandorojo's full-sized avatar

Fernando Rojo nandorojo

View GitHub Profile
@RobSchilderr
RobSchilderr / .cursorrules
Last active November 27, 2024 16:56
Tamagui Takeout .cursorrules Test
# Takeout Cursor Rules
You are an expert in cross-platform development with React Native, Expo, TypeScript, React, PostgreSQL, Tamagui, Expo Router, tRPC, Solito, Supabase, and more. You possess deep knowledge of best practices and performance optimization techniques across these technologies. Our codebase is a shared Turborepo called "Takeout".
• Prompt Context:
1. If the question explicitly mentions any of the tools or technologies listed above or pertains to the Takeout codebase, ensure your answer incorporates best practices relevant to the mentioned technologies.
2. If the question is about frontend/backend without specific mentions, apply general best practices relevant to the context.
3. If the question involves general TypeScript or other unrelated tasks, stick to general best practices.
4. For follow-up questions unrelated to the technologies or content specified in these rules, the rules do not apply. Focus on answering the question without considering the specified best practices unless explicit
@nandorojo
nandorojo / create-context.tsx
Last active September 21, 2024 19:51
A much better createContext, usable before React 19, with good TypeScript Types
import { createContext as create, useContext } from 'react'
export function createContext<T>(initial?: T) {
const ctx = create<T>(initial ?? (null as any))
return Object.assign(
function Provider(props: React.ComponentProps<typeof ctx.Provider>) {
return <ctx.Provider {...props} />
},
ctx,
@peterpme
peterpme / enforce-platform-shared-types.js
Created August 12, 2024 19:06
React Native Eslint: Enforce Platform Shared Types
const path = require("path");
const fs = require("fs");
module.exports = {
meta: {
type: "problem",
docs: {
description: "Enforce shared types for multi-platform components",
category: "Possible Errors",
recommended: true,
"use client";
import React, { useEffect, useId, useState } from "react";
import { motion, AnimatePresence, MotionConfig } from "framer-motion";
import { PlusIcon, XIcon } from "lucide-react";
import { createPortal } from "react-dom";
import { cn } from "@/lib/utils";
import { buttonVariants } from "../button";
const transition = {
import { useMemo, useState } from 'react';
import { type ViewProps, StyleSheet } from 'react-native';
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
import Animated, {
interpolate,
useAnimatedStyle,
useSharedValue,
withTiming,
Easing,
type SharedValue,
import SwiftUI
struct ChatGPTTextField: View {
// MARK: - State
/// State to hold our `TextField` query.
@State private var queryMessage: String = ""
/// Focus state for our `TextField`.
import ExpoModulesCore
import SwiftUI
public class SwiftuiViewModule: Module {
public func definition() -> ModuleDefinition {
Name("SwiftuiForm")
View(SwiftuiView.self) {
Prop("name") { (view, name: String) in
view.name = name
}
@gragland
gragland / use-optimistic-mutation-example.ts
Last active July 1, 2024 07:39
useOptimisticMutation for React Query. Optimistically update data in multiple locations with rollback on error.
import axios from 'axios'
import { useOptimisticMutation } from "./useOptimisticMutation.ts"
type Response = boolean
type Error = unknown
type MutationVariables = {itemId: string}
type Items = {id: string; name: string}[]
type Likes = {itemId: string}[]
type History = {type: string}[]
import { z } from "zod";
import { zodToTs, printNode } from "zod-to-ts";
// Replace with your `openai` thing
import { openai } from "../openai.server";
import endent from "endent";
function createJSONCompletion<T extends z.ZodType>({
prompt,
schema_name,
export const chaosTestStrings = (): void => {
const textNodes = getAllTextNodes(document.body);
for (const node of textNodes) {
const textNodeLength = node.textContent ? node.textContent.length : 0;
if (node.textContent === null) {
return;
}
if (node.parentElement instanceof Element) {
if (node.parentElement.dataset.originalText === undefined) {