Skip to content

Instantly share code, notes, and snippets.

@yalovek
yalovek / iterate-arrays.js
Last active March 30, 2019 04:42
Iterate arrays
(function(cb, ...params) {
const last = params.length - 1;
const count = params[last] - 1;
function iterate(c, values) {
params[c].forEach(function(item) {
if (c === count) {
cb(...values, item);
} else {
iterate(c + 1, [...values, item]);
@yalovek
yalovek / lucky-ticket.js
Last active March 11, 2019 16:57
Lucky ticket
(function(count){
if (count % 2 !== 0) {
throw Error('Must be even number');
}
const result = {};
const length = count / 2;
const sums = Array.from({length: Math.pow(9, length) / 2});
const nums = Array.from({length: 10});
const go = (l, m, n) => {
@yalovek
yalovek / convertKeyboardKeysCyrillicToLatin.js
Created October 24, 2016 19:58
Convert keyboard keys from cyrillic to latin
/**
* Function for converting keyboard keys from cyrillic to latin
* @param {String} word Word on cyrillic
* @return {String} Word converted to latin
*/
const convertKeyboardKeysCyrillicToLatin = word => {
const keyboardMap = {
'ф': 'a',
'и': 'b',
'c': 'c',
@yalovek
yalovek / convertKeyboardKeysLatinToCyrillic.js
Created October 23, 2016 16:49
Convert keyboard keys from latin to cyrillic
/**
* Function for converting keyboard keys from latin to cyrillic
* @param {String} word Word on latin
* @return {String} Word converted to cyrillic
*/
const convertKeyboardKeysLatinToCyrillic = word => {
const keyboardMap = {
'a': 'ф',
'b': 'и',
'c': 'c',
@yalovek
yalovek / translitLatinToCyrillic.js
Created October 23, 2016 16:26
Translit latin to cyrillic
/**
* Function for translitirating latin to cyrillic
* @param {String} word Word on latin
* @return {String} Word translitirated to cyrillic
*/
const translitLatinToCyrillic = word => {
const translitMap = {
'a': 'а',
'b': 'б',
'c': 'ц',
@yalovek
yalovek / translitCyrillicToLatin.js
Last active October 23, 2016 16:24
Translit cyrillic to latin
/**
* Function for translitirating cyrillic to latin
* @param {String} word Word on cyrillic
* @return {String} Word translitirated to latin
*/
const translitCyrillicToLatin = word => {
const translitMap = {
'а': 'a',
'б': 'b',
'в': 'v',
@yalovek
yalovek / sum.js
Created October 17, 2016 07:03
Calculating sum of numbers sum(2)(3)(4)
function sum(x) {
const f = y => sum(x + y);
f.valueOf = () => x;
return f;
}
@yalovek
yalovek / anagram.js
Last active October 23, 2016 15:24
Function for checking array of words for anagrams
/**
* Function for checking array of words for anagrams
* @param {Array} words Array of words
* @return {Array} Array of arrays with anagram words
*/
const anagram = words => words.reduce((result, word) => {
if (!result[word.length]) {
result[word.length] = [word];
}
else {
@yalovek
yalovek / checkParams.js
Created August 29, 2016 11:07
Check url params for XSS: window.location = 'javascript://a%0aalert%28document.cookie%29'
window.location.search.substr(1).split('&').map(value => {
return value.split('=')[1];
}).filter(value => {
const parser = document.createElement('a');
parser.href = value;
return parser.protocol === "javascript:";
}).length;
#!/usr/bin/env sh
# Install new vim
sudo apt-get build-dep vim
unzip vim-master.zip
cd vim-master
make
sudo make install
hash -r
vim --version