Skip to content

Instantly share code, notes, and snippets.

@oofnivek
oofnivek / Main.java
Last active January 11, 2024 17:31
Extract certificate from JKS in PEM format
package org.example;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
import org.bouncycastle.util.io.pem.PemObject;
import java.io.*;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
@oofnivek
oofnivek / Main.java
Created January 11, 2024 12:46
Appending string to file
package org.example;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import static java.util.UUID.randomUUID;
@oofnivek
oofnivek / Main.java
Created January 11, 2024 12:31
Write string contents to file
package org.example;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
String content = "hello world";
try {
@oofnivek
oofnivek / Main.java
Last active January 11, 2024 12:24
Read file line by line
package org.example;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try {
package com.example.demo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;
@Configuration
public class CacheStoreBeans {
package com.example.demo;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.concurrent.TimeUnit;
public class CacheStore<T> {
private Cache<String, T> cache;
package com.example.demo;
import org.springframework.stereotype.Service;
@Service
public class BookService {
public Book getBookById(String id){
try{
// simulate slow retrieval from DB
Thread.sleep(2000);
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class BookController {
package com.example.demo;
import lombok.Getter;
import lombok.Setter;
public class Book {
@Getter
@Setter
private String id;
package common;
import java.util.Random;
public class MyRandom {
private String alphabets = "abcdefghijklmnopqrstuvwxyz";
private String numbers = "0123456789";
private String alphanumerics = numbers + alphabets;
public String randomizer(String validChars, int length){