Skip to content

Instantly share code, notes, and snippets.

View ashikuzzaman-ar's full-sized avatar

Md Ashikuzzaman ashikuzzaman-ar

View GitHub Profile
@ashikuzzaman-ar
ashikuzzaman-ar / BlockingCallsInReactiveStreams.java
Created February 15, 2022 07:02
What if you have no choice to call some blocking codebase from a legacy library or some legacy system. This is a way arround for the problem. Though this is not reactive but at least it's non blocking.
@Test
void callingBlockingCodeInReactiveStreams() {
Mono.fromCallable(() -> {
// Your blocking code here
return new Object();
}).subscribeOn(Schedulers.boundedElastic());
Flux.fromIterable(Stream.of(1, 2, 3, 4, 5).map(i -> {
// Your blocking code here
return new Object();
import java.io.Serializable;
/**
* URL: https://leetcode.com/problems/valid-palindrome/
*/
public class ValidPalindrome implements Serializable {
public boolean isPalindrome1(String s) {
s = s.trim().replaceAll("\\W", "").replaceAll("_", "").toLowerCase();
int length = s.length();
@ashikuzzaman-ar
ashikuzzaman-ar / DiagonalEncoderDecoder.java
Last active September 2, 2021 08:26
Encrypt text in array diagonal and decrypt diagonally encrypted string to the original text.
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
public class DiagonalEncoderDecoder {
/**
* String = "my name is"
@ashikuzzaman-ar
ashikuzzaman-ar / Solution.java
Created April 11, 2021 06:30
Question: you have an array of integers and an array of sort order. You have to sort input array according to that sort order. Those numbers don't belongs to order list will sort ascending order and will add at the last of the result. Example: Input: [2, 3, 8, 4, 3, 5, 2, 7, 6, 2, 3, 5, 4, 1] Order: [5, 2, 3] Output: [5, 5, 2, 2, 2, 3, 3, 3, 1, …
/*
Question: you have an array of integers and an array of sort order. You have to sort input array according
to that sort order. Those numbers don't belongs to order list will sort ascending order and will add at
the last of the result.
Example:
Input: [2, 3, 8, 4, 3, 5, 2, 7, 6, 2, 3, 5, 4, 1]
Order: [5, 2, 3]
Output: [5, 5, 2, 2, 2, 3, 3, 3, 1, 4, 4, 6, 7, 8]
*/
import java.util.ArrayList;
@ashikuzzaman-ar
ashikuzzaman-ar / Solution.java
Last active April 11, 2021 06:31
Question: you have an array of string and you have to sort them according to their size. Example: Input: ["ab", "a", "abc", "z", "abcd", "mp"]; Output: ["a", "z", "ab", "mp", "abc", "abcd"]
/*
Question: you have an array of string and you have to sort them according to their size.
Example:
Input: ["ab", "a", "abc", "z", "abcd", "mp"];
Output: ["a", "z", "ab", "mp", "abc", "abcd"]
*/
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@ashikuzzaman-ar
ashikuzzaman-ar / PolymorphicMethodOverloading.java
Last active April 5, 2021 16:11
Method overloading with polymorphic instances
public class PolymorphicMethodOverloading {
public static void main(String[] args) {
Consumer consumer = new Consumer();
Parent p1 = new Parent();
Parent p2 = new Child1();
Parent p3 = new Child2();
Child1 p4 = new Child1();
Child2 p5 = new Child2();
@ashikuzzaman-ar
ashikuzzaman-ar / Main.java
Last active April 20, 2019 07:38
different style of adding two time in hour minute and second format
import java.util.Scanner;
/**
* @author ashik
*
*/
public class Main {
/**
* @param args
package com.studevs.example.test.core;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Please type your name: ");
@ashikuzzaman-ar
ashikuzzaman-ar / Main.java
Created November 10, 2017 21:04
Downloading a file from remote server
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) throws IOException {
@ashikuzzaman-ar
ashikuzzaman-ar / Main.java
Last active November 10, 2017 21:07
Downloading a file from internate
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
String from = "https://download.gimp.org/mirror/pub/gimp/v2.8/gimp-2.8.10.tar.bz2";