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
@agrublev
agrublev / CircularJSON.js
Last active February 20, 2020 16:49
Circular JSON stringify
var // should be a not so common char
// possibly one JSON does not encode
// possibly one encodeURIComponent does not encode
// right now this char is '~' but this might change in the future
specialChar = "~",
safeSpecialChar = "\\x" + ("0" + specialChar.charCodeAt(0).toString(16)).slice(-2),
escapedSafeSpecialChar = "\\" + safeSpecialChar,
specialCharRG = new RegExp(safeSpecialChar, "g"),
safeSpecialCharRG = new RegExp(escapedSafeSpecialChar, "g"),
safeStartWithSpecialCharRG = new RegExp("(?:^|([^\\\\]))" + escapedSafeSpecialChar),
@agrublev
agrublev / asdsad.md
Last active December 17, 2019 16:08

(fix) [teas] sad - 2016-09-07

5343}

Updated:


package bump type
"@f/fkit" patch
/* 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);
}