Skip to content

Instantly share code, notes, and snippets.

View akullpp's full-sized avatar

aku akullpp

View GitHub Profile
@akullpp
akullpp / use-auto-save.ts
Created February 8, 2024 23:50
Autosave hook for react-hook-form
import { useCallback } from 'react'
import { debounce } from 'lodash-es'
import { useWatch } from 'react-hook-form-mui'
import type { useForm } from 'react-hook-form-mui'
import { useDeepEffect } from '@/hooks/use-deep-effect'
const useAutoSave = (context: ReturnType<typeof useForm>, onSubmit: (data: unknown) => void) => {
const watch = useWatch({ control: context.control })
@akullpp
akullpp / use-deep-effect.ts
Created February 8, 2024 23:49
Deep compare version of useEffect for React
import { useEffect, useMemo, useRef } from 'react'
import { isEqual } from 'lodash-es'
type UseEffectParams = Parameters<typeof useEffect>
type EffectCallback = UseEffectParams[0]
type DependencyList = UseEffectParams[1]
type UseEffectReturn = ReturnType<typeof useEffect>
const isPrimitive = (val: unknown) => {
@akullpp
akullpp / use-previous.ts
Created February 8, 2024 23:49
Use previous value hook for React
import { useEffect, useRef } from 'react';
const usePrevious = (value) => {
const ref = useRef();
useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
@akullpp
akullpp / repeat.ts
Created February 8, 2024 23:41
Repeat query params
// Builds the query params in a way that extends arrays of params to be repeated instead of concatenated, e.g.
// { id: 1, foo: ['1', '2', '3'] } => /api?id=1&foo=1&foo=2&foo=3
const repeat = (url: string, params: object) => {
const p = new URLSearchParams()
Object.entries(params).forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach((v) => {
return p.append(key, v)
})
} else if (value) {
@akullpp
akullpp / keeping-a-stoic-journal.md
Last active November 20, 2023 17:24
Keeping a Stoic Journal

I have experimented with other exercises, but journaling is my primary Stoic exercise, although I journal a variety of ways.

One of the better starting points (not historically Stoic, but influenced by Stoicism) is the philosophical meditation routine from the The Philosopher's Mail, although I personally bring more Stoic elements into it by, in addition to the questions listed there, I ask what the different experiences say about what I value, whether these values concern virtues/vices or externals, and what virtues and vices do apply.

Although I think it clear that writing was an important element in ancient Stoic training, explicit instructions are lacking. The best references I know of are Marcus Aurelius's Meditations as an example of such writing, Epictetus's Discourses I.1 and II.1. There is also Seneca's letter 84.

Other journaling ideas, some Stoic (or at least related to Stoicism), some not (repeated from an [earlier comm

@akullpp
akullpp / keybindings.json
Created October 5, 2023 20:08
console.log keybinding for vscode
[
{
"key": "cmd+shift+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.log(${TM_SELECTED_TEXT}$1)$0"
}
}
]
@akullpp
akullpp / ecr_lifecycle_policy.json
Created October 1, 2023 18:03
ECR Lifecycle Policy
{
"rules": [
{
"action": {
"type": "expire"
},
"selection": {
"countType": "imageCountMoreThan",
"countNumber": 3,
"tagStatus": "tagged",
@akullpp
akullpp / commands.txt
Last active June 7, 2022 06:45
Solve Python Poetry invalid hashes error after CTRL+C during installation on MacOS
rm -rf poetry.lock
poetry cache clear . --all
rm -r ~/Library/Caches/pypoetry/cache
rm -r ~/Library/Caches/pypoetry/artifacts
poetry install
@akullpp
akullpp / command.txt
Last active May 23, 2022 09:42
Install a different arch (e.g. darwin_amd64) with asdf if you have a M1 macbook (e.g. darwin_arm64)
arch -x86_64 asdf install <plugin> <version>
@akullpp
akullpp / try.kt
Created August 9, 2021 11:54
Try
sealed class Try<T> {
companion object {
operator fun <T> invoke(func: () -> T): Try<T> =
try {
Success(func())
} catch (error: Exception) {
Failure(error)
}