Skip to content

Instantly share code, notes, and snippets.

@mkarajohn
mkarajohn / cloudSettings
Last active September 12, 2018 14:29
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-05-05T00:31:17.192Z","extensionVersion":"v2.9.2"}
@mkarajohn
mkarajohn / machine.js
Last active April 1, 2020 04:26
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@mkarajohn
mkarajohn / machine.js
Created April 2, 2020 17:00
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@mkarajohn
mkarajohn / machine.js
Last active April 3, 2020 02:13
Generated by XState Viz: https://xstate.js.org/viz
const fileMachine = Machine(
{
id: 'file',
initial: 'idle',
context: null,
states: {
idle: {
on: {
START: 'pending',
},
@mkarajohn
mkarajohn / collapsed-stacked-inlines.js
Created January 11, 2021 20:24
Django Collapsed Stacked Inlines
/* collapsed_stacked_inlines.js */
/* Created in May 2009 by Hannes Rydén */
/* Use, distribute and modify freely */
// Original script
// https://djangosnippets.org/snippets/1492/
// 2021 updates by Dimitris Karagiannis
// @MitchKarajohn
@mkarajohn
mkarajohn / useCustomizableSpecificReactQueryHook.ts
Last active February 9, 2024 21:24
Customizable specific react-query hook
// Usecase: Say you have an endpoint `/clients` and you have created a custom
// hook, that wraps over a `useQuery` that has a fixed `queryKey` and `queryFn`
// (because it is supposed to only fetch data from the `/clients` endpoint)
// However you want to be able to pass a valid `useQuery` config object in order
// to customize its behaviour (except for passing a custom queryKey or queryFn)
// This is one way to do this.
// 2023 Dimitris Karagiannis
// Twitter: @MitchKarajohn
export function useSpecificButCustomizableQuery(
@mkarajohn
mkarajohn / useTextInputToDelayedURLParam.ts
Last active February 13, 2024 16:31
A React hook that propagates the value of a text input to a specific URL param after a small delay. This implementation depends on react-router-dom ^5.x.x but can be modified to use another solution
import { useEffect, useState } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
/*
* The following hook makes use of this technique
* https://react.dev/reference/react/useState#storing-information-from-previous-renders
* thus cutting down the amount of re-renders to a minimum.
* Do not freak out by the lack of useEffects
* // 2024 Dimitris Karagiannis
* // Twitter: @MitchKarajohn