Skip to content

Instantly share code, notes, and snippets.

View abm0's full-sized avatar

Igor Dranichnikov abm0

  • Ulyanovsk, Russia
View GitHub Profile
function Plant(name) {
this.name = name;
};
Plant.prototype.height = 0;
Plant.prototype.grow = function() {
this.height += 1;
};
@abm0
abm0 / diff.js
Last active October 1, 2019 14:48
var diff = function (obj1, obj2) {
// Make sure an object to compare is provided
if (!obj2 || Object.prototype.toString.call(obj2) !== '[object Object]') {
return obj1;
}
//
// Variables
//
@abm0
abm0 / index.js
Created June 7, 2019 08:35
Get properties diff between two objects
var deepDiffMapper = function() {
return {
VALUE_CREATED: 'created',
VALUE_UPDATED: 'updated',
VALUE_DELETED: 'deleted',
VALUE_UNCHANGED: 'unchanged',
map: function(obj1, obj2) {
if (this.isFunction(obj1) || this.isFunction(obj2)) {
throw 'Invalid argument. Function given, object expected.';
}
@abm0
abm0 / index.js
Last active June 7, 2019 08:36
Snippet for tracing changed component properties
componentDidUpdate(prevProps, prevState) {
Object.entries(this.props).forEach(([key, val]) =>
prevProps[key] !== val && console.log(`Prop '${key}' changed`)
);
Object.entries(this.state).forEach(([key, val]) =>
prevState[key] !== val && console.log(`State '${key}' changed`)
);
}
// hook
/* eslint-disable global-require */
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const ip = require('ip').address();
const postcssImport = require('postcss-import');
const precss = require('precss');
const postcssClearfix = require('postcss-clearfix');
const postcssCenter = require('postcss-center');
const postcssMath = require('postcss-math');
/* eslint-disable global-require */
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const postcssImport = require('postcss-import');
const precss = require('precss');
const postcssClearfix = require('postcss-clearfix');
import React, { Component } from 'react';
export default function withPropsChecker(WrappedComponent) {
return class PropsChecker extends Component {
componentWillReceiveProps(nextProps) {
Object.keys(nextProps)
.filter(key => {
return nextProps[key] !== this.props[key];
})
.map(key => {
const isPalindrome = (string) => {
const _string = string.split(' ').join('').toLowerCase();
const reverseString = _string.split('').reverse().join('');
return _string === reverseString;
}
console.log(isPalindrome('Лазер боре хер обрезал')); // true
console.log(isPalindrome('Карл у Клары украл кораллы')); // false
traverse = (obj, path, callback) ->
i = 0
do (obj) ->
key = path[i]
i++
if typeof obj[key] is 'object'
arguments.callee obj[key]
else
function validate(string) {
if (string[0] == ')') {
console.error(string + ' error: string should start with "("');
return;
}
if (string.length % 2 !== 0) {
console.error(string + ' error: bracket number should be even');
return;
}