Skip to content

Instantly share code, notes, and snippets.

View sagar-gavhane's full-sized avatar
🏠
Working from home

Sagar sagar-gavhane

🏠
Working from home
View GitHub Profile
@sagar-gavhane
sagar-gavhane / app.js
Created July 16, 2018 07:32 — 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 => {
@sagar-gavhane
sagar-gavhane / JsxControls.js
Created July 1, 2018 10:41
JSX Control State IFEE
class JsxControls extends Component {
constructor(props) {
super(props);
this.state = {
counter: 100
}
}
render() {
return (
@sagar-gavhane
sagar-gavhane / handleInputChange.js
Last active June 30, 2018 11:19
HandleInputChange for React function
handleInputChange(name, value, args = {}) {
const { key, ...restArgs } = args;
let obj = {};
if (typeof key !== 'undefined') {
if (Object.keys(restArgs).length === 0 && restArgs.constructor === Object) {
obj = { ...this.state[key], ...{ [name]: value } };
} else {
obj = { ...this.state[key], ...{ [name]: value, ...restArgs } };
}
@sagar-gavhane
sagar-gavhane / parsleyConfig.js
Created June 22, 2018 18:48
Parsley plugin initialization with tweaks to style Parsley for Bootstrap 4
// Parsley plugin initialization with tweaks to style Parsley for Bootstrap 4
$("#my-form").parsley({
errorClass: 'is-invalid text-danger',
successClass: 'is-valid', // Comment this option if you don't want the field to become green when valid. Recommended in Google material design to prevent too many hints for user experience. Only report when a field is wrong.
errorsWrapper: '<span class="form-text text-danger"></span>',
errorTemplate: '<span></span>',
trigger: 'change'
}) /* If you want to validate fields right after page loading, just add this here : .validate()*/ ;
// Parsley full doc is avalailable here : https://github.com/guillaumepotier/Parsley.js/
@sagar-gavhane
sagar-gavhane / workspace.json
Last active July 19, 2018 12:26
Visual Studio Code Settings
{
"window.zoomLevel": 0,
"editor.fontFamily": "Operator Mono Medium, Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 14,
"editor.fontLigatures": true,
"editor.tabSize": 4,
"editor.mouseWheelZoom": true,
"editor.rulers": [120],
"editor.smoothScrolling": true,
"editor.tabCompletion": true,
@sagar-gavhane
sagar-gavhane / sublimetext.txt
Created June 20, 2018 08:18
Sublime Text Licence Key Build 3176
----- BEGIN LICENSE -----
sgbteam
Single User License
EA7E-1153259
8891CBB9 F1513E4F 1A3405C1 A865D53F
115F202E 7B91AB2D 0D2A40ED 352B269B
76E84F0B CD69BFC7 59F2DFEF E267328F
215652A3 E88F9D8F 4C38E3BA 5B2DAAE4
969624E7 DC9CD4D5 717FB40C 1B9738CF
20B3C4F1 E917B5B3 87C38D9C ACCE7DD8
@sagar-gavhane
sagar-gavhane / removeCookie.js
Created June 20, 2018 06:24
Remove all cookies from browser - Important set path
removeCookie(){
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"+";path=/";
}
}
#Add the Ubuntu 12.04(precise) repositories
cat <<EOF >> /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu precise main restricted universe
deb http://archive.ubuntu.com/ubuntu precise-updates main restricted universe
deb http://security.ubuntu.com/ubuntu precise-security main restricted universe multiverse
EOF
# Update the repos
apt-get update
@sagar-gavhane
sagar-gavhane / RegExp.js
Last active January 19, 2019 17:03
Regular Expression for JavaScript
// Matching a ip address version 4
const IPV4_1 = /^(25[0-5]|2[0-4][0-9]|1?[0-9][0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}$/;
const IPV4_2 = /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
const IPV4WithPort = /^((?:2[0-5]{2}|1\d{2}|[1-9]\d|[1-9])\.(?:(?:2[0-5]{2}|1\d{2}|[1-9]\d|\d)\.){2}(?:2[0-5]{2}|1\d{2}|[1-9]\d|\d)):(\d|[1-9]\d|[1-9]\d{2,3}|[1-5]\d{4}|6[0-4]\d{3}|654\d{2}|655[0-2]\d|6553[0-5])$/;
// Matching a ip address version 6
const IPV6_1 = /^([0-9a-f]|:){1,4}(:([0-9a-f]{0,4})*){1,7}$/i;
// Matching a Username
const username_1 = /^[a-z0-9_-]{5,16}$/;
// Ref:
// 1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
// 2. https://davidwalsh.name/es6-generators
// ------------------------------------
function makeIterator(array) {
var nextIndex = 0;
return {