Instantly share code, notes, and snippets.

View CodeParsingJWT_ReceivedFromRequest.java
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
final HttpServletRequest req = (HttpServletRequest) request;
final String authHeader = req.getHeader("authorization");
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
throw new ServletException("Missing or invalid Authorization header");
}
View AuthenticationControllerCreatingJWT.java
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
@RestController
public class AuthenticationController { ...
@ApiOperation(value = "Validate the user login")
@PostMapping("/api/authentication/login")
public ResponseEntity<?> userLogin(@RequestBody User user) {
String jwtToken = "";
View application.properties
server.port=8889
hello.greeting= nice to meet you
hello.version= 2.0
View HelloController.java
package demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
View manifest.yml
---
applications:
- name: hello-boot
instances: 1
host: hello-boot-${random-word}
path: target/hello-boot-1.0.jar
View simple-inefficient-quicksort-algo
// Sort an array using a simple but inefficient quicksort.
public int[] quicksortSimple(int[] data) {
if (data.length < 2) {
return data;
}
int pivotIndex = data.length / 2;
int pivotValue = data[pivotIndex];
int leftCount = 0;
// Count how many are less than the pivot
View SwaggerChangesForSpringREST.java
/* Mentioning all the swagger changes made on top of
Spring REST app: https://gist.github.com/codinko/79986dbed38d0f2b2d1b */
---------------------------------------
Modified File: pom.xml
---------------------------------------
<properties>
<swagger.version>1.0.2</swagger.version>
</properties>
<dependencies>
<dependency>
View APIContract.java
package com.codinko.springrestapi.vo;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
// Generic class that can have data of generic type. See it's usage when an instance of this class is created
public class APIContract<T> {
private boolean success;
private String message;
View samplePOMwithnothing.xml
<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.codinko.restapi</groupId>
<artifactId>restapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
View SelectFromMysqlUsingPHPPDO.php
<?php
class Config {
public static $dbserver = "localhost";
public static $username = "usernamemax";
public static $pwd = "Compl$#1Pwd";
public static $dbname = "sampledb";
}
?>
<?php