Skip to content

Instantly share code, notes, and snippets.

Avatar

Pavel Eremin paveleremin

View GitHub Profile
@paveleremin
paveleremin / doomsday.js
Created Jan 9, 2019
Google Solar Doomsday
View doomsday.js
function sum(arr) {
return arr.reduce((sum, n) => sum + n, 0);
}
function answer(initArea) {
var list = [];
var area = initArea;
var i = 1;
View Create flat array
function equals(arr1, arr2) {
return JSON.stringify(arr1) === JSON.stringify(arr2);
}
function flatten(arr) {
return arr.reduce((result, toFlatten) => {
return result.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
View gist:6b12a5d90199ebd53fd587e281e38739
window.getByXpath = function() {};
document.getByXpath = function() {};
getByXpath = function() {};
alert(123);
alert(typeof getByXpath);
View babel-polyfill
!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var c="function"==typeof require&&require;if(!u&&c)return c(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var a=n[o]={exports:{}};t[o][0].call(a.exports,function(n){var r=t[o][1][n];return s(r?r:n)},a,a.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(t,n,r){(function(n){"use strict";function define(t,n,e){t[n]||Object[r](t,n,{writable:!0,configurable:!0,value:e})}if(t(295),t(296),t(2),n._babelPolyfill)throw new Error("only one instance of babel-polyfill is allowed");n._babelPolyfill=!0;var r="defineProperty";define(String.prototype,"padLeft","".padStart),define(String.prototype,"padRight","".padEnd),"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(functi
@paveleremin
paveleremin / Cisco.vbs
Created Feb 24, 2017
Cisco AnyConnect: save password
View Cisco.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """%PROGRAMFILES(x86)%\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"""
WScript.Sleep 1500
WshShell.AppActivate "Cisco AnyConnect Secure Mobility Client"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
View chunk.js
Array.prototype.chunk = function(len) {
var chunks = [];
for (var i = 0, l = this.length; i < l; i += len) {
chunks.push(this.slice(i, i + len));
}
return chunks;
};
@paveleremin
paveleremin / index.js
Last active Sep 3, 2016
Siteimprove test
View index.js
'strict mode';
/**
* > You choose programming language, any external libraries
* > and strategi for implementation.
* > You should build a solution from scratch.
*
* I chose Javascript that work on a server (NodeJS)
*/
@paveleremin
paveleremin / gist:f3ad1f6ec22447e8ce47
Created Oct 13, 2015
Array shuffle, without creating new array
View gist:f3ad1f6ec22447e8ce47
var array = [1, 2, 3, 4, 5, 6];
Array.prototype.shuffle = function() {
var i = this.length,
tmp,
randIndex;
while (--i) {
randIndex = Math.floor(i * Math.random());
tmp = this[i];
this[i] = this[randIndex];
@paveleremin
paveleremin / tickets.js
Last active Sep 10, 2015
Count lucky tickets regarding max length
View tickets.js
var Tickets = function(maxLen){
if (maxLen % 2) {
throw Error('Max length must be even: 2, 4, 6, ...');
}
this.maxLen = parseInt((new Array(maxLen / 2 + 1)).join(9));
};
Tickets.prototype.count = function(num, undefined){
var digits = {},
i,
tmp;
@paveleremin
paveleremin / array_reverse
Last active Aug 29, 2015
Implement array_reverse() without creating new array and usage of array_pop() array_shift()
View array_reverse
function array_reverse($arr) {
$length = count($arr);
for ($i=0; $i < $length/2; $i++) {
$tmp = $arr[$i];
$arr[$i] = $arr[$length - 1 - $i];
$arr[$length - 1 - $i] = $tmp;
}
}
var_dump(array_reverse([1,2,3,4,5]))