Skip to content

Instantly share code, notes, and snippets.

View paveleremin's full-sized avatar

Pavel Eremin paveleremin

View GitHub Profile
@paveleremin
paveleremin / doomsday.js
Created January 9, 2019 17:17
Google Solar Doomsday
function sum(arr) {
return arr.reduce((sum, n) => sum + n, 0);
}
function answer(initArea) {
var list = [];
var area = initArea;
var i = 1;
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);
}, []);
}
window.getByXpath = function() {};
document.getByXpath = function() {};
getByXpath = function() {};
alert(123);
alert(typeof getByXpath);
!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 February 24, 2017 06:45
Cisco AnyConnect: save password
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}"
@paveleremin
paveleremin / chunk.js
Created November 4, 2015 17:19
Array chunk
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 September 3, 2016 20:24
Siteimprove test
'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 October 13, 2015 10:16
Array shuffle, without creating new array
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 September 10, 2015 09:29
Count lucky tickets regarding max length
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 August 29, 2015 14:25
Implement array_reverse() without creating new array and usage of array_pop() array_shift()
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]))