Skip to content

Instantly share code, notes, and snippets.

@serhii-lypko
serhii-lypko / visitor_pattern.java
Last active September 27, 2025 12:19
Visitor pattern
/*
* We want to be able to define new operations without having to add a new method
* to each class every time.
*
* The Visitor pattern lets you execute an operation over a set of objects with
* different classes by having a visitor object implement several variants of
* the same operation, which correspond to all target classes.
*/
abstract class Figure {
/*
|--
|--
|--
|--
|--
|--
|--
import 'dart:io';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:rxdart/rxdart.dart';
import 'package:green_way/shared/utils.dart';
import 'package:green_way/shared/constants.dart';
class FilesLoaderRepository {
@serhii-lypko
serhii-lypko / index.ts
Last active September 2, 2024 13:48
Find pivot of sorted rotated array with binary search
/// Using binary search
// [6, 7, 8, 9, 11, 13, 15, 0, 1, 2]
function findPivot(nums) {
let l = 0;
let r = nums.length - 1;
if (nums[l] < nums[r]) return 0;
function fourSum(nums: number[], target: number) {
nums.sort((a, b) => a - b);
let res: any = [], quad: any = [];
// NOTE: better to use inner func since it has access to nums
const kSum = (k, start, target) => {
if (k != 2) {
for (let i = start; i < nums.length - k + 1; i++) {
if (i > start && nums[i - 1] == nums[i]) continue;
@serhii-lypko
serhii-lypko / go_router_example.dart
Created April 25, 2024 18:15 — forked from onatcipli/go_router_example.dart
go_router_example.dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
main() {
CustomNavigationHelper.instance;
runApp(const App());
}
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@serhii-lypko
serhii-lypko / assessments_1.py
Last active September 22, 2023 00:22
Python assessments #1
# Task 1.
# Find the arithmetic mean of the list
# 1.a -> find the sum of list
# 1.b -> divide sum by list len
# 1.c -> print result
#
# list = [13, 9, 14, 8, 100, 212, 57]
# expected result: 59
@serhii-lypko
serhii-lypko / js_async_generators.js
Last active October 30, 2022 15:04
Async non-blocking generators
(function() {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function* infiniteProcessing() {
while (true) {
await sleep(3000);
yield Math.random();
}
@serhii-lypko
serhii-lypko / how_browser_works.txt
Last active August 30, 2021 10:07
How browser works
* * * * * * * * * * * * Rendering Engine * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1. Constructing the DOM Tree
2. Constructing the CSSOM Tree
type Foo<T> = T extends { a: infer U, b: infer U } ? U : never;
type T10 = Foo<{ a: string, b: string }>; // string
type T11 = Foo<{ a: string, b: number }>; // string | number
type T22 = Foo<{ a: string }>; // never
/* * . * . * . * Type Systems vs Shapes * . * . * . */