void saveAsImagePdfFromTextPdf() throws IOException {
final Path originalPdfPath = Paths.get("<source pdf path>");
final Path imagePdfPath = Paths.get("<destination pdf path>");
try(PDDocument document = PDDocument.load(originalPdfPath.toFile()); PDDocument imageDoc = new PDDocument()) {
PDFRenderer pdfRenderer = new PDFRenderer(document);
for (int pageNum = 0; pageNum < document.getNumberOfPages(); ++pageNum) {
final BufferedImage bufferedImage = pdfRenderer.renderImageWithDPI(pageNum, 300, ImageType.RGB);
PDPage page = new PDPage(new PDRectangle(bufferedImage.getWidth(), bufferedImage.getHeight()));
imageDoc.addPage(page);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Merriam Webster -> Lexico linker | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @author You | |
// @match https://www.merriam-webster.com/dictionary/* | |
// @grant none | |
// ==/UserScript== | |
(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name wikipedia | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @author You | |
// @match https://*.wikipedia.org/wiki/* | |
// @match https://*.wikiquote.org/wiki/* | |
// @match https://*.wiktionary.org/wiki/* | |
// @grant none | |
// ==/UserScript== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String base64Encode(Path filePath) { | |
String base64EncodeFileConetnt = ""; | |
try (InputStream fileStream = newInputStream(filePath)) { | |
// Reading a Image file from file system | |
byte[] fileData = new byte[(int) Files.size(filePath)]; | |
//noinspection ResultOfMethodCallIgnored | |
fileStream.read(fileData); | |
base64EncodeFileConetnt = Base64.getEncoder().encodeToString(fileData); | |
} catch (FileNotFoundException e) { | |
System.out.println("File not found" + e); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int getNumOfDigits(int number) { | |
int numOfDigits = 0; | |
int remainder = number; | |
do { | |
numOfDigits++; | |
remainder = remainder / 10; | |
} while (remainder > 0); | |
return numOfDigits; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void deleteDirRecursively(Path pathToDel) throws IOException { | |
Files.walk(pathToDel) | |
.sorted(reverseOrder()) // dir would be listed before the files inside. So, we delete the files in the right order | |
.forEach(path -> run(() -> delete(path))); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void zip(Path sourceDirPath, Path zipFilePath) throws IOException { | |
//@formatter:off | |
createFile(zipFilePath, DEFAULT_FILE_ATTRS); | |
try (ZipOutputStream zos = new ZipOutputStream(newOutputStream(zipFilePath)); Stream<Path> paths = Files.walk(sourceDirPath)) { | |
paths.filter(path -> !Files.isDirectory(path)) | |
.forEach(path -> { | |
ZipEntry zipEntry = new ZipEntry(sourceDirPath.relativize(path).toString()); | |
try { | |
zos.putNextEntry(zipEntry); | |
Files.copy(path, zos); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.lowagie.text.Document; | |
import com.lowagie.text.pdf.PdfCopy; | |
import com.lowagie.text.pdf.PdfImportedPage; | |
import com.lowagie.text.pdf.PdfReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.nio.file.Files; | |
import java.nio.file.Path; |
Assuming that the following environment variables are set:
KAFKA_HOME
where Kafka is installed on local machine (e.g./opt/kafka
)ZK_HOSTS
identifies running zookeeper ensemble, e.g.ZK_HOSTS=192.168.0.99:2181
KAFKA_BROKERS
identifies running Kafka brokers, e.g.KAFKA_BROKERS=192.168.0.99:9092
Start Zookepper and Kafka servers
WIP
- Either extend your interface from
CrudRepository<T, ID>
(or more specific variant of it, if the classpath contains repositories for multiple types of data sources sayJpaRepository<T, ID>
,MongoRepository<T, ID>
) - (or) copy paste selective methods from
CrudRepository/JpaRepository
interface and annotate your interface with@RepositoryDefinition(domainClass = T.class, idClass = Id.class)
. With this your repository interface would be quite clean @EnableJpaRepositories
(+ its persistence specific variants) at the@Configuration
class level- Expects the transaction manager to be named
transactionManager
& entityManagerFactory to be namedentityManagerFactory
by default. If not, we have to explicitly specify the actual names - For all default method, you can find implementation in
SimpleJpaRepository
, which is internally annotated with@Repository
(gives exception translation) &@Transactional(readOnly = true)
for transactional guarantee