Skip to content

Instantly share code, notes, and snippets.

View MonstraG's full-sized avatar

Arseny Garelyshev MonstraG

  • Lifekeys AS
  • Bergen, Norway
  • 20:45 (UTC +01:00)
View GitHub Profile
const { readFileSync, writeFileSync, readdirSync } = await import('fs');
const componentsToReplace = [
"Snackbar",
"FormHelperText",
"ListItemSecondaryAction",
"ListItemButton",
"IconButton",
"ToggleButtonGroup",
"ToggleButton",
@MonstraG
MonstraG / imgs_to_webp.sh
Created April 24, 2024 08:28
Convert images in folder from (png, svg) -> webp@384px without alpha
#!/bin/bash
if [ -z "$1" ]
then
echo "pass background color to replace transparency with!"
fi
mkdir output
# convert .svg's to .pngs and save them in `output` folder
for file in *.svg; do
#! /bin/bash
# ask go.dev, what is the last version and grep/regex it out
GOLANG_VERSION=$(curl https://go.dev/dl/?mode=json | grep -oP '"version": "\K(go[\d|\.]+)' | head -1)
# download it
wget https://go.dev/dl/"$GOLANG_VERSION".linux-amd64.tar.gz
# nuke existing go installation
rm -rf /usr/local/go
# unpack new version
tar -C /usr/local -xzf "$GOLANG_VERSION".linux-amd64.tar.gz
@MonstraG
MonstraG / useSsrSafeQueryState.tsx
Created November 9, 2023 11:27
Wrapper for "next-usequerystate" for SSR apps
import { useEffect, useState } from "react";
import { useQueryState, type UseQueryStateOptions } from "next-usequerystate";
export const useSsrSafeQueryState = <T,>(
key: string,
options: UseQueryStateOptions<T> & { defaultValue: T }
) => {
const [queryState, setQueryState] = useQueryState<T>(key, options);
const [isFirstRender, setIsFirstRender] = useState<boolean>(true);
@MonstraG
MonstraG / SnackbarHost.tsx
Created November 8, 2023 20:44
Imperative snackbar @mui/joy based ony zustand store. Replacing with react context should be fairly easy.
"use client";
import { Snackbar, type SnackbarProps } from "@mui/joy";
import type { FC } from "react";
import { create } from "zustand";
const useSnackbarStore = create<{
props: Omit<SnackbarProps, "open" | "key">;
key: number;
open: boolean;
}>(() => ({ props: {}, key: 0, open: false }));
import { type MutableRefObject, type Ref, useCallback } from "react";
export const useCombinedRefs = <T,>(...refs: Ref<T>[]) =>
useCallback(
(element: T) =>
refs.forEach((ref) => {
if (!ref) return;
if (typeof ref === "function") {
ref(element);