Skip to content

Instantly share code, notes, and snippets.

View Edgar-P-yan's full-sized avatar
😏
it's happening

Edgar Pogosyan Edgar-P-yan

😏
it's happening
View GitHub Profile
@Edgar-P-yan
Edgar-P-yan / dynamic-multi-reader.go
Created February 17, 2023 15:10
DynamicMultiReader - a dynamic version of golangs standard io.MultiReader
package dynamicmultireader
import "io"
var EOF = io.EOF
type dynamicMultiReader struct {
currentReader io.Reader
newReaderFactory NewReaderFactory
closeHandler CloseHandler
@Edgar-P-yan
Edgar-P-yan / escape-postgresql-like-operator.js
Last active June 29, 2022 19:59
[Node.js] Escape function for PostgreSQL LIKE/ILIKE operator
/**
* Escapes pattern-characters of LIKE and ILIKE operators.
*
* @example
* query('SELECT * FROM articles WHERE title LIKE $1', [ '%' + escapePostgresLikeOperator(searchString) + '%' ])
*
* @param input {string} string to escape
*
* @returns {string} the string to use in LIKE/ILIKE clause
*/
@Edgar-P-yan
Edgar-P-yan / example-of-using-headers-with-validation-decorator.ts
Created March 7, 2021 00:27
[Nest.js] Decorator for validating headers with ValidationPipe, class-validator and class-transformer
// get-books-headers.dto.ts
import { Contains } from 'class-validator';
class GetBooksHeadersDto {
@Contains('en')
'accept-language': string;
}
// books.controller.ts
import { HeadersWithValidation } from './headers-with-validation.decorator.ts'
#include <stdio.h>
int main()
{
int a, b, c, d;
int count = scanf("%d %d", &c, &d);
b = (c + d) / 2;
a = c - b;
printf("%d %d", a, b);
return 0;
const { promisify } = require('util');
const fs = require('fs');
const path = require('path');
const readDir = promisify(fs.readdir);
const lstat = promisify(fs.lstat);
async function traverseDir(dir, first) {
// рекурсивный перебор файлов
const files = await readDir(dir);
@Edgar-P-yan
Edgar-P-yan / contiguous-array-with-the-same-degree.js
Created May 5, 2019 15:13
Contiguous array with the same degree
function alg(arr) {
const maxFreqNum = findMaxFreqNum(arr)
const firstIndex = arr.indexOf(maxFreqNum)
const lastIndex = arr.lastIndexOf(maxFreqNum)
const contiguousArr = arr.slice(firstIndex, lastIndex+1)
return contiguousArr.length
}