Skip to content

Instantly share code, notes, and snippets.

View Cauen's full-sized avatar
🎯
Focusing

Cauê Nolasco Cauen

🎯
Focusing
View GitHub Profile
// Name: Deep URL decode
// Description: Sometimes you want to know what inside a URL, use this to show as a deep json...
import "@johnlindquist/kit"
const decode = (str: string) => decodeURIComponent((str + '').replace(/\+/g, '%20'))
function getParamsFromUrl(url: string): Record<string, string> | void {
if (url.startsWith("https%")) return getParamsFromUrl(decode(url))
// Name: Deep URL decode
// Description: Sometimes you want to know what inside a URL, use this to show as a deep json...
// Example url: https://google.com/notify/messages/1295812905/click?signature=fake_signature_id&url=https%3A%2F%2Fgoogle.com%2Fusers%2Flink%2FZW1hbnVlbC5-9AF80a98fg8vbQ%3D%3DMTY3NDQzMjg2NA%3D%3D6a8f74a552%3Fredirect_to%3Dhttps%253A%252F%252Fgoogle.com%252Fteam%252F832678%252Fincidents%252F331734795%26utm_source%3Descalation_mailer%26utm_medium%3Demail%26utm_campaign%3Dresolved
import "@johnlindquist/kit"
const decode = (str: string) => decodeURIComponent((str + '').replace(/\+/g, '%20'))
function getParamsFromUrl(url: string): Record<string, string> | void {
// Name: Deep URL decode
// Description: Sometimes you want to know what inside a URL, use this to show as a deep json...
import "@johnlindquist/kit";
const decode = (str: string) => decodeURIComponent((str + '').replace(/\+/g, '%20'))
function getParamsFromUrl(url: string): Record<string, string> | void {
if (url.startsWith("https%")) return getParamsFromUrl(decode(url))
@Cauen
Cauen / code.ts
Last active May 3, 2024 17:39
Prisma Accent Case + Complex Query
// Raw Query
const getUnnacentPersonIdsByNameOrNickname = async (text?: string | null) => {
if (!text) return []
// Search accent case with View
const unnacentLower = (str: string) =>
str
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLocaleLowerCase()
const nameWhere = `unaccent(lower(name)) ilike '%${unnacentLower(
@Cauen
Cauen / findManyApiKey.ts
Last active November 21, 2024 13:46
Pothos Realtime Subscription with Prisma query optimization and context cache
// Idea from https://github.com/hayes/pothos/issues/1349
import { builder } from '@/schema/builder'
import { pubsub } from '@/pubsub'
import { withFilter } from 'graphql-subscriptions'
import { queryFromInfo } from '@pothos/plugin-prisma'
import crypto from 'crypto'
import { Context } from '@/context'
import { prisma } from '@orm/db'