Skip to content

Instantly share code, notes, and snippets.

View dmi3y's full-sized avatar
🌵
Dill with it

Dmitry Lapshukov dmi3y

🌵
Dill with it
  • Planet Earth
View GitHub Profile
@dmi3y
dmi3y / gittipsandtricks.md
Last active May 21, 2021 16:49
Git Tips and Tricks
@dmi3y
dmi3y / keybase.md
Last active September 13, 2020 20:11

Keybase proof

I hereby claim:

  • I am dmi3y on github.
  • I am dmi3y (https://keybase.io/dmi3y) on keybase.
  • I have a public key ASAtmc2GMZ8OtZQRJZLlVe99TEiNvRTmc3IlhYKp_d8RJwo

To claim this, I am signing this object:

@dmi3y
dmi3y / 12daysOfChristmas.js
Last active December 24, 2018 04:09
12DaysOfChristmas
#!/usr/bin/env node
const sumit = (sum, it) => sum + it
// Christmas is around us!
const christmasPresentsPerDays = (days = 12) => {
const bag = [];
for (let i = 0; i < days; i++) {
bag.push(i + 1 + bag[i - 1] || 1);
}
return bag.reduce(sumit, 0);
function fibonacciSum(n) {
'use strict';
var
sequence = fibonacci(n);
return sequence.reduce(function(a, b) {
return a + b;
});
}
@dmi3y
dmi3y / index.js
Created November 26, 2018 20:02 — forked from zkat/index.js
npx is cool
#!/usr/bin/env node
console.log('Nishtyak!')
@dmi3y
dmi3y / naive.js
Created February 26, 2017 21:20
Number padder
function padding(num, sep) {
var numarr = num['toString']().split('')
var numarrLen = numarr.length
var out = []
for (;numarrLen--;) {
var num = numarr[numarrLen]
out.unshift(num)
if (numarr.length !== numarrLen && num % 3 === 0) out.unshift(sep)
}
return out.join('')
@dmi3y
dmi3y / hashStr2json.js
Last active February 22, 2017 02:06
eval-ish strip comments from js hash string to valid js object `ala unstrict JSON.parse()`, useful for json configuration files where you want to enable comments.
function hashStr2JSON (str) {
try {
return Function('return ' + str)();
} catch(e) {
// something goes wild
throw new Error('Could not parse hash because of: ' + e.toString())
}
}
var jsonfromhash = hashStr2JSON('{a:/*comment*/"b"}//comment'); // read hash string, it will also work with multiline files
@dmi3y
dmi3y / sortJsonByKeys.js
Created June 27, 2016 22:09
Sort JSON structure by keys recursevely
function sortJsonByKeys (json) {
let out = {}
let keys = Object.keys(json)
keys.sort()
keys.forEach((key) => {
if (typeof json[key] === 'object') {
out[key] = sortJsonByKeys(json[key])
} else {
out[key] = json[key]
}
function mapRomanToArabic (roman) {
switch(roman) {
case 'I':
return 1
case 'V':
return 5
case 'X':
return 10
case 'L':
return 50
function findSumPairs(arr, sum) {
'use strict';
var
i = 0,
j = 0,
isum,
imatch,
out = [],
larr;