This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
class Collection<T> extends Array<T> { | |
// noinspection JSAnnotator | |
public constructor(...args: T[]) { | |
let array = super(...args); | |
Object.setPrototypeOf(array, this.constructor.prototype); | |
return array; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Security { | |
static encrypt(text, password) { | |
password = String(password); | |
return String(text) | |
.split('') | |
.map((char, index) => String.fromCharCode(char.charCodeAt(0) + password.charCodeAt(index % password.length))) | |
.join(''); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare type Dependency = any; | |
declare type DependencyKey = string|number|{new(...args: any[])}; | |
/** | |
* Dependency injection container | |
* | |
* Example: | |
* | |
* // There is a class | |
* class Auth { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Encoder { | |
public static encode(str: string, pass: string): string { | |
let res = ''; | |
let j = 0, jlen = pass.length; | |
str = pass + str; | |
for (let i = 0, ilen = str.length; i < ilen; i++) { | |
let charCode = str.charCodeAt(i), | |
passCode = pass.charCodeAt(j), | |
sumCode = charCode + passCode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let str = 'My Secure String'; | |
let enc = str.split('').map(char => '0x'+char.codePointAt(0).toString(16)).join(' '); | |
let dec = enc.split(' ').map(code => String.fromCodePoint(parseInt(code))).join('') | |
console.log(`Encoded: '${enc}'`); | |
console.log(`'${str}' === '${dec}'`, str === dec); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rhombus(n) { | |
return n < 0 || n % 2 == 0 ? null : | |
[ | |
(n - (n % 2)) / 2, | |
max => Array(max+1).fill(1).map((i, j) => ' '.repeat(max-j) + '*'.repeat(j*2+1)), | |
half => half.concat(half.slice(0, -1).reverse(), '').join('\n') | |
] | |
.reduce((curr, fn) => fn(curr)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li>item 1 | |
<ul> | |
<li>sub-item 1</li> | |
<li>sub-item 2</li> | |
<li>sub-item 3</li> | |
</ul> | |
</li> | |
<li>item 2 | |
<ol> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is helper class for parse server response | |
*/ | |
export class To { | |
public static number(raw: any): number { | |
const n = Number(raw); | |
return raw === undefined || raw === null || isNaN(n) ? null : n; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hasDatabase() { | |
DB_NAME=$1; | |
return $(MYSQL_PWD="${MYSQL_ROOT_PASSWORD}" mysql -u${DB_USER} --skip-column-names --batch -e "SHOW DATABASES LIKE '${DB_NAME}'" | wc -l) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Encoder</title> | |
<script> | |
var numberSystem = +prompt('Введите систему счисления(число от 2 до 36):', '16'); | |
if (numberSystem >= 2 && numberSystem <= 36) { | |
var data = prompt('Введите данные для обработки:'); |