This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: " + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
google = { | |
source = "hashicorp/google" | |
version = "4.14.0" | |
} | |
} | |
} | |
provider "google" { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var i = 0; | |
var count = document.querySelectorAll( | |
"ytd-channel-renderer:not(.ytd-item-section-renderer)" | |
); | |
myTimer(); | |
function myTimer() { | |
if (count == 0) return; | |
el = document.querySelector(".ytd-subscribe-button-renderer"); | |
el.click(); | |
setTimeout(function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# This is a comment for illustrating a YAML file | |
name: Vivek Naskar | |
designation: "Software Developer" | |
age: 29 | |
company: Google | |
frameworks: | |
- Spring Boot | |
- Django | |
- nodeJs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
/** | |
* Preventing the breaking of SingletonPattern due to Deserialization | |
* by implementing readResolve() to return the current instance | |
*/ | |
public class SingletonDeserializationPreventExample implements Serializable { | |
private static SingletonDeserializationPreventExample single_instance = null; |