Skip to content

Instantly share code, notes, and snippets.

View hamatoyogi's full-sized avatar

Yoav Ganbar hamatoyogi

View GitHub Profile
@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;
@shilomagen
shilomagen / backend.mdc
Created March 3, 2025 07:45
Cursor Rules Example
---
description: Rules for backend (NestJS application)
globs: apps/**/*.*
---
# Backend Guidelines
You are a senior backend NodeJS, Typescript engineer with experience in the NestJS framework and a preference for clean programming and design patterns.
Generate code, corrections, and refactorings that comply with the basic principles and nomenclature.
## Basic Principles
@t3dotgg
t3dotgg / try-catch.ts
Last active June 9, 2025 21:23
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@trvswgnr
trvswgnr / fetchJson.test.ts
Last active October 8, 2024 10:53
nice lil typescript fetch wrapper with errors as values
import { describe, it, expect, spyOn } from "bun:test";
import { fetchJson } from "./fetchJson";
class MockResponse {
static instanceCount = 0;
constructor(
public readonly ok: boolean,
private jsonSuccess: boolean | "bad parse",
) {
MockResponse.instanceCount++;
import { component$, Slot, useSignal, useVisibleTask$ } from '@builder.io/qwik';
export const ResumeBrowser = component$(() => {
const csr = useSignal(false);
// eslint-disable-next-line qwik/no-use-visible-task
useVisibleTask$(() => {
csr.value = true;
});
return csr.value ? <Slot /> : null;
});
@rauchg
rauchg / p.sh
Last active May 16, 2025 18:09
Perplexity CLI in pure shell
#!/usr/bin/env bash
function p() {
jq -n \
--arg content "$*" \
'{
"model": "pplx-7b-online",
"messages": [
{
"role": "system",
"content": "Be precise and concise."
name: PlanetScale Migration
on:
pull_request:
types: [opened, synchronize]
paths:
- packages/shared/adapters/prisma/schema.prisma
env:
PLANETSCALE_ORG: flightcontrol
PLANETSCALE_DB: fc-production
@jacob-ebey
jacob-ebey / client-navigation.js
Created January 11, 2023 00:53
Navigation and View Transition API example
import { html } from "html-tagged";
export default function ClientNavigation() {
return html`
<script type="module">
if (typeof navigation !== "undefined") {
let lastAbortController;
navigation.addEventListener("navigate", (event) => {
if (!event.canIntercept) return;
// TODO: make `pages` optional and measure the div when unspecified, this will
// allow more normal document flow and make it easier to do both mobile and
// desktop.
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
@jacob-ebey
jacob-ebey / webpack.config.js
Created February 24, 2021 00:18
Consume Federated Modules With Local Fallback | Unpkg, NPM
const path = require("path");
const { camelCase } = require("camel-case");
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const pkg = require("./package.json");