Skip to content

Instantly share code, notes, and snippets.

View klesogor's full-sized avatar

Kyrylo Lesohorskyi klesogor

View GitHub Profile
@klesogor
klesogor / academy_coin.java
Last active May 11, 2021 07:29
2021 BSA Java HW#1 algo tasks solutions
package com.binary_studio.academy_coin;
import java.util.stream.Stream;
public final class AcademyCoin {
private AcademyCoin() {
}
static class AcademyCoinAccumulator {
@klesogor
klesogor / Description.md
Created February 19, 2021 14:03
Why You Should Not Do Service Interfaces

In this example we will see why you should not declare interface for service and then implement it.

Generaly service composition is a bad idea because:

  • Services are generaly effectfull, but effects are not part of their methods' signatures, so it's hard to predict what would happen if you call it;
  • Composing services can lead to circular dependencies, which are resolvable only in runtime(happens more often than you think).

Now to declaring interfaces itself. Primary reason why we create interfaces is dependency inversion, we want to change the direction of dependency to decrease coupling. In this example we want to invert dependency from ServiceBImpl to ServiceA. Let's see what happens when we introduce interface ServiceA:

  • ServiceA contains ALL methods of ServiceAImpl. Any change to ServiceAImpl contract will be reflected in ServiceA and vice versa.
  • ServiceBImpl uses ONLY doFoo method of ServiceA. But if we want to mock it we have to mock two more unused method.
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define NAMEDPIPE_NAME_IN "/tmp/my_named_pipe_in"
#define NAMEDPIPE_NAME_OUT "/tmp/my_named_pipe_out"
#define BUFSIZE 256
@klesogor
klesogor / conditional_variable.cpp
Created November 15, 2020 11:07
Cpp concurrency
#include <iostream>
#include <thread>
#include <mutex>
#include <list>
#include <condition_variable>
using namespace std;
class FooBazBar{
private:
void routineLoop(const char* word){
@klesogor
klesogor / ExecutorServiceExample.java
Created July 13, 2020 07:28
Java concurrency examples
package JavaConcurrency;
import java.util.concurrent.*;
public class ExecutorServiceExample {
public static void main(String[] args) throws ExecutionException, InterruptedException {
var executor = new ThreadPoolExecutor(5, 10, 0, TimeUnit.SECONDS, new LinkedBlockingDeque<>());
// executor.submit(() -> {
// try {
// Thread.sleep(100);
@klesogor
klesogor / ExecutorServiceExample.java
Created July 13, 2020 07:25
Java concurrency examples
package JavaConcurrency;
import java.util.concurrent.*;
public class ExecutorServiceExample {
public static void main(String[] args) throws ExecutionException, InterruptedException {
var executor = new ThreadPoolExecutor(5, 10, 0, TimeUnit.SECONDS, new LinkedBlockingDeque<>());
// executor.submit(() -> {
// try {
// Thread.sleep(100);
@klesogor
klesogor / DHasher.java
Last active July 14, 2020 14:34
BSA-java-concurrency dHash algo impl
package bsa.java.concurrency.image.service;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
public class DHasher{
public long calculateHash(byte[] image) {

Modern Java

Welcome to Java world

Java is a general-purpose programming language that is class-based, object-oriented, and designed to have as few implementation dependencies as possible. It is intended to let application developers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture.

Ява? Это когда вместо «Кобол наносит ответный удар» пишут «удар.нанестиОтвет (новый Кобол ())» — вот это Ява.