Skip to content

Instantly share code, notes, and snippets.

from playwright import async_playwright
from sanic import Sanic
from sanic import response
app = Sanic(name='Translate application')
#test with: curl 'http://localhost:5000/translate?sl=nl&tl=en&translate=auto'
@app.route("/translate")
async def doTranslate(request):
@MaartenSmeets
MaartenSmeets / DemoController.java
Created July 26, 2019 09:10
DemoController.java
package nl.amis.smeetsm.sb;
import oracle.jdbc.OracleArray;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
@MaartenSmeets
MaartenSmeets / process-exporter.yml
Created December 9, 2018 10:23
Proces exporter yml file to monitor my Spring Boot processes
process_names:
# comm is the second field of /proc/<pid>/stat minus parens.
# It is the base executable name, truncated at 15 chars.
# It cannot be modified by the program, unlike exe.
- comm:
- java
cmdline:
- app.jar
@MaartenSmeets
MaartenSmeets / docker-compose.yml
Created December 9, 2018 10:21
docker-compose.yml test setup
version: '2'
services:
spring-boot-jdk:
image: "spring-boot-jdk"
container_name: spring-boot-jdk
ports:
- "8080:8080"
networks:
- dockernet
mem_limit: 1024M
String output = String.format("{ \"access_token\" : \"%s\",\n" + " \"scope\" : \"read write\",\n" + " \"token_type\" : \"Bearer\",\n" + " \"expires_in\" : %s\n}", token,expirytime);
@MaartenSmeets
MaartenSmeets / gist:bc204e98208dee1d8e1d58e443c36e0f
Created October 27, 2018 10:21
Generate and sign the token
SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).keyID(rsaJWK.getKeyID()).build(), claimsSet);
signedJWT.sign(signer);
String token = signedJWT.serialize();
JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
.subject(user)
.issuer(prop.getProperty("tokenissuer"))
.expirationTime(expires)
.issueTime(new Date(new Date().getTime()))
.build();
@MaartenSmeets
MaartenSmeets / signer.java
Created October 27, 2018 10:20
Obtain a signer
JWSSigner signer = new RSASSASigner(rsaJWK);
@MaartenSmeets
MaartenSmeets / gist:5f97bda15aa116b467ed35d927c8461b
Created October 27, 2018 10:19
Build RSAKey from public and private keys
RSAKey rsaJWK = new RSAKey.Builder(myPublicKey).privateKey(myPrivateKey).keyID(prop.getProperty("keyalias")).build();
@MaartenSmeets
MaartenSmeets / gist:97857d59c5d59cbd3fd7489bb404279b
Created October 27, 2018 10:18
Get RSA keys for use with JWT token
RSAPrivateKey myPrivateKey = (RSAPrivateKey) pkEntry.getPrivateKey();
RSAPublicKey myPublicKey = (RSAPublicKey) pkEntry.getCertificate().getPublicKey();