Skip to content

Instantly share code, notes, and snippets.

View leonidkuznetsov18's full-sized avatar
:electron:
stay hungry, stay foolish

Leonid Kuznetsov leonidkuznetsov18

:electron:
stay hungry, stay foolish
View GitHub Profile
@leonidkuznetsov18
leonidkuznetsov18 / arrayPlusArray.js
Last active May 27, 2020 19:46
Array plus Array (codewars)
function arrayPlusArray(arr1, arr2) {
return arr1.concat(arr2).reduce((acc, cur) => acc + cur);
}
// return masked string
function maskify(cc) {
return cc.replace(/.(?=.{4})/g, "#");
}
// or
function maskify(cc) {
return cc.replace(/.(?=....)/g, '#');
}
// or
function maskify(cc) {
@leonidkuznetsov18
leonidkuznetsov18 / isDblTouchTap.js
Created January 31, 2018 09:18 — forked from MoOx/isDblTouchTap.js
Double touch tap workaround for React based on onTouchTap (react-tap-event-plugin)
const dblTouchTapMaxDelay = 300
let latestTouchTap = {
time: 0,
target: null,
}
export default function isDblTouchTap(event) {
const touchTap = {
time: new Date().getTime(),
target: event.currentTarget,
@leonidkuznetsov18
leonidkuznetsov18 / findAll.js
Last active May 27, 2020 19:45
Find property by key in deep object
// with recursion
function findAll(obj, key){
if(Array.isArray(obj)){
return obj.reduce((a,v) => a.concat(findAll(v, key)),[]);
}
if(typeof obj === 'object'){
return Object.keys(obj).reduce(function(v, k){
if(k === key){
return v.concat(obj[k]);
}
@leonidkuznetsov18
leonidkuznetsov18 / difference.js
Last active May 27, 2020 19:45
Deep diff between two object
function difference(object, base) {
return _.transform(object, (result, value, key) => {
if (!_.isEqual(value, base[key])) {
result[key] = _.isObject(value) && _.isObject(base[key]) ? difference(value, base[key]) : value;
}
});
}
ssh-keygen -t rsa -C "<email>" -f <name_key>
exec zsh -l
@leonidkuznetsov18
leonidkuznetsov18 / reboot.css
Last active April 1, 2019 19:15
reboot.css
/* Document
1. Change from `box-sizing: content-box` so that `width` is not affected by `padding` or `border`.
2. Change the default font family in all browsers.
3. Correct the line height in all browsers.
4. Prevent adjustments of font size after orientation changes in IE on Windows Phone and in iOS.
5. Setting @viewport causes scrollbars to overlap content in IE11 and Edge, so we force a non-overlapping, non-auto-hiding scrollbar to counteract.
6. Change the default tap highlight to be completely transparent in iOS.
*/
*,
*::before,
@leonidkuznetsov18
leonidkuznetsov18 / group_anagrams.js
Last active June 26, 2019 17:04
Group Anagrams
/*
INPUT
anagrams(['xxy', 'cab', 'bca', 'cab', 'bac', 'baa', 'abb', 'dash', 'shad'])
OUTPUT
[
['xxy'],
['cab', 'bca’, 'bac'],
['dash', 'shad'],
['abb'],