Skip to content

Instantly share code, notes, and snippets.

View ram0973's full-sized avatar
:octocat:
Thinking

ram0973 ram0973

:octocat:
Thinking
View GitHub Profile
@ram0973
ram0973 / Main.java
Last active March 14, 2021 09:48
Java Mockito example
// Let's consider an example. UsdConverter class is responsible for converting local currency to USD (United States dollar).
// The test should check the behavior of the tested unit in isolation from its dependencies.
// As the exchange rate varies with time, UsdConverter uses ExchangeRateService to get the latest updates.
// Moreover, getUsd method of a live ExchangeRateService can send a request over HTTP to get the actual exchange rate,
// which is difficult to reproduce in the test environment.
// Mockito allows us to avoid those difficulties and provides an API for creating empty objects and managing behavior.
// Note: here we use BigDecimal since financial transactions need high accuracy:
public class UsdConverter {
@ram0973
ram0973 / Words.java
Created February 25, 2021 09:18
Java count most 10 frequent words in text
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.function.Function.identity;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
@ram0973
ram0973 / hell.java
Created February 21, 2021 09:02
Фабрика фабрик
class TestDrive {
public static void main(String[] args) throws InterruptedException {
BurgerStore mcDonalds = new McDonStore();
BurgerStore burgerKing = new BurgerKingStore();
Burger burger;
System.out.println("-Hello, one McDonalds style cheeseburger");
System.out.println("-Okay! Please wait for a sec, -Calling to the McDonaldsStore. -Cheeseburger");
burger = mcDonalds.orderBurger(Burger.CHEESE);
@ram0973
ram0973 / deleteDirRecursively.java
Created January 31, 2021 11:20
deleteDirRecursively in Java
public void deleteDirRecursively(File dir) {
File[] children = dir.listFiles();
for (File child : children) {
if (child.isDirectory()) {
deleteDirRecursively(child);
} else {
child.delete();
}
}
@ram0973
ram0973 / Main.java
Created January 31, 2021 11:12
Deepest file or directory
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
Path longestPath = Files.walk(Paths.get("D:\\Downloads\\basedir"))
.max(Comparator.comparingInt(Path::getNameCount)).orElseThrow(NullPointerException::new);
@ram0973
ram0973 / Main.java
Last active March 8, 2021 21:41
Как получить список живых нитей из группы ThreadGroup? Как получить список мертвых нитей из группы ThreadGroup?
package com.examples;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Main {
public static List<Thread> threads = new ArrayList<>();
public static void main(String[] args) throws InterruptedException {
Random random = new Random();
@ram0973
ram0973 / a-infinality-w10-config.sh
Created May 18, 2020 15:32 — forked from sorenvonsarvort/a-infinality-w10-config.sh
Windows 10-like font rendering config for Linux
# make sure You have installed the infinality patches
export INFINALITY_FT_FILTER_PARAMS="8 17 50 17 8"
export INFINALITY_FT_GRAYSCALE_FILTER_STRENGTH="0"
export INFINALITY_FT_FRINGE_FILTER_STRENGTH="55"
export INFINALITY_FT_AUTOHINT_HORIZONTAL_STEM_DARKEN_STRENGTH="0"
export INFINALITY_FT_AUTOHINT_VERTICAL_STEM_DARKEN_STRENGTH="0"
export INFINALITY_FT_WINDOWS_STYLE_SHARPENING_STRENGTH="20"
export INFINALITY_FT_CHROMEOS_STYLE_SHARPENING_STRENGTH="0"
export INFINALITY_FT_STEM_ALIGNMENT_STRENGTH="0"
@ram0973
ram0973 / fix-wsl2-dns-resolution
Created April 20, 2020 06:53 — forked from coltenkrauter/fix-wsl2-dns-resolution
Fix DNS resolution in WSL2
1. Create a file: /etc/wsl.conf.
2. Put the following lines in the file in order to ensure the your DNS changes do not get blown away
[network]
generateResolvConf = false
3. In a cmd window, run wsl --shutdown
4. Restart WSL2
5. Create a file: /etc/resolv.conf. If it exists, replace existing one with this new file.
6. Put the following line in the file
@ram0973
ram0973 / java
Last active March 31, 2020 18:53
Java multiplication table
public class Solution {
public static void main(String[] args) {
for (int x = 2; x <= 6; x += 4) {
for (int y = 1; y <= 9; y++) {
for (int z = x; z <= x + 3; z++) {
System.out.print(String.format("%d * %d = %-2d ", z, y, y * z));
}
System.out.println();
}
System.out.println();
<div class="container">
<div class="score">
score: <span class="score_val">0</span>
</div>
<div class="canvas-wrapper">
<canvas width="400" height="400"></canvas>
</div>
<div class="controls">
<button class="btn-start">Start</button>
<button class="btn-pause">Pause</button>