Skip to content

Instantly share code, notes, and snippets.

Avatar

Vishal Telangre vishaltelangre

View GitHub Profile
@vishaltelangre
vishaltelangre / FormikSubmitErrorMiddleware.js
Created Sep 18, 2020
Get access to errors on submitting the Formik-powered form and act accordingly anywhere down the Formik children hierarchy #formik
View FormikSubmitErrorMiddleware.js
import React, { useEffect } from "react";
import { useFormikContext } from "formik";
const FormikSubmitErrorMiddleware = ({ onSubmitError }) => {
const formikContext = useFormikContext();
const { submitCount, isSubmitting, isValid } = formikContext;
useEffect(() => {
if (
submitCount > 0 &&
@vishaltelangre
vishaltelangre / 100-local-citus.sql
Created Aug 9, 2020 — forked from marchelbling/100-local-citus.sql
Local Citus cluster setup — bis
View 100-local-citus.sql
-- user:
CREATE ROLE citus WITH NOSUPERUSER LOGIN IN ROLE pg_monitor;
-- database:
ALTER DATABASE citus SET citus.shard_replication_factor = 1;
ALTER DATABASE citus OWNER TO citus;
-- extensions:
CREATE EXTENSION IF NOT EXISTS "hll";
CREATE EXTENSION IF NOT EXISTS "topn";
View combine_pdfs_into_one.sh
"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o "output.pdf" *.pdf
View upsert_all_postgres_issue.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
@vishaltelangre
vishaltelangre / left_shift_and_right_shift_operators.md
Last active Aug 31, 2018
Left Shift (<<) and Right Shift (>>) Operators
View left_shift_and_right_shift_operators.md

Left Shift (<<) Operator

x << y == x * (2 ^ y)
Examples
1 << 5 == 1 * (2 ^ 5) == 32
@vishaltelangre
vishaltelangre / Main.elm
Last active Oct 22, 2017
Heartbeat animation rendering on HTML5 Canvas in Elm using "evancz/elm-graphics" package. Compatible with Elm v 0.18. This is ported from an old example on http://outreach.mcmaster.ca/tutorials/animation/animation.html which uses old packages like "Signal" and "Graphics.Collage" which no longer exists in new Elm versions now.
View Main.elm
module Main exposing (..)
import Html exposing (..)
import Color exposing (..)
import Collage exposing (..)
import Element exposing (..)
import Time exposing (Time)
import AnimationFrame
@vishaltelangre
vishaltelangre / Managing_Data_in_Microservices.md
Last active Aug 27, 2017
Managing Data in Microservices - Notes
View Managing_Data_in_Microservices.md

Link to the talk: https://www.infoq.com/presentations/microservices-data-centric

Notes:

  1. Service for each table
  2. Local/own/isolated database for each service
  3. Cache join query information locally on respective service's DBs on each write to avoid cascaded service calls (aka joins in monolithic/shared DB)
  4. Alternative to ACID transactions is to perform multi-step operations using a state machine which can be rollbacked
  5. Dealing with events
    5.1 At most once delivery - When you don't care about such events, like logging stuff using UDP
View keybase.md

Keybase proof

I hereby claim:

  • I am vishaltelangre on github.
  • I am vishaltelangre (https://keybase.io/vishaltelangre) on keybase.
  • I have a public key ASAgnXEmPd6H1DjWLMKbHYF4gOL529tTFVCjGzWvqDRwQQo

To claim this, I am signing this object:

@vishaltelangre
vishaltelangre / mac_locate_big_files.md
Last active Aug 26, 2020
Locate big files on macOS
View mac_locate_big_files.md
$ mdfind 'kMDItemFSSize > 200000000' | sed 's| |\\ |g' | xargs du -sch
#                             ^
#                         ~ 200MiB
@vishaltelangre
vishaltelangre / docker.sh
Created Oct 1, 2016
Add a volume to an existing Docker container
View docker.sh
docker run --name rails-modified-container -v "$PWD":/usr/src/app -w /usr/src/app -d rails
^ ^ ^ ^
name of container app dir dir on image from which
on host container create container
You can’t perform that action at this time.