Skip to content

Instantly share code, notes, and snippets.

View bassemZohdy's full-sized avatar

Bassem Reda Zohdy bassemZohdy

View GitHub Profile
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
public class RetryRunnable implements Runnable {
private final long sleep;
private final Runnable r;
private final int times;
private final Predicate<Throwable> p;
private BiConsumer<Integer, Throwable> log;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
public class StringToCharSequences implements Function<String, CharSequence[]> {
final private char delimiter;
public StringToCharSequences(char delimiter) {
this.delimiter = delimiter;
import java.util.function.Function;
public class BytesConvertUtils {
public static final Function<Integer, byte[]> intToBytes = l -> {
int count = Integer.BYTES;
return new byte[] { (byte) ((l >> 8 * --count) & 0xFF),
(byte) ((l >> 8 * --count) & 0xFF),
(byte) ((l >> 8 * --count) & 0xFF),
(byte) ((l >> 8 * --count) & 0xFF) };
};
import static java.lang.Thread.currentThread;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedBlockingQueue;
@bassemZohdy
bassemZohdy / ScriptValidator.java
Created September 13, 2016 17:36
ScriptValidator validate java object with javascript
import java.util.function.Predicate;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class ScriptValidator implements Predicate<Object> {
private final ScriptEngine engine;
private final String functionName;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.IntStream;
public class StreamSample {
#/bin/bash
# if sudo not required
# find . -name *.sh 2>>/dev/null| xargs chmod +x
find . -name *.sh 2>>/dev/null| xargs sudo chmod +x
# to verify
# find . -name *.sh -ls 2>>/dev/null
# OR
# find . -name *.sh 2>>/dev/null| xargs ls -l
#!/bin/bash
set -e
set -x
MAP_FILE='./map'
DELIMITER=","
add (){
KEY=$1
VALUE=$2
echo Key=$KEY Value=$VALUE
#!/usr/bin/env bash
set -e
#set -x
arrayContains(){
ARRAY=($1);
ITEM=$2;
if echo "${ARRAY[*]}" | grep -E -q " $ITEM |^$ITEM | $ITEM\$" ;
then
echo true;
else
FROM alpine
LABEL maintainer="[email protected]"
ARG JAVA_VERSION=8
ENV LANG C.UTF-8
ENV JAVA_HOME /usr/lib/jvm/default-jvm
ENV PATH $PATH:/usr/lib/jvm/default-jvm/jre/bin:/usr/lib/jvm/default-jvm/bin
RUN apk update --no-cache && apk add --no-cache bash openjdk$JAVA_VERSION
ADD https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/2.0.0.BUILD-SNAPSHOT/spring-boot-cli-2.0.0.BUILD-20171013.160946-30-bin.tar.gz /opt/spring/
WORKDIR /opt/spring/
RUN tar xvf spring-boot-cli-2.0.0.BUILD-20171013.160946-30-bin.tar.gz