Skip to content

Instantly share code, notes, and snippets.

View YannBirba's full-sized avatar
⚛️
React ♥️

Yann YannBirba

⚛️
React ♥️
View GitHub Profile
@t3dotgg
t3dotgg / try-catch.ts
Last active April 23, 2025 18:06
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;
};
@sergiodxa
sergiodxa / crud.ts
Last active April 21, 2025 04:56
A crud helper for RRv7 routes.ts file
import { index, prefix, route } from "@react-router/dev/routes";
import { camelize, pluralize, singularize } from "inflected";
function createCrud(base = "./views") {
/**
* Create a CRUD route configuration.
* @param name The name of the resource. It will be pluralized for the path.
* @param options The options for the crud.
* @param options.member Extra routes to add to each member.
* @param options.collection Extra routes to add to the collection.
@cjkihl
cjkihl / settings.json
Created December 9, 2024 04:33
TailwindCSS Config for Autocomplete
{
// Config for VsCode Tailwind CSS IntelliSense extension for React
// Type hints for className and class attributes
"tailwindCSS.classAttributes": [
"class",
"className",
],
// Type hints for variables and properties ending with *className
"tailwindCSS.experimental.classRegex": [
@andrasbacsai
andrasbacsai / firewall.sh
Last active April 19, 2025 14:31
Update a Hetzner Firewall rule with your IP address
#!/bin/bash
# Script to update a firewall rule in a Hetzner Firewall with your current IP address.
# Good if you would like to restrict SSH access only for your current IP address (secure).
#################
# WARNING: This script will overwrite all rules in the firewall rules, so make sure you
# added all the required rules.
# I use a separate firewall rule just for SSH access.
#################
# SETUP #
DOMAIN=example.com
PROJECT_REPO="[email protected]:example.com/app.git"
AMOUNT_KEEP_RELEASES=5
RELEASE_NAME=$(date +%s--%Y_%m_%d--%H_%M_%S)
RELEASES_DIRECTORY=~/$DOMAIN/releases
DEPLOYMENT_DIRECTORY=$RELEASES_DIRECTORY/$RELEASE_NAME
# stop script on error signal (-e) and undefined variables (-u)
@eusonlito
eusonlito / 01-README.md
Last active April 2, 2025 16:51
SQLite optimization for Laravel

The SQLite optimizations must be carried out at two different times: once in a unique and permanent way for the database and another time for each connection that is made. Below are the configurations that should be made in each case.

Unique and Permanent Configurations

These configurations are set only once and affect the database persistently, meaning they do not need to be reconfigured each time a connection is established:

PRAGMA journal_mode = WAL;

Sets the database journal mode to "WAL" (Write-Ahead Logging), which improves performance in concurrent operations.

@AlemTuzlak
AlemTuzlak / gist:9ecd385e7e3b57ba80c36914123800e8
Created March 2, 2024 11:12
react-query adapter for remix
import { QueryClient } from "@tanstack/react-query";
import { CacheAdapter, createCacheAdapter } from "remix-client-cache";
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 5,
},
},
});
@srsholmes
srsholmes / grecent.sh
Created November 23, 2023 15:58
Recent git branches
function grecent() {
local branches branch
branches=$(git branch --sort=-committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]') \
&& branch=$(echo "$branches" | fzf --ansi) \
&& branch=$(echo "$branch" | awk '{print $1}' | tr -d '*') \
&& git checkout "$branch"
}
@pingrishabh
pingrishabh / useOptimisticUpdate.js
Created September 24, 2023 08:36
Simple hook to perform optimistic updates with react-query
import { useCallback } from "react";
import { useQueryClient } from "@tanstack/react-query";
export default function useOptimisticUpdate() {
const queryClient = useQueryClient();
return useCallback(
async (queryKey, updater) => {
await queryClient.cancelQueries({ queryKey });
@dilaouid
dilaouid / bbcode.js
Created September 5, 2023 16:14
regex for global XSS protection and bbCode check
const bbCodeMatch = /\[(b|i|u|s)\](.*?)\[\/\1\]/gs;
const XSSMatch = /[<]*<[\s\u200B]*script[\s\u200B]*>.*[/]*[<]*<[\s\u200B]*\/[\s\u200B]*script[\s\u200B]*>/ig;