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 / post_message_example.js
Last active Aug 31, 2020
window.postMessage example
View post_message_example.js
// recieve message
// event object contains:
// - data: message sent
// - origin (host from which the message was sent, e.g. http://blah.example.com)
// - source (reference to a Window object from which message was sent)
function postMessageHandler( event ) {
console.log("We've got a message!");
console.log("* Message:", event.data);
console.log("* Origin:", event.origin);
console.log("* Source:", event.source);
@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 / 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";
@vishaltelangre
vishaltelangre / tools_i_use.md
Last active Apr 28, 2020
Tools I Use #tools_i_use
View tools_i_use.md

Shell

Git

@vishaltelangre
vishaltelangre / blur.css
Created Apr 17, 2014
cross browser blur filter using css
View blur.css
.blur {
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
-ms-filter: blur(3px);
-o-filter: blur(3px);
/* FF doesn't support blur filter, but SVG */
filter: url("data:image/svg+xml;utf8,<svg height='0' xmlns='http://www.w3.org/2000/svg'><filter id='svgBlur' x='-5%' y='-5%' width='110%' height='110%'><feGaussianBlur in='SourceGraphic' stdDeviation='5'/></filter></svg>#svgBlur");
filter: progid: DXImageTransform.Microsoft.Blur(PixelRadius = '3');
filter: blur(3px);
}
View logrotate.md
  • Create /etc/logrotate.d/my-crazy-app file with following snippet:
/var/log/my-crazy-app/*.log {
        daily
        size 500M
        missingok
        rotate 10
        compress
        delaycompress
View combine_pdfs_into_one.sh
"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o "output.pdf" *.pdf
@vishaltelangre
vishaltelangre / savon.rb
Last active Sep 16, 2019
Logging Savon SOAP requests/responses in Rails
View savon.rb
# initializers/savon.rb
# Savon Global configuration
Savon.configure do |config|
config.log = true
config.log_level = :debug
config.logger = Rails.logger
config.env_namespace = :soapenv
end
@vishaltelangre
vishaltelangre / nginx_assets.md
Last active Sep 12, 2019
Serving Static Assets via Nginx
View nginx_assets.md

Concept

  • People talk about two servers: a web server (e.g. Nginx, Apache, etc.) and a app server (e.g. Language specific servers like Unicorn, Node.js, Tomcat, Http-Kit, etc.). There are exceptions where app servers not required at all (as web server itself provides preprocessors for handling), but let's not talk about now.
  • Web servers are really fast and supports lot of standard and commonly used MIME-type requests. Concept of serving a file is -- forming and sending a response of bytes of data and labeling it with requested MIME-type by a client (e.g. web browser).
  • Every response format (in layman's language, a file) is recognized by it's MIME-type, for e.g. a PNG image file has "image/png" MIME-type. JavaScript file has "text/javascript". HTML responses (or files) has "text/html". Plain text files have "text/plain".
  • Modern Browsers supports a lot of standard MIME-types. Images, videos, text files (XML, HTML, SVG, JS), and they better know how to visualize it. Browser also knows unrec
You can’t perform that action at this time.