Skip to content

Instantly share code, notes, and snippets.

Avatar
🌵
Dill with it

Dmitry Lapshukov dmi3y

🌵
Dill with it
  • Planet Earth
View GitHub Profile
View keybase.md

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 Dec 24, 2018
12DaysOfChristmas
View 12daysOfChristmas.js
#!/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);
@dmi3y
dmi3y / index.js
Created Nov 26, 2018 — forked from zkat/index.js
npx is cool
View index.js
#!/usr/bin/env node
console.log('Nishtyak!')
@dmi3y
dmi3y / naive.js
Created Feb 26, 2017
Number padder
View naive.js
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 / sortJsonByKeys.js
Created Jun 27, 2016
Sort JSON structure by keys recursevely
View sortJsonByKeys.js
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]
}
View roman-to-arabic.js
function mapRomanToArabic (roman) {
switch(roman) {
case 'I':
return 1
case 'V':
return 5
case 'X':
return 10
case 'L':
return 50
View calc.js
function calcFromStr(str) {
var ops = ['*','/','+','-'];
var reg = /(\b\D)/;
var calc = str.split(reg);
function calculator(l, op, r) {
switch( op ) {
case '*':
return l*r;
@dmi3y
dmi3y / findintersections.js
Last active Aug 29, 2015
Find intersections
View findintersections.js
// http://jsbin.com/mapena/edit?js,console
// http://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript
function findIntersctions(a, b) {
var ai = 0;
var bi = 0;
var out = [];
while( ai < a.length && bi < b.length ) {
if( a[ai] > b[bi] ) {
@dmi3y
dmi3y / uber.js
Created Jun 17, 2015
`uber` (super) method from Douglas Crockford - http://www.crockford.com/javascript/inheritance.html
View uber.js
Function.method('inherits', function (parent) {
this.prototype = new parent();
var d = {},
p = this.prototype;
this.prototype.constructor = parent;
this.method('uber', function uber(name) {
if (!(name in d)) {
d[name] = 0;
}
var f, r, t = d[name], v = parent.prototype;
@dmi3y
dmi3y / closure.js
Last active Aug 29, 2015
Countdowns
View closure.js
function setCountDown(n) {
n = n || 5;
for ( var i = 0; i <= n; i++ ) {
(function() {
var j = n - i;
setTimeout(function() {
console.log(j);
}, 1000 * i);
}());
}