Skip to content

Instantly share code, notes, and snippets.

@kachar
kachar / Dockerfile
Created February 16, 2021 15:13
Production ready multi-stage Next.js docker container based on node:14-alpine (avg size 250mb)
# 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 February 13, 2021 11:52
cross-domain-local-storage ES6
/**
* 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 January 6, 2021 12:59 — forked from CatTail/htmlentity.js
Javascript: encode(decode) html text into html entity
// 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--) {
@kachar
kachar / LocaleSwitcher.tsx
Last active February 1, 2023 06:56
i18next + next.js 10 + Material UI
import { useCallback } from 'react'
import { useRouter } from 'next/router'
import { useTranslation } from 'react-i18next'
import { Box, Button, ButtonGroup } from '@material-ui/core'
export default function LocaleSwitcher() {
const { t } = useTranslation()
const router = useRouter()
const changeLang = useCallback(
// Same route different language
@kachar
kachar / psql_useful_stat_queries.sql
Created November 24, 2020 15:20 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables
@kachar
kachar / create_certificates.sh
Created October 31, 2020 20:15 — forked from OnnoGabriel/create_certificates.sh
Create self-signed CA certificates and certificates for local domains
#!/bin/bash
# Creates self-signed CA certificates and certificates for local domains.
#
# Prompts for a local domain name (e.g. my-app.localhost) and creates all
# necessary certificates.
#
# Next steps:
# Copy the certificates (e.g. my-app.localhost.crt and my-app.localhost.key) to
# your service (Nginx, Apache, ...) and configure it.
@kachar
kachar / gist:0f787af108607a309c1c0858d87b34a2
Last active August 25, 2022 07:48 — forked from svilensabev/gist:713584cd30133969f395d1333563031e
PostgreSQL timeslots, rrulesets and booking timetables
-- First create schema/data data for tests
DROP TABLE api.slot CASCADE;
CREATE TABLE api.slot (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT,
latitude NUMERIC,
longitude NUMERIC,
geog geography(Point, 4326) DEFAULT NULL
@kachar
kachar / RouteIndicator.tsx
Last active March 8, 2020 23:51 — forked from jaydenseric/RouteIndicator.js
A route change indicator for Next.js using React hooks.
import cn from 'classnames'
import Router from 'next/router'
import React, { useState } from 'react'
const DONE_DURATION = 250
export default function RouteIndicator() {
const [loading, setLoading] = useState(false)
const [timeoutId, setTimeoutId] = useState<ReturnType<typeof setTimeout>>()
@kachar
kachar / Link-Next13.tsx
Last active January 21, 2024 11:44
Next.js Link + Material UI Link/Button components bundled with forwardRef
@kachar
kachar / actions.js
Created July 1, 2019 21:30
actions.js
import React from 'react'
import _ from 'lodash'
import PropTypes from 'prop-types'
import lang from 'lang'
import Form from 'common/components/form'
import './actions.scss'
export default class EmotionWordActions extends Form {