Skip to content

Instantly share code, notes, and snippets.

/**
// work with jboss-eap-6.1
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>2.3.0</version>
</dependency>
*/
import com.auth0.jwt.JWTSigner;
public class ResponseMap<K, V> extends HashMap<K, V> {
private ResponseMap() {
}
public static <K, V> ResponseMap<K, V> of(K k1, V v1) {
ResponseMap<K, V> map = new ResponseMap<K, V>();
map.put(k1, v1);
return map;
@mhewedy
mhewedy / deploy.sh
Last active November 25, 2017 20:44
shell file to deploy web app into tomcat
#!/usr/bin/env bash
# run from the base dir of the maven webapp
# you need to modify the following file in <tomcat_home>/conf/context.xml do:
#
#<Context reloadable="true">
# <Resources allowLinking="true"> </Resources>
TOMCAT_HOME=/home/mhewedy/programs/apache-tomcat-8.5.23
@mhewedy
mhewedy / LocalDateArgumentResolver.java
Created February 26, 2018 22:33
LocalDateArgumentResolver.java
package com.example.dateargsresolver;
import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
@mhewedy
mhewedy / BracketsBalanceChecker.java
Created April 21, 2018 08:34
BracketsBalanceChecker
import java.util.ArrayDeque;
import java.util.Deque;
public class BracketsBalanceChecker {
public static void main(String[] args) {
System.out.println(isBalanced("[()]{}{[()()]()}"));
System.out.println(isBalanced("[(])"));
@mhewedy
mhewedy / BinaryGap.java
Created April 21, 2018 18:26
Codility binary gap solution
private static int gap(int N) {
int max = 0;
int counter = -1;
while (N != 0) {
if ((N & 1) == 1) {
if (counter > max) {
public class TreeHeight {
static class Node {
char data;
Node left, right;
Node(char data) {
this.data = data;
}
@mhewedy
mhewedy / LowestCommonAncestor.java
Last active April 21, 2018 20:34
in tree, find the node that is lowest common ancestor between two nodes O(logn)
public class LowestCommonAncestor {
static class Node {
int data;
Node left, right;
Node(int data) {
this.data = data;
}
@mhewedy
mhewedy / CyclicRotation.java
Last active April 22, 2018 07:50
codality CyclicRotation
import java.util.Arrays;
public class CyclicRotation {
public static void main(String[] args) {
System.out.println(Arrays.toString(shiftBy(new int[]{3, 8, 9, 7, 6}, 3)));
}
private static int[] shiftBy(int[] A, int K) {
@mhewedy
mhewedy / OddOccurrencesInArray.java
Created April 22, 2018 09:02
codality OddOccurrencesInArray
import java.util.HashMap;
import java.util.Map;
public class OddOccurrencesInArray {
public static void main(String[] args) {
System.out.println(new OddOccurrencesInArray().solution(new int[]{9, 3, 9, 3, 9, 9, 7}));
}