Skip to content

Instantly share code, notes, and snippets.

View useLocalStorage.tsx
import { Dispatch, SetStateAction, useState } from 'react'
export default function useLocalStorage<T>(
key: string,
initialValue: T,
): [T, Dispatch<SetStateAction<T>>] {
// State to store our value
// Pass initial state function to useState so logic is only executed once
const [storedValue, setStoredValue] = useState<T>(() => {
if (typeof window === 'undefined') {
@kachar
kachar / gist:62e91c90a8cce7c6a0877b9563c5834b
Created Jun 9, 2022
find lines of code in a repo and sort them desc
View gist:62e91c90a8cce7c6a0877b9563c5834b
wc -l $(git ls-files services/webapp/**/*.js ) | sort -n
View tp-link ac1300 driver ubuntu
View git-crypt-rm-gpg-user.sh
#!/usr/bin/env bash
#
# Script to remove GPG user (recipient) with git-crypt
#
# It will re-initialize git-crypt for the repository and re-add all keys except
# the one requested for removal.
#
# Note: You still need to change all your secrets to fully protect yourself.
# Removing a user will prevent them from reading future changes but they will
# still have a copy of the data up to the point of their removal.
View golang-vscode.md

After the March update 1.55.0 of VSCode I've experienced a misconfiguration in golang extension

Failed to run '/snap/bin/go env. The config change may not be applied correctly.

Golang is installed locally via snap so I had to change the following paths in vscode settings.json

go env GOPATH
go env GOROOT
View DockerTasks.yml
# https://taskfile.dev
# sudo snap install task --classic
version: "3"
tasks:
ps: docker-compose ps
up: docker-compose up -d {{- .SERVICE}}
View README.md

Usage

<WizardProvider steps={4}>
  <Container maxWidth="sm">
    <Paper className={classes.paper}>
      <WizardSlotForm />
    </Paper>
 
@kachar
kachar / Dockerfile
Created Feb 16, 2021
Production ready multi-stage Next.js docker container based on node:14-alpine (avg size 250mb)
View Dockerfile
# Build target dependencies #
###########################
FROM node:14-alpine AS base
WORKDIR /app
ARG NODE_ENV=production
ENV PATH=/app/node_modules/.bin:$PATH \
NODE_ENV="$NODE_ENV"
COPY package.json yarn.lock /app/
EXPOSE 3040
@kachar
kachar / xdLocalStorage.js
Created Feb 13, 2021
cross-domain-local-storage ES6
View xdLocalStorage.js
/**
* Created by dagan on 07/04/2014.
* https://github.com/ofirdagan/cross-domain-local-storage
*/
const MESSAGE_NAMESPACE = "cross-domain-local-message";
/* global console */
export const xdLocalStorage = () => {
const requests = {};
@kachar
kachar / htmlentity.js
Last active Jan 6, 2021 — forked from CatTail/htmlentity.js
Javascript: encode(decode) html text into html entity
View htmlentity.js
// encode(decode) html text into html entity
var decodeHtmlEntity = function(str) {
return str.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
});
};
var encodeHtmlEntity = function(str) {
var buf = [];
for (var i=str.length-1;i>=0;i--) {