Skip to content

Instantly share code, notes, and snippets.

View viveknaskar's full-sized avatar
🎯
Focusing

Vivek Naskar viveknaskar

🎯
Focusing
View GitHub Profile
@viveknaskar
viveknaskar / ThenAcceptExample.java
Last active September 20, 2022 22:23
Illustration of thenAccept method chaining for CompletableFuture
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public class ThenAcceptExample {
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture<Void> completableFuture = CompletableFuture.supplyAsync(() -> {
try {
// delaying the thread by 2 seconds
TimeUnit.SECONDS.sleep(2);
@viveknaskar
viveknaskar / ThenApplyChainingExample.java
Created September 20, 2022 21:48
Illustration of thenApply method chaining for CompletableFuture
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public class ThenApplyChainingExample {
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
try { // delaying the thread by 2 seconds
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
@viveknaskar
viveknaskar / ThenApplyExample.java
Last active September 20, 2022 21:39
Simple Illustration of thenApply method for CompletableFuture
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public class ThenApplyExample {
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
try {
// delaying the thread by 2 seconds
TimeUnit.SECONDS.sleep(2);
@viveknaskar
viveknaskar / SupplyAsyncExample.java
Last active September 20, 2022 21:26
Simple Illustration of supplyAsync method for CompletableFuture
import java.util.concurrent.*;
public class SupplyAsyncExample {
public static void main(String[] args) throws ExecutionException, InterruptedException {
// creating an executor to use thread pools to execute tasks
Executor executor = Executors.newFixedThreadPool(3);
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
try {
// fetching the name of the Thread
System.out.println("Executing from: " +
@viveknaskar
viveknaskar / RunAsyncExample.java
Last active September 20, 2022 04:51
Simple Illustration of runAsync method for CompletableFuture
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public class RunAsyncExample {
public static void main(String[] args) throws ExecutionException, InterruptedException {
CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
try {
// delaying the thread by 2 seconds
TimeUnit.SECONDS.sleep(2);
@viveknaskar
viveknaskar / SimpleCompletableFutureExample.java
Created September 18, 2022 15:23
Simplest example of CompletableFuture
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class SimpleCompletableFutureExample {
public static void main(String[] args) {
CompletableFuture<String> completableFuture = new CompletableFuture<>();
try {
// we can get the result using CompletableFuture.get()
@viveknaskar
viveknaskar / vm.tf
Created March 22, 2022 12:30
A sample code snippet for provisioning compute instance in GCP using terraform
resource "google_compute_instance" "default" {
name = "compute_engine"
machine_type = "e2-medium"
zone = "us-central1-a"
boot-disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
@viveknaskar
viveknaskar / main.tf
Created March 22, 2022 12:24
Sample code snippet for terraform block for explain a tf file
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.14.0"
}
}
}
provider "google" {
@viveknaskar
viveknaskar / bootstrap-modal-on-form-submit.markdown
Created August 14, 2019 21:13
Bootstrap Modal on Form Submit
@viveknaskar
viveknaskar / sample.yaml
Last active October 3, 2021 16:45
An illustration of a sample YAML file
---
# This is a comment for illustrating a YAML file
name: Vivek Naskar
designation: "Software Developer"
age: 29
company: Google
frameworks:
- Spring Boot
- Django
- nodeJs