Skip to content

Instantly share code, notes, and snippets.

@gusfune
gusfune / pgSqlPrefixedId.sql
Created August 10, 2023 13:22
collision resistance prefixed ID for PostgreSQL
-- This requires nanoid to be installed to work
-- https://github.com/viascom/nanoid-postgres
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE OR REPLACE FUNCTION prefixedid(
prefix text,
size int DEFAULT 24,
alphabet text DEFAULT '0123456789abcdefghijklmnopqrstuvwxyz'
)
@gusfune
gusfune / noQL.ts
Created November 21, 2022 18:22
The world lightest GraphQL Client
interface GraphQLResponse {
data: unknown
}
const noqlFetcher = async <T>(
endpoint: string,
query: string,
variables?: object,
headers: object = {}
): Promise<T> => {
@gusfune
gusfune / gist:19ba6e9da4d5b39a95fc246e38777598
Last active December 20, 2021 12:19
DangerJS check for gitmoji usage
// Check if Gitmoji is being used in Commits
const regex =
/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/gi
danger.git.commits.forEach((commit) => {
const hasGitmoji = regex.test(commit.message)
if (!hasGitmoji) {
warn(`Please use gitmojis in commits.`)
}
})
/**
* useOrientation custom hook
* Usage:
* const { orientation } = useOrientation();
*/
import { useState, useEffect } from "react"
const useOrientation = () => {
const [orientation, setOrientation] = useState<
"portrait" | "landscape" | undefined
@gusfune
gusfune / clean_git.sh
Created July 15, 2020 17:08
Clean up all stable branches locally that have been removed from remote branch
git fetch -p && git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -D
@gusfune
gusfune / useScroll.ts
Last active November 11, 2021 01:04 — forked from joshuacerbito/useScroll.js
Custom React hook for listening to scroll events
import { useState, useEffect } from "react"
type SSRRect = {
bottom: number
height: number
left: number
right: number
top: number
width: number
x: number
@gusfune
gusfune / countries.ts
Created April 25, 2020 16:27
Complete list of countries with ISO Code
export interface Country {
name: string
code: string
}
export const CountryList: Country[] = [
{ name: "Afghanistan", code: "AF" },
{ name: "Albania", code: "AL" },
{ name: "Algeria", code: "DZ" },
{ name: "American Samoa", code: "AS" },