Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexey Samoshkin samoshkin

View GitHub Profile
@samoshkin
samoshkin / index.js
Created Nov 4, 2021
Process items from Iterable in parallel with given concurrency factor
View index.js
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 / jira_ticket_status_diagram_in_mermaid.mmd
Created Aug 28, 2021
JIRA ticket state diagram written in Mermaid DSL
View jira_ticket_status_diagram_in_mermaid.mmd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@samoshkin
samoshkin / conditionally_build_array_using_if_else_blocks.js
Created Aug 20, 2021
Conditionally build an array using if..else blocks
View conditionally_build_array_using_if_else_blocks.js
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 / conditionally_build_array_using_logical_and_operator_1.js
Created Aug 20, 2021
Conditionally build array using logical AND operator
View conditionally_build_array_using_logical_and_operator_1.js
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 / conditional_rendering_in_react.jsx
Created Aug 20, 2021
Conditional rendering in React and JSX
View conditional_rendering_in_react.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 / tech_lead_role.md
Last active Aug 20, 2021
Tech Lead role and responsibilities
View tech_lead_role.md

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 / text_vs_binary_protocols.md
Last active May 15, 2022
Comparison of text and binary protocols
View text_vs_binary_protocols.md

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 / async_generator_to_observable.ts
Created Mar 1, 2020
Create Observable from async generator
View async_generator_to_observable.ts
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;
View observable_operators.ts
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 / prose.md
Created Feb 27, 2020
Angular DI и Forms. О чем вам не расскажут книги.
View prose.md

Например есть такая задача. Есть компонент, и на него же вешается директива.

<input [formControl]="controller.formControl"></input>

где component - в данном случае это родной [formControl] - это директива

Задача директивы это настроить связку между "input.value" (view) и controller.formControl (model) в две стороны: