Skip to content

Instantly share code, notes, and snippets.

@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 April 24, 2025 13:33
Oh my ZSH with zsh-autosuggestions zsh-syntax-highlighting zsh-fast-syntax-highlighting and zsh-autocomplete.md

Oh my zsh.

Oh My Zsh

Install ZSH.

sudo apt install zsh-autosuggestions zsh-syntax-highlighting zsh

Install Oh my ZSH.

@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';
@wesleygrimes
wesleygrimes / ngrx-higher-order-action-creators.ts
Created July 21, 2019 21:44
NgRx v8 Higher-Order Action Creators
import { createAction, props } from '@ngrx/store';
import { Joke } from 'src/app/models';
export const createJokeSuccessAction = (actionType: string) =>
createAction(actionType, props<{ jokes: Joke[] }>());
export const createJokeFailureAction = (actionType: string) =>
createAction(actionType, props<{ error: any }>());
export const loadAll = createAction('[Jokes Page] Load All');