Skip to content

Instantly share code, notes, and snippets.

View VinayakBagaria's full-sized avatar
💭
So much to experiment on..

Vinayak Bagaria VinayakBagaria

💭
So much to experiment on..
View GitHub Profile
@VinayakBagaria
VinayakBagaria / .editorconfig
Last active January 8, 2024 15:23
Prettier, ESLint, Husky, Lint-Staged, Editorconfig for React (Web/Native)
# look for an .editorconfig file inside this project
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
# while saving
insert_final_newline = true
@VinayakBagaria
VinayakBagaria / Websites
Last active May 17, 2018 19:24
List of dev websites whitelisted in Chrome for Wakatime
https://github.com
https://codesandbox.io
https://codepen.io
https://medium.com
https://codementor.io
https://reddit.com
https://egghead.io
https://freecodecamp.com
https://facebook.github.io
https://www.vuemastery.com
import React from 'react'
export default function withRouter(WrappedComponent) {
const WithRouter = ({router}) => {
if (!router) {
return <WrappedComponent {...this.props} />
}
const { params, location, routes } = router
const props = { ...this.props, router, params, location, routes }
return <WrappedComponent {...props} />
@VinayakBagaria
VinayakBagaria / routes.js
Created August 16, 2018 17:08
Lazy loading via React Loadable for routing
import Loadable from 'react-loadable';
const A = Loadable({
loader: () => import('../A' /* webpackChunkName: "pc-r-A" */),
loading: () => null,
});
const B = Loadable({
loader: () => import('../B' /* webpackChunkName: "pc-r-B" */),
loading: () => null,
@VinayakBagaria
VinayakBagaria / dominant.py
Last active August 20, 2018 20:21
Get 2 most dominant colors from an input image - verify at https://www.w3schools.com/colors/colors_rgb.asp
from collections import namedtuple
from math import sqrt
import random
from PIL import Image
Point = namedtuple('Point', ('coords', 'n', 'ct'))
Cluster = namedtuple('Cluster', ('points', 'center', 'n'))
def get_points(img):
points = []
@VinayakBagaria
VinayakBagaria / resize-image.py
Created August 21, 2018 08:16
Resize original image and save it
from PIL import Image, ImageDraw
def get_colors(infile, outfile, resize=150):
image = Image.open(infile)
im = image.resize((resize, resize))
im.save(outfile, "JPEG")
if __name__ == '__main__':
get_colors('abc.jpeg', 'outfile.jpeg')
@VinayakBagaria
VinayakBagaria / polyfill.js
Created October 2, 2018 16:40
Dynamic pollyfill loading
let TransformStreamPromise = Promise.resolve()
.then(() => {
if ('TransformStream' in self) {
return TransformStream;
}
const { TransformStream } = await import('./some-polyfill.js');
return TransformStream;
});
(async function () {
@VinayakBagaria
VinayakBagaria / app.js
Created October 2, 2018 17:33 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@VinayakBagaria
VinayakBagaria / HOC-connection.js
Created October 16, 2018 06:56
Connection Component
function withConnectionType(WrappedComponent, respondToChange = false) {
return class extends React.Component {
constructor(props) {
super(props)
this.state = {
connectionType: undefined
}
// Basic API Support Check.
this.hasNetworkInfoSupport = Boolean(
navigator.connection && navigator.connection.effectiveType
@VinayakBagaria
VinayakBagaria / GalleryBox.js
Last active December 7, 2018 19:52
Image Observer React Gallery Box
// @flow
import React, { PureComponent } from 'react';
import GalleryBoxWithIntersection from './GalleryBoxWithIntersection';
import GalleryBoxWithoutIntersection from './GalleryBoxWithoutIntersection';
type Image = {
url: string,
height: number,
width: number,