Skip to content

Instantly share code, notes, and snippets.

View agrublev's full-sized avatar
💭
Always moving forward

Angel Grablev agrublev

💭
Always moving forward
View GitHub Profile
/* eslint eqeqeq: 0 */
import React from 'react';
function computeHeight(node) {
const totalHeight = parseInt(getComputedStyle(node).height, 10);
const padding =
parseInt(getComputedStyle(node).paddingTop, 10) +
parseInt(getComputedStyle(node).paddingBottom, 10);
return totalHeight - padding;
}
@agrublev
agrublev / recursiveFileList.js
Last active January 31, 2020 17:31
read files recursively Node Recursive File List
const fs = require("fs");
const path = require("path");
const walk = function(dir, done) {
let results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
let pending = list.length;
if (!pending) return done(null, results);
list.forEach(function(file) {
const isObject = obj => obj === Object(obj);
const merge = (obj1, obj2) => {
Object.keys(obj1).forEach(key => {
if (Array.isArray(obj1[key])) {
if (obj2[key]) obj1[key] = [...obj1[key], ...obj2[key]];
} else if (isObject(obj1[key])) {
if (obj2[key]) obj1[key] = { ...obj1[key], ...obj2[key] };
} else {
if (obj2[key] !== undefined) {
@agrublev
agrublev / genFileDateName.js
Last active October 22, 2019 19:56
Generate filename with date
/**
* Return a timestamp with the format "m-d-yy"
* @type {Date}
*/
function timeStamp() {
// Create a date object with the current time
let now = new Date();
// Create an array with the current month, day and time
const arr1 = [1, 2, 3, 4, 5];
if (arr1.indexOf(1) !== -1) {
console.log("Arr1 HAS the integer 1!");
}
if (arr1.includes(1)) {
console.log("Arr1 HAS the integer 1!");
}
@agrublev
agrublev / cleanall.sh
Created June 4, 2019 05:49
Clean all node modules
find . -name "node_modules" -exec rm -rf '{}' +
@agrublev
agrublev / RECURS_OBJECTS.js
Last active April 23, 2019 19:13
Recursive object manipulation
const iterateObject = (obj, executeOnValue) => {
Object.keys(obj).forEach(name=> {
let val = obj[name];
if (typeof val === "object") {
return iterateObject(val, executeOnValue);
} else if (val === undefined) {
obj[name] = "";
} else {
obj[name] = executeOnValue(val);
}
import "@blueprintjs/icons/lib/css/blueprint-icons.css";
import "@blueprintjs/core/lib/css/blueprint.css";
module.exports = {
plugins: ["react","markdown"],
globals: {
importScripts: true
},
env: {
browser: true,
node: true,
es6: true
},