Skip to content

Instantly share code, notes, and snippets.

View ostapenko-me's full-sized avatar
👋

Anatoly Ostapenko ostapenko-me

👋
View GitHub Profile
@ostapenko-me
ostapenko-me / button.component.ts
Created June 11, 2020 13:50
Проверка на непустой this.props.children — Angular edition
import {
AfterContentInit,
AfterViewInit,
ChangeDetectorRef,
Component,
ElementRef,
Input,
OnInit,
QueryList,
ViewChild,
@ostapenko-me
ostapenko-me / highlight.component.ts
Created June 10, 2020 20:54
XSS-safe highlight component in Angular
import { Component, ElementRef, Inject, Input, OnInit } from '@angular/core';
import { DOCUMENT } from '@angular/common';
type ILocalOccurrences = Array<[number, number]>;
@Component({
selector: 'ui-highlight',
template: '',
})
export class HighlightComponent implements OnInit {
@ostapenko-me
ostapenko-me / feast.d.ts
Created March 27, 2017 19:29
Feast typescript declaration files
declare namespace Feast {
interface Block {
extend: (props: any) => Block;
get: (prop: string) => any;
set: (prop: string, value: any) => void;
}
interface Feast {
Block: Block
}
@ostapenko-me
ostapenko-me / class_decorator.ts
Created March 26, 2017 10:53 — forked from remojansen/class_decorator.ts
TypeScript Decorators Examples
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
}
try {
...
} catch (TypeError) {
console.log('Не массив');
}

Hi, @christian-bromann

const assert = require('assert');
const d = {
I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000, IV: 4, IX: 9, XL: 40, XC: 90, CD: 400, CM: 900
};
const f = i => eval(i.replace(/(I(V|X)?|X(L|C)?|C(D|M)?|V|L|D|M)/ig, l => '+' + d[l]));
assert.equal(f('I'), 1, 'I=' + f('I'));
assert.equal(f('XI'), 11, 'XI=' + f('XI'));
@ostapenko-me
ostapenko-me / fromRoman-one-line.js
Last active February 25, 2017 11:03
One line JavaScript fromRoman function
const assert = require('assert');
const numbersDict = {
I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000
};
const fromRoman = input => [...input.toUpperCase()].reduce((number, letter, i, source) => number + (numbersDict[letter] >= ( numbersDict[source[i + 1]] | 0)) ? numbersDict[letter] : -numbersDict[letter], 0);
assert.equal(fromRoman('I'), 1, 'I=' + fromRoman('I'));
assert.equal(fromRoman('XI'), 11, 'XI=' + fromRoman('XI'));
// https://github.com/jshttp/mime-types
const sexyMap = {
'js' : 'application/javascript',
'css' : 'text/css'
}
const contentType = url => sexyMap[url.split('.').pop()] || 'text/plain';
console.log([
@ostapenko-me
ostapenko-me / js-task-1.md
Created February 4, 2017 08:34 — forked from codedokode/js-task-1.md
Задания на яваскрипт (простые)