Git Squash

When using Git on a branch of development feature, we did several commits and we want to combine all the lasts commits into one.

Git Squash

On your local dev branch:

  • git rebase -i <SHA Code: all the commits after this (include) will combine>
  • change pick to squash
  • save modification
  • git push origin <your_branch> --force

Git Reset local branch as remote master branch

  • git fetch origin
  • git reset --hard origin/master

Using JWT RSA in Java

JWT is used generally in two cases (according to https://jwt.io/introduction/):
Authentication  and
Information Exchange: JSON Web Tokens are a good way of securely transmitting information between parties. Because JWTs can be signed—for example, using public/private key pairs—you can be sure the senders are who they say they are. Additionally, as the signature is calculated using the header and the payload, you can also verify that the content hasn’t been tampered with.

  1. Generate JWT RS256 Private, Public Key
ssh-keygen -t rsa -b 2048 -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
2.RSA Key Format
  • Public Key:

PKCS#1 RSAPublicKey* (PEM header: BEGIN RSA PUBLIC KEY)
X.509 SubjectPublicKeyInfo** (PEM header: BEGIN PUBLIC KEY)

  • Private Key:

PKCS#1 RSAPrivateKey** (PEM header: BEGIN RSA PRIVATE KEY)
PKCS#8 PrivateKeyInfo* (PEM header: BEGIN PRIVATE KEY)

3. Sign JWT with Private Key

Using auth0 java-jwt lib

try {
    Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);
    String token = JWT.create()
        .withIssuer("auth0")
        .sign(algorithm);
} catch (JWTCreationException exception){
    //Invalid Signing configuration / Couldn't convert Claims.
}

 

4.Verify JWT with Public Key

Using auth0 java-jwt lib

try {
    Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);
    JWTVerifier verifier = JWT.require(algorithm)
        .withIssuer("auth0")
        .build(); //Reusable verifier instance
    DecodedJWT jwt = verifier.verify(token);
} catch (JWTVerificationException exception){
    //Invalid signature/claims
}

Code Example Git

RESTful API is all about resource

The heart of the design of restful API is around `resource`.

GET, POST, PUT, DELETE, etc – HTTP verbs to manipulate resources.

URL –  the path to locating the resources.

Some options for restful API design:

Endpoints (URL):
  • using plural nouns, lowercase.(e.g.  prod.api.aerodc/users/:id/settings)
  • always putting ‘: id’ in the path, not in the body Json.
HTTP Response code:
  • not found for findAll -> 200 with empty resources
  • not found for findById -> 404 not found
  • 201: post resource created
  • 204:  no content. deleted resource
  • 202:  HTTP PUT or in some microservice environment
  • 400: Bad request (wrong format parameters)
  • 401: Unauthorized (missing parameters)
  • 403: Forbidden (security concern)
  • 404: Not found (resources not exist)
  • 409: Conflict (resources already exist)
  • 429: Ratelimit (too many requests)
JSON
  • Property: snake_case
  • For boolean property: avoid using like “is_deleted” is_xxx.
Some good articles about restful api design:

Octohttps://blog.octo.com/en/design-a-rest-api/

Paypalhttps://github.com/paypal/api-standards/blob/master/api-style-guide.md

Gocardlesshttps://github.com/gocardless/http-api-design

Java8 Practice – Transforming Map to String

Case: We have a parameters and values Map, and we want to transform it into URL param string like ‘param1=value1&param2=value2’.

We could use Java8 lambda to make a short clean code:


public static String mapToString(Map&lt;String, String&gt; inputMap){

        return inputMap
                .entrySet()
                .stream()
                .sorted(Map.Entry.comparingByKey())
                .filter(e-&gt;;e.getValue()!=null)
                .map(e-&gt;;e.getKey()+'='+e.getValue())
                .collect(Collectors.joining(";"));
}

 

Source Code Github

How to create a https web site using WordPress and AWS

This site, my personal blog was built using WordPress and hosting on AWS. I found that it was quite easy and not that expensive.

Billing details:

  • AWS is free for hosting the site for the first year. (https://aws.amazon.com/free/)
  • I paid 13.3 dollars (tax including) for buying my domain name and paid 0.51 dollars for AWS Route53.

The process to build the https site using AWS and WordPress:

That is it!

PSD2

PSD2 (The second Payment Services Directive) came into effect 13 January 2018. It will force the banks to open their clients’ financial data for the third parties. This will bring significate change in the future Europe Banking markets.

Here is a list of views by some hotTEST Europe Fintech Startups:

Others: