S

@supriyo_biswas

ThreadPoolExecutor example

Python
3 years ago
from concurrent.futures import ThreadPoolExecutor class A: def p(self): print("hello") def foo(value, a): print(value) a.p()

Matplotlib bar color demo

Python
3 years ago
# https://matplotlib.org/stable/gallery/lines_bars_and_markers/bar_colors.html#sphx-glr-gallery-lines-bars-and-markers-bar-colors-py import matplotlib.pyplot as plt fig, ax = plt.subplots() fruits = ['apple', 'blueberry', 'cherry', 'orange'] counts = [40, 100, 30, 55] bar_labels = ['red', 'blue', '_red', 'orange'] bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']

Usage of concurrent.futures

Python
3 years ago
from concurrent.futures import ThreadPoolExecutor def func1(): return "result1" def func2(): return "result2" with ThreadPoolExecutor() as executor: future1 = executor.submit(func1)

Passing an array to a variadic parameter

Java
3 years ago
import java.util.*; import java.lang.*; import java.io.*; class Main { public static void foo(int... a) { for (int i = 0; i < a.length; i++) { System.out.println(i); } }

Sum elements of a map using the Stream API

Java
3 years ago
import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main(String[] args) { Map<String, Integer> bill = Map.of("Sugar", 100, "Potato", 50, "Rice", 200); int total = bill.entrySet().stream() .map(x -> x.getValue()) .reduce(0, (acc, x) -> acc + x);

Queue interface - add/offer/remove methods

Java
3 years ago
import java.util.*; import java.util.concurrent.*; import java.util.stream.*; class Main { public static void main(String[] args) { Queue<Integer> queue = IntStream.rangeClosed(1, 5) .boxed() .collect(Collectors.toCollection(LinkedList::new));

Find the employees who are receiving the same salary

SQL
3 years ago
create table employees ( name varchar(30) not null, salary int not null ); insert into employees values ('Ram', 1000), ('Ankita', 4000), ('Ganesh', 3000), ('Yuvraj', 3000),

Print duplicate elements using the stream API

Java
3 years ago
import java.util.*; class Main { public static void main(String[] args) { List<Integer> list = Arrays.asList(1, 8, 4, 3, 2, 2, 4, 6, 1, 7, 1); HashMap<Integer, Boolean> s = new HashMap<>(); list.stream().forEach(x -> { Boolean b = s.get(x); if (b == null) {

Find the employees with the second highest salary

SQL
3 years ago
create table employees ( name varchar(30) not null, salary int not null ); insert into employees values ('Ram', 1000), ('Ankita', 4000), ('Ganesh', 3000), ('Yuvraj', 3000),

PriorityQueue (heap)

Java
3 years ago
import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main(String[] args) { PriorityQueue<Integer> minHeap = new PriorityQueue<>(); minHeap.add(60); minHeap.add(10); minHeap.add(50);

Java Streams

Java
3 years ago
import java.util.*; import java.util.stream.*; class Main { public static void main(String[] args) { List<Integer> l = Arrays.asList(1, 2, 3, 4, 5, 6, 10); Integer sum = l.stream().reduce(0, (acc, x) -> acc + x); Optional<Integer> max = l.stream().max(Integer::compare); Optional<Integer> min = l.stream().min(Integer::compare); System.out.println(sum);

Executors and futures in Java

Java
3 years ago
import java.util.concurrent.*; import java.util.*; class MyCallable implements Callable<Integer> { public Integer call() { try { int random = ThreadLocalRandom.current().nextInt(0, 200); Thread.sleep(random); return random; } catch (InterruptedException e) {

Executors and ExecutorService in Java

Java
3 years ago
import java.util.concurrent.*; import java.util.*; class MyRunnable implements Runnable { protected int id; MyRunnable(int id) { this.id = id; }

CyclicBarrier

Java
3 years ago
import java.util.concurrent.*; import java.util.*; class Person implements Runnable { protected String name; protected CyclicBarrier meet; Person(CyclicBarrier meet, String name) { this.name = name; this.meet = meet;

CountdownLatch

Java
3 years ago
import java.util.concurrent.*; import java.util.*; class Animal implements Runnable { protected String name; protected CountDownLatch lives; Animal(CountDownLatch lives, String name) { this.name = name; this.lives = lives;

Semaphores

Java
3 years ago
import java.util.concurrent.*; import java.util.*; class MyRunnable implements Runnable { Semaphore sem; MyRunnable(Semaphore sem) { this.sem = sem; }

Map interface

Java
3 years ago
import java.util.*; import java.lang.*; class Main { public static void main(String[] args) { Map<String,Integer> phone = new HashMap<>(); phone.put("Barack Obama", 111111); phone.put("Donald Trump", 222222); phone.put("Joe Biden", 3333333);

List Interface and comparators in Java

Java
3 years ago
import java.util.*; import java.lang.*; import java.io.*; class DescendingCompare implements Comparator<Integer> { public int compare(Integer a, Integer b) { if (a == b) { return 0; }

Set interface in Java

Java
3 years ago
import java.util.*; import java.util.stream.*; class Main { public static void main(String[] args) { Set<String> s1 = new HashSet<>(); s1.addAll(Arrays.asList("Apple", "Pear", "Orange", "Banana")); // elements can be in any order System.out.println("s1 = " + s1);

StringBuffer methods in Java

Java
3 years ago
import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main(String[] args) { StringBuilder s = new StringBuilder(); System.out.println(s.length()); System.out.println(s.capacity());