Skip to content

Instantly share code, notes, and snippets.

@pontusab
pontusab / proximity-prefetch.tsx
Created April 6, 2025 06:43
Next.js Proximity Prefetch (PPF)
"use client";
import { useRouter } from "next/navigation";
import type { ReactNode } from "react";
import { useCallback, useEffect, useState } from "react";
interface ProximityPrefetchProps {
children: ReactNode;
threshold?: number;
predictionInterval?: number;
@cpfiffer
cpfiffer / r1-structured.py
Last active March 7, 2025 19:07
Using Outlines to get structured output from R1
import time
from typing import Literal
import outlines
import re
import torch
from transformers import AutoTokenizer
from outlines.fsm.json_schema import convert_json_schema_to_str
from outlines_core.fsm.json_schema import build_regex_from_schema
from pydantic import BaseModel
@andyjessop
andyjessop / prompt.txt
Created April 20, 2024 07:43
A prompt to categorise and analyse sentiment for GitHub issues
Please analyze the following GitHub issue data, which is provided as a JSON object:
{
"title": "🐛 BUG: WebSocket typing doesn't work in apps that also pull in DOM types",
"body": "Which Cloudflare product(s) does this pertain to?",
}
Provide a response with the following structure:
<json>
@KristofferEriksson
KristofferEriksson / useLocation.ts
Created February 11, 2024 16:44
A React Typescript hook that provides real-time geolocation data, complete with heading and speed metrics
import { useEffect, useState } from "react";
interface LocationOptions {
enableHighAccuracy?: boolean;
timeout?: number;
maximumAge?: number;
}
interface LocationState {
coords: {
@natew
natew / AnimatedNumbers.tsx
Last active March 8, 2024 00:27
AnimatePresence number ticker
const AnimatedNumbers = () => {
const [numbers, setNumbers] = useState(100_000)
const len = `${numbers}`.length
return (
<YStack gap="$5">
<XStack gap="$2">
<Button
onPress={() => {
import React from 'react';
import {View, SafeAreaView, ScrollView} from 'react-native';
import {MotiView} from 'moti';
const MotiPlaceholders = () => {
const gray = '#505050';
const lightGray = '#a0a0a0';
const animationDuration = 700;
return (
@pzatorski
pzatorski / react-native-setup-ios.sh
Created May 7, 2022 20:03
Clean a React Native project (iOS)
#!/bin/bash
# exit when any command fails
set -e
COMMAND=$1
function clean() {
printf "🧹 Cleaning.. \n"
rm -rf ~/Library/Caches/CocoaPods Pods ~/Library/Developer/Xcode/DerivedData
@SimeonGriggs
SimeonGriggs / wordle.js
Last active February 11, 2022 09:54
Sanity Schema for Wordle
import React from 'react'
import {withDocument} from 'part:@sanity/form-builder'
import {Stack, Card, Flex, Text} from '@sanity/ui'
import {format} from 'date-fns'
const WORD_LENGTH = 5
function Guess({char, answer, index}) {
const answerSplit = answer.split('')
let tone = `default`
@kelset
kelset / 2018-2022 RN retrospective.md
Last active July 26, 2022 05:11
A personal retrospective of being a maintainer for React Native for the past 4 years.

4 years as a React Native OSS maintainer: a retrospective

Why writing this, and why now? In January 2018 I started my journey as a maintainer of the React Native (RN) open source repo — it is the longest role I’ve ever kept going in my professional career, in a way — and I think now, at the 4 years mark, it is a very good time for me to pause, and force myself to think about how things have changed since then.

How did I become a maintainer? After a big burnout with react-navigation that led me to learn how to correctly interact with Open Source Software (OSS), I was starting to interact with OSS again by being a good citizen in the RN repository. Seeing me constantly in the issue section, trying to help out, led some Facebook (FB) engineers to decide to ask me to join the OSS repo with write access, so that I could be more proactive in helping its maintenance… and here we are.

Even so, I was never an em