Skip to content

Instantly share code, notes, and snippets.

View vishaltelangre's full-sized avatar

Vishal Telangre vishaltelangre

View GitHub Profile
@vishaltelangre
vishaltelangre / async_load_script.js
Last active November 3, 2020 21:39
load script async #js
function loadScript( url, callback ) {
// create script element
var script = document.createElement('script');
script.async = true;
script.src = url;
// attach it to DOM
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(script, entry);
@vishaltelangre
vishaltelangre / FormikSubmitErrorMiddleware.js
Created September 18, 2020 14:28
Get access to errors on submitting the Formik-powered form and act accordingly anywhere down the Formik children hierarchy #formik
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 August 9, 2020 15:08 — forked from marchelbling/100-local-citus.sql
Local Citus cluster setup — bis
-- 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 / blur.css
Created April 17, 2014 09:34
cross browser blur filter using 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);
}
@vishaltelangre
vishaltelangre / combine_pdfs_into_one.sh
Created October 3, 2019 11:07
#combine_pdf #merge_pdf #pdf
"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o "output.pdf" *.pdf
@vishaltelangre
vishaltelangre / savon.rb
Last active September 16, 2019 14:41
Logging Savon SOAP requests/responses in Rails
# 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
# 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 August 31, 2018 18:01
Left Shift (<<) and Right Shift (>>) Operators

Left Shift (<<) Operator

x << y == x * (2 ^ y)
Examples
1 &lt;&lt; 5 == 1 * (2 ^ 5) == 32
@vishaltelangre
vishaltelangre / make_encrypt_decrypt.md
Last active January 26, 2018 10:29
encrypt/decrypt confidential file with CAST5 algorithm
  • Let's encrypt a file conf/config.json from current directory
  • Create a file named Makefile with following contents:
.PHONY: _pwd_prompt decrypt_conf encrypt_conf
 
CONF_FILE=conf/config.json
 
# 'private' task for echoing instructions
_pwd_prompt:
@vishaltelangre
vishaltelangre / Main.elm
Last active October 22, 2017 16:43
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.
module Main exposing (..)
import Html exposing (..)
import Color exposing (..)
import Collage exposing (..)
import Element exposing (..)
import Time exposing (Time)
import AnimationFrame