Skip to content

Instantly share code, notes, and snippets.

View Cauen's full-sized avatar
🎯
Focusing

Cauê Nolasco Cauen

🎯
Focusing
View GitHub Profile
@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(
// 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))
// Name: Port kill
// Description: Enter port number to kill process listening on port.
// Author: kyo young
// GitHub:
import '@johnlindquist/kit';
const killPort = await npm('kill-port');
const port = await arg('Enter port to kill')
const containerClassName = 'flex justify-center items-center text-4xl h-full'
/*
## Open [https://scriptkit.com](https://scriptkit.com) in your browser
*/
// Name: ScriptKit.com
// Description: Launch scriptkit.com in your browser
// Author: John Lindquist
// Twitter: @johnlindquist
// Note: Feel free to delete this script!
@Cauen
Cauen / how-to-expose-zustand-immer-to-update-any-field-inside-components.md
Created July 14, 2022 02:25
Expose Zustand Immer to Update Any Part of Store inside Components

Why?

In examples, we dont know how to use immer outside of the store implementation. Here's how to.

// store.ts
import { immer } from 'zustand/middleware/immer'
import { CreateOneShopOrderFromCheckoutInput } from '@/graphql/generated'
import { WritableDraft } from 'immer/dist/internal'
@Cauen
Cauen / parse-google-sheet-or-spreadsheet-data-copied-to-clipboard-to-json-object-array-of-objects.ts
Last active March 29, 2023 10:21
Parse Google Sheet or Spreadsheet Data Copied to Clipboard to JSON Object (Array of Objects)
const fake = 'Name\tAge\t\t\nEmanuel\t18\t\t\nCauê\t13\t\t\n\t\t\t\n\t\t\t'
const data = prompt("Digite o conteúdo") || fake
const splitInRows = (data: string): string[] => data.split("\n")
const isEmptyRow = (data: string): boolean => data.replaceAll('\t', '').length === 0
const splitRowInColumns = (row: string): string[] => row.split("\t")
const splitRowsInColumns = (rows: string[]) => rows.map(row => splitRowInColumns(row))
const getFilledColumnsIndexes = (headerRow: string[]): number[] => headerRow.reduce((prev, curr, currentIndex) => (curr.trim()) ? [...prev, currentIndex] : prev, [] as number[])
const keepOnlySpecificIndexesInArray = (row: string[], indexes: number[]): string[] => indexes.map(index => row[index])
const cleanifyRows = (rows: string[][], indexesToKeep: number[]) => rows.map(row => keepOnlySpecificIndexesInArray(row, indexesToKeep))
@Cauen
Cauen / adminbro-translation-ptbr.js
Last active June 29, 2021 18:46
Adminbro portuguese configuration file (translated all strings to brazilian portuguese)
// Unfortunately the singular and plural are having problems in my version of admin bro, and therefore should be updated if yours is already working
export const translations = {
actions: {
new: 'Criar novo',
edit: 'Editar',
show: 'Mostrar',
delete: 'Deletar',
bulkDelete: 'Deletar tudo',
list: 'Listagem',
@Cauen
Cauen / gist:eab04bf191d0980f18f87cf865c71741
Created May 29, 2020 20:42
Docker Swarm + Portainer + Traefik (Global Redirection & Subdomain & Auth to view Dashboard) + 2 backends
version: '3'
services:
traefik:
image: traefik:v2.0.0
command:
- --api.insecure=false # set to 'false' on production
- --api.dashboard=true # see https://docs.traefik.io/v2.0/operations/dashboard/#secure-mode for how to secure the dashboard
- --api.debug=true # enable additional endpoints for debugging and profiling
- --log.level=DEBUG # debug while we get it working, for more levels/info see https://docs.traefik.io/observability/logs/