Skip to content

Instantly share code, notes, and snippets.

@alvinsng
alvinsng / no-use-effect.md
Created March 17, 2026 20:00
Skill generated by Factory Droid
name no-use-effect
description Enforce the no-useEffect rule when writing or reviewing React code. ACTIVATE when writing React components, refactoring existing useEffect calls, reviewing PRs with useEffect, or when an agent adds useEffect "just in case." Provides the five replacement patterns and the useMountEffect escape hatch.

No useEffect

@emilien-jegou
emilien-jegou / result.ts
Created February 24, 2025 14:31
Typescript error handling
import type { Prettify } from 'ts-essentials';
export type Result<T = unknown, E = unknown> = Success<T> | Failure<E>;
export interface Success<T> {
kind: 'success';
value: T;
}
export interface Failure<E> {
@rpggio
rpggio / parseOrNull.ts
Last active September 26, 2024 20:28
React hook to persist MUI DataGrid column settings
/**
* If argument is a string, try to parse as JSON.
* Otherwise return null.
*/
export function parseOrNull(raw: unknown) {
if (!raw) return null
if (typeof raw === 'string') {
try {
return JSON.parse(raw)
const uuid = () => Date.now().toString(36) + Math.random().toString(36).substr(2);
@n1snt
n1snt / Oh my ZSH with zsh-autosuggestions zsh-syntax-highlighting zsh-fast-syntax-highlighting and zsh-autocomplete.md
Last active March 31, 2026 08:17
Oh my ZSH with zsh-autosuggestions zsh-syntax-highlighting zsh-fast-syntax-highlighting and zsh-autocomplete.md
@meded90
meded90 / LocalStorageService.ts
Created February 21, 2020 10:13
LocalStorage servise
enum LocalStorageExpired {
INFINITE = 'INFINITE',
LOGOUT = 'LOGOUT',
}
class LocalStorageService {
prefix = 'GG_';
get<T extends unknown>(key: string, defaultValue: T): T {
try {
@praveev
praveev / pull request template.md
Last active May 16, 2020 20:31
pull-request template

Description

Please include a summary of the change and why this is needed.

  • [Design Document](paste URL here or delete)
  • [Jira Ticket](paste URL here or delete)

Type of change

Please delete options that are not relevant.

@ccnokes
ccnokes / event-emitter.js
Created October 30, 2019 15:50
Event emitter using the native DOM APIs: EventTarget and CustomEvent
// Who needs eventemitter3, mitt, or some other library when you can use native DOM APIs? 😁
let eventEmitter = new EventTarget();
eventEmitter.addEventListener('test', console.log); // CustomEvent { type: 'test', detail: 123, ... }
eventEmitter.dispatchEvent(new CustomEvent('test', { detail: 123 }));
@skokenes
skokenes / index.js
Created September 26, 2019 14:25
SVG Path Generator for Rounded Rectangles
function createRoundedRectPath(x, y, width, height, radius) {
return (
// Move to position, offset by radius in x direction
"M" +(x + radius) + "," + y
// Draw a horizontal line to the top right curve start
+ "h" + (width - 2 * radius)
// Draw the top right corner curve
+ "a" + radius + "," + radius + " 0 0 1 " + radius + "," + radius
// Draw a vertical line to the bottom right corner
+ "v" + (height - 2 * radius)
import axios from 'axios';
import { LANGUAGE_NAME, REFRESH_TOKEN_IN_STORE, TOKEN_NAME_IN_STORE } from '../constants/api';
import { getBrowserLang, setTokens } from './GlobalHelper';
import { logoutDispatch } from './StoreHelper';
import LocalStorageHelper from './LocalStorageHelper';
import { BACKEND_ROUTES } from '../constants/routes';
export const API_REQUEST_AUTH_USER_LOGIN_URL = '/users/login';
export const API_REQUEST_AUTH_USER_LOGIN_SOCIAL_URL = '/login/social';