Skip to content

Instantly share code, notes, and snippets.

View shasisingh's full-sized avatar

Shasi Singh shasisingh

View GitHub Profile
@shasisingh
shasisingh / generate-certificate-chain.sh
Last active February 16, 2024 21:05 — forked from yamen/generate-certificate-chain.sh
Generate a full self-signed certificate chain (Root -> Intermediate CA -> Server) using keytool, that can be used for 'localhost' development
#!/bin/bash
#exit on error
set -B
rm *.jks 2> /dev/null
rm *.pem 2> /dev/null
echo "===================================================="
echo "Creating fake third-party chain root -> ca"
public static void main(String[] args) {
System.Logger logger = System.getLogger("Apps");
logger.log(System.Logger.Level.ERROR, "some log");
logger.log(System.Logger.Level.INFO, "some info");
}
public static void main(String[] args) {
var task = new TimerTask() {
@Override
public void run() {
System.out.println("run some task");
}
};
var timeer = new Timer();
timeer.scheduleAtFixedRate(task, 10, 10);
public static void main(String[] args) throws InterruptedException {
var start = Instant.now();
verySlow();
var end= Duration.between(start,Instant.now()).toMillis();
System.out.printf("Time Taken: %dms%n",end);
}
private static void verySlow() throws InterruptedException {
Thread.sleep(1000);
}
@shasisingh
shasisingh / createTarGzipFiles.java
Last active April 13, 2023 18:05
GzipCompressor and TarArchive
public static void createTarGzipFiles(List<Path> files, Path output) {
try (OutputStream fOut = Files.newOutputStream(output);
BufferedOutputStream buffOut = new BufferedOutputStream(fOut);
GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(buffOut);
TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut)) {
for (Path path : Collections.unmodifiableList(files)) {
if (!Files.isRegularFile(path)) {
throw new IOException("Support only file!");
}
@shasisingh
shasisingh / ParseRSAKeys.java
Created March 17, 2023 14:37 — forked from destan/ParseRSAKeys.java
Parse RSA public and private key pair from string in Java
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;