Skip to content

Instantly share code, notes, and snippets.

View eugeneglova's full-sized avatar

Eugene Glova eugeneglova

View GitHub Profile

Keybase proof

I hereby claim:

  • I am eugeneglova on github.
  • I am eugeneglova (https://keybase.io/eugeneglova) on keybase.
  • I have a public key ASBrec6n1FG-muShEVnao1E0EGvSWfu9feDyDgC38639-Ao

To claim this, I am signing this object:

document.body.innerHTML = "";
var script = document.createElement("script");
script.src =
"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js";
document.body.appendChild(script);
document.body.style.background = "#fff";
var script = document.createElement("script");
script.src =
"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css";
@eugeneglova
eugeneglova / findmissing.js
Last active August 25, 2017 06:33
find missing
var list = [1, 3, 5, 2, 6, 7, 9, 4];
list.sort();
function find(list, acc = 0) {
if (list.length < 3 && list[1] - list[0] !== 1) return list[0] + 1;
const n = Math.round(list.length / 2);
const n1 = acc + n;
const realN = list[n - 1];
return find(n1 * (n1 + 1) === realN * (realN + 1) ? list.slice(n - (list.length % 2 === 0 ? 0 : 1)) : list.slice(0, n), n1);
}
find(list);
@eugeneglova
eugeneglova / recursion.js
Created February 27, 2017 09:32
tail call recursion optimization for factorial and fibonacci
'use strict';
const factorial = n => n < 2 ? 1 : n * factorial(n - 1)
// run with --harmony and "use strict" to optimize tail call recursion
const factorialOptimizedTailRecursion = (n, acc = 1) => n < 2 ? acc : factorialOptimizedTailRecursion(n - 1, acc * n)
const n = 100000000
// console.log(factorial(n)) // RangeError: Maximum call stack size exceeded
@eugeneglova
eugeneglova / flatten.js
Last active February 1, 2017 15:19
Flatten Array ES6
/**
* Flattens deeply nested array into simple array
* @param {Array} arr - input array of numbers
* @param {Array} [acc] - accumulator to store resulting array during recursion calls
* @return {Array}
*/
const flatten = (arr, acc = []) => {
const isArray = Array.isArray(arr);
// safe check for input
@eugeneglova
eugeneglova / .vimrc
Created October 7, 2016 09:51
vim settings
set nocompatible
" filetype off
let $PATH = $PATH . ':' . expand("~/.local/bin")
call plug#begin('~/.vim/plugged')
Plug 'eshion/vim-sync'
Plug 'jlanzarotta/bufexplorer'
" Plug 'nathanaelkane/vim-indent-guides'
@eugeneglova
eugeneglova / index.js
Last active April 25, 2021 20:55
Fill array with missing values using recursion
// [1,3,8,9,17] -> [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
// Using recursion
var dates = [1,3,8,9,17];
function nextI (i) {return i+1;}
function getMissingElements(nextI, element, currentNextElement) {
var nextElement = nextI(element);
if (nextElement === currentNextElement) {
return [];
}
return [nextElement].concat(getMissingElements(nextI, nextElement, currentNextElement));
<?php
error_reporting(E_ALL & ~E_WARNING);
// cache time in seconds
$cache_time = 5 * 60; // 5 mins
$time = floor(time() / $cache_time) * $cache_time;
// Getting headers sent by the client.
$headers = apache_request_headers();
@eugeneglova
eugeneglova / index.js
Last active August 29, 2015 14:10
Check for correct brackets in string
function check(s) {
var i = 0, l;
s = s.replace(/[^\{\}\(\)\[\]]/g, "");
l = s.length;
if ( ! l) return true;
if (l % 2 !== 0) return false;
(function() {
"use strict";
var loaded_css_urls = [];
function getFontById(fonts, id) {
var found_font;
fonts.some(function(font) {
if (font.id === id) {