Skip to content

Instantly share code, notes, and snippets.

View mnadeem's full-sized avatar

Nadeem Mohammad mnadeem

View GitHub Profile
@mnadeem
mnadeem / FibonacciStream.java
Created March 13, 2022 15:33 — forked from mtorchiano/FibonacciStream.java
Fibonacci sequence generation using Java Stream API
package streams;
import java.util.stream.LongStream;
import java.util.stream.Stream;
public class FibonacciStream {
public static LongStream fibonacciGG() {
class FibonacciGenerator{
int prev=0;
@mnadeem
mnadeem / Redis HA Master Slave Cluster Kubernetes.yml
Created October 1, 2020 16:27
Redis HA Master Slave Cluster Kubernetes.yml
apiVersion: v1
kind: Template
metadata:
name: ${NAME}
labels:
name: ${NAME}
annotations:
description: Redis master/slave templates based on Statefulsets
parameters:
- name: NAME
int start = 1, end = 10;
List<Integer> primeNumbers = IntStream.range(start, end)
.filter(number -> number > 1 && IntStream.range(2, number).noneMatch(divider -> number % divider == 0))
.boxed().collect(Collectors.toList());
System.out.println(primeNumbers);
Integer sumOfPrimes = IntStream.range(start, end).filter(
number -> number > 1 && IntStream.range(2, number - 1).noneMatch(divider -> number % divider == 0))
.reduce(0, (a, b) -> a + b);
@mnadeem
mnadeem / RestUrl.java
Created August 16, 2017 03:58
Builder Pattern With Fluent Interface
/**
* @author Nadeem Mohammad
*/
public class RestUrl {
private String url;
private RestUrl(String url) {
this.url = url;
}
@mnadeem
mnadeem / pom.xml
Created July 15, 2017 16:02
Add non maven jar in maven way
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.app</groupId>
<artifactId>demo-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<version.maven-install-plugin>2.5.2</version.maven-install-plugin>
<version.non-maven1>1.0.0</version.non-maven1>
@mnadeem
mnadeem / FixdedDelayJobData.java
Created January 18, 2017 06:00
Fixed Delay job data used by FixedDelayJobListener
import java.io.Serializable;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public final class FixdedDelayJobData implements Serializable {
private static final long serialVersionUID = 1L;
private long delay;
private TimeUnit delayUnit;
@mnadeem
mnadeem / FixedDelayJobListener.java
Last active January 18, 2017 10:35
Listener to execute the quartz job with fixed delay
import static org.quartz.TriggerBuilder.newTrigger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
@mnadeem
mnadeem / ScalingThreadPoolExecutor.java
Last active October 27, 2021 21:36
Scalable Thread Pool Executor (TPE) Which first creates threads up to max pool size and then queue up the tasks (Queue Does not depends upon Executor)
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TransferQueue;
public final class ScalingThreadPoolExecutor extends ThreadPoolExecutor {
@mnadeem
mnadeem / ScalableThreadPoolExecutor.java
Last active October 4, 2021 11:58
Salable thread pool executor (TPE) which first creates threads up to maximum pool size then queue up the work (Queue depends upon Executor)
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TransferQueue;
import java.util.concurrent.locks.ReentrantLock;
public final class ScalableThreadPoolExecutor extends ThreadPoolExecutor {
@mnadeem
mnadeem / gpg-list-keys.ps1
Created August 30, 2016 14:21
GPG list keys command
C:\Users\Nadeem>gpg --list-keys
gpg: checking the trustdb
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
C:/Users/Nadeem/AppData/Roaming/gnupg/pubring.kbx
-------------------------------------------------
pub rsa2048 2016-08-29 [SC]
5694AA563793429557F1727835B3BD2A223A
uid [ultimate] Nadeem Mohammad <[email protected]>
sub rsa2048 2016-08-29 [E]