Skip to content

Instantly share code, notes, and snippets.

View samoshkin's full-sized avatar

Alexey Samoshkin samoshkin

View GitHub Profile
type Operator<TSource, TTarget> = (source: Observable<TSource>) => Observable<TTarget>;
function pipe(this: Observable<any>, ...operators: Operator<any, any>[]): Observable<any> {
return operators.reduce((acc, curr) => curr(acc), this);
}
// replace native pipe() method
Observable.prototype.pipe = pipe;
function map<TSource, TTarget>(transform: (TSource) => TTarget): Operator<TSource, TTarget> {
@samoshkin
samoshkin / async_generator_to_observable.ts
Created March 1, 2020 18:37
Create Observable from async generator
this.obs = createFrom(async function *() {
await delay(1000);
yield 1;
yield 2;
await delay(500);
await delay(300);
yield 3;
await delay(400);
yield 4;
yield 5;
@samoshkin
samoshkin / text_vs_binary_protocols.md
Last active February 16, 2024 02:16
Comparison of text and binary protocols

Text protocols

In plain text protocols, the bit stream is organised as a sequence of characters or text strings, e.g. Unicode or ASCII. So the two computers are exchanging textual messages. Example: number 20020 is represented by five characters (5 bytes).

Pros and cons:

  • interoperability between multiple platforms and runtimes that adhere to open and well-known standards: JSON, XML.
  • results in larger size messages
  • can be easily, inspected, read, debugged
@samoshkin
samoshkin / tech_lead_role.md
Last active May 14, 2025 08:26
Tech Lead role and responsibilities

What I mean by "Tech Lead" role and responsibilities

  1. It's the person who is responsible for the technical quality of the project. For example, the Team agrees to adhere to a particular level of quality (e.g no linter errors, no failing tests, naming conventions, Git branching model, release cycles, modular structure, software design practices and principles). The Tech Lead is the person who detects violations of our quality policy, communicates it to team members, and explains what should be improved.

  2. Tech Lead has a high-level vision of the project architecture, and also aware of low-level details and nuances, by being involved in everyday development activities.

  3. Tech lead spends 80% of his time in development activities. Otherwise, he will lose the technical feeling of the project, and become a "Сферический конь в вакууме". In the same way, Tech Lead is not limited only to tech debt or infrastructure-related tasks, he works on regular product

@samoshkin
samoshkin / conditional_rendering_in_react.jsx
Created August 20, 2021 18:17
Conditional rendering in React and JSX
import React, { useCallback } from "react";
import { createEventPageUrl } from "app/packages/error-handling";
function ErrorBoundaryFallback(props) {
const { error, componentStack, resetError, eventId } = props;
const renderEventId = useCallback(eventId => (
<a href="createEventPageUrl(eventId))">{eventId}</a>
), []);
@samoshkin
samoshkin / conditionally_build_array_using_logical_and_operator_1.js
Created August 20, 2021 18:44
Conditionally build array using logical AND operator
const deployment = {
debug: process.env.NODE_ENV === 'development',
};
const defaultIntegrations = integrations.filter(x => x.name !== 'Dedupe');
return [
// add all the default integrations but those which were excluded using spread syntax
...defaultIntegrations,
@samoshkin
samoshkin / conditionally_build_array_using_if_else_blocks.js
Created August 20, 2021 19:05
Conditionally build an array using if..else blocks
const deployment = {
debug: process.env.NODE_ENV === 'development',
};
const defaultIntegrations = integrations.filter(x => x.name !== 'Dedupe');
const integrations = [
// add all the default integrations but those which were excluded using spread syntax
...defaultIntegrations,
@samoshkin
samoshkin / jira_ticket_status_diagram_in_mermaid.mmd
Created August 28, 2021 06:30
JIRA ticket state diagram written in Mermaid DSL
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@samoshkin
samoshkin / index.js
Created November 4, 2021 08:58
Process items from Iterable in parallel with given concurrency factor
async function eachParallel(iterable, action, concurrencyFactor) {
const evt = new EventEmitter();
let runningCount = 0;
let cancelled = false;
const errors = new Map();
let ended = false;
const emit = evt.emit.bind(evt);
const on = evt.on.bind(evt);
const until = eventName => new Promise(res => evt.once(eventName, res));
@samoshkin
samoshkin / app.js
Created November 14, 2022 21:34
Node application entry point and runner based on "redux-saga" library
const Sentry = require('@sentry/node');
const {
fork,
} = require('redux-saga/effects');
async function init() {
// create any services and run all startup activites (e.g start HTTP server, connect to Db, etc)
const dbConn = await mongoDb.connect(config.services.mongo);
Basic.db = dbConn;