Skip to content

Instantly share code, notes, and snippets.

@LorisBachert
LorisBachert / TikaExtractor.java
Last active September 4, 2024 12:52
Using Apache TIKA to extract the following formats: DOC, DOCX, PPT, PPTX, XLS, XLSX, PDF, JPG, PNG, TXT Note: Tesseract must be installed in order to get JPG and PNG extraction working.
/**
* Uses Tikas {@link AutoDetectParser} to extract the text of a file.
*
* @param document
* @return The text content of a file
*/
@Override
public String extractTextOfDocument(File file) throws Exception {
InputStream fileStream = new FileInputStream(file);
Parser parser = new AutoDetectParser();
@LorisBachert
LorisBachert / MongoDAO.java
Last active January 25, 2016 11:57
CRUD operations for MongoDB using Java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
@LorisBachert
LorisBachert / animated.css
Last active November 13, 2015 07:00
Animating elements using CSS
.animated {
-webkit-transition: width 0.25s ease-in-out;
-moz-transition: width 0.25s ease-in-out;
-o-transition: width 0.25s ease-in-out;
-ms-transition: width 0.25s ease-in-out;
transition: width 0.25s ease-in-out;
}
@LorisBachert
LorisBachert / FileHelper.java
Created November 26, 2015 10:34
Detecting the type of a file by its name
public static String getFileExtension(File file) {
return FileHelper.getFileExtension(file.getName());
}
public static String getFileExtension(String name) {
if (! name.contains(".")) {
return "";
}
String[] split = name.split("\\.");
String extension = split[split.length - 1];
@LorisBachert
LorisBachert / constants.js
Created June 10, 2016 14:18
Create a javascript object with frozen constants. Includes a deep freeze aswell!!!
// Define your constants
var Constants = {
"CONSTANT_NAME" : "CONSTANT_VALUE",
"CONSTANT_OBJECT" : {
"CONSTANT_OBJECT_KEY" : "CONSTANT_OBJECT_VALUE"
}
};
createConstantsAndFreeze(Constants);
// Do the magic
function createConstantsAndFreeze(obj) {
@LorisBachert
LorisBachert / unlock liquibase.sql
Created February 26, 2018 14:07
When Liquibase cannot get the changelog due to a canceled run
UPDATE DATABASECHANGELOGLOCK SET LOCKED=FALSE, LOCKGRANTED=null, LOCKEDBY=null where ID=1;
@LorisBachert
LorisBachert / move offscreen window to screen
Created November 12, 2018 05:20
Move an offscreen window back to the screen in Windows 10
Select window with CTRL+ALT+TAB
Press ALT+SPACE+M
Select "Move" option
Use arrow keys to move the window back to the screen