Skip to content

Instantly share code, notes, and snippets.

View pbteja1998's full-sized avatar

Bhanu Teja Pachipulusu pbteja1998

View GitHub Profile
$(function(){
let referral_url = new URL(window.location.href);
if (referral_url.searchParams.has('gclid') && referral_url.searchParams.has('via')) {
setTimeout(function(){
Cookies.remove('rewardful.referral', { path: '/', domain: window.location.hostname })
console.log(Cookies.get('rewardful.referral'))
console.log("Deleted referral cookie as visit came from Google Ads (forbidden by Terms of Service)")
}, 2000)
}
});
@jacobparis
jacobparis / timing.server.ts
Created April 29, 2023 23:24
Server Timing Utilities for Remix
export type PerformanceServerTimings = Record<
string,
Array<PerformanceServerTiming>
>
/**
* Run this on the server to get a `time` function that can be used to time
* server-side operations and add them to the `Server-Timing` header.
*/
export function getServerTiming() {
@perkinsjr
perkinsjr / middleware.ts
Last active January 31, 2024 11:06
Using Clerk with Upstash for Middleware rate limiting and API Protection
import { getAuth, withClerkMiddleware } from "@clerk/nextjs/server";
import { NextResponse, NextFetchEvent } from "next/server";
import type { NextRequest } from "next/server";
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
// Add public paths for Clerk to handle.
const publicPaths = ["/", "/sign-in*", "/sign-up*", "/api/blocked"];
// set your rate limit.
@huw
huw / README.md
Last active March 12, 2024 21:32
Remix, Sentry & Cloudflare Workers

How to integrate Remix, Sentry, and Cloudflare Workers (incl. tracing)

The code above is just a sample—I have adapted it from a production codebase and I can't guarantee it will work as-is. It's just here to illustrate what a solution should look like.

The main things you need to do to get everything hooked up are:

  1. Rewrite instrumentBuild to accept a passed-through Hub instance, rather than using getCurrentHub() (including, perniciously, in helper functions such as hasTracingEnabled())
  2. In server/index.ts, create a root transaction from the current route’s name and wrap the loaders and actions in spans via instrumentBuild.
  3. In root.tsx, pass through your tracing & baggage into the meta function.
  4. In root.tsx, include the current domain in tracePropagationTargets (because Remix fetchers will fetch from the entire URL rather than / root, which will confuse Sentry)
  5. (Remix v2) In root.tsx, create an ErrorBoundary component (with the v2_errorBoundary flag set if you're
import invariant from "tiny-invariant";
class AmalgoBox extends HTMLElement {
get input() {
return this.querySelector("input") as HTMLInputElement;
}
get button() {
return this.querySelector("button") as HTMLButtonElement;
}
@fnky
fnky / login.tsx
Last active December 15, 2023 19:56
Remix Form validation with zod
import { json, ActionFunction, useActionData, Form } from "remix";
import { z } from "zod";
// This type infer errors from a ZodType, as produced by `flatten()` of a parsed schema.
type inferSafeParseErrors<T extends z.ZodType<any, any, any>, U = string> = {
formErrors: U[];
fieldErrors: {
[P in keyof z.infer<T>]?: U[];
};
};
@jacob-ebey
jacob-ebey / image.ts
Last active February 29, 2024 05:25
Remix Image Component
import { createHash } from "crypto";
import fs from "fs";
import fsp from "fs/promises";
import path from "path";
import https from "https";
import { PassThrough } from "stream";
import type { Readable } from "stream";
import type { LoaderFunction } from "remix";
import sharp from "sharp";
import type { Request as NodeRequest } from "@remix-run/node";
@andrelandgraf
andrelandgraf / pre.tsx
Created December 26, 2021 17:35
PrismJS custom component
​import​ ​type​ ​{​ ​FC​,​ ​HTMLAttributes​,​ ​ReactElement​ ​}​ ​from​ ​'react'​;
​import​ ​{​ ​Children​ ​}​ ​from​ ​'react'​;
​import​ ​invariant​ ​from​ ​'tiny-invariant'​;
​import​ ​Highlight​,​ ​{​ ​Language​,​ ​defaultProps​ ​}​ ​from​ ​'prism-react-renderer'​;
​import​ ​CopyClipboardButton​ ​from​ ​'../button/copyClipboardButton'​;
​function​ ​getLanguageFromClassName​(​className​: ​string​)​ ​{
​  ​const​ ​match​ ​=​ ​className​.​match​(​/​language-​(​\w​+​)​/​)​;
​  ​return​ ​match​ ? ​match​[​1​]​ : ​''​;
@Ntropish
Ntropish / index..js
Last active December 24, 2021 00:11
Remix with Socket.io Recipe
// This approach uses:
// - Remix's Express Adapter
// - An external Socket.io server on port 3050
// - http-proxy-middleware
//
// install http-proxy-middleware and apply these lines to `server/index.js`:
//
const { createProxyMiddleware } = require("http-proxy-middleware");
// Add the middleware before remix's catch-all '*' route
@andrelandgraf
andrelandgraf / createSitemap.ts
Last active January 29, 2024 08:36
sitemap.xml generator for remix.run
import childProcess from 'child_process';
import fs from 'fs';
import dotenv from 'dotenv';
import prettier from 'prettier';
const rootDir = process.cwd();
dotenv.config({
path: `${rootDir}/.env.production`,
});