Skip to content

Instantly share code, notes, and snippets.

@sthum
sthum / psql_text_similaritry_operator.sql
Created June 28, 2016 12:52
Pragmatic solution for calculating the similarity of text / words of database entires in PostgreSQL
--- If you are missing the pypythonu extension, install it first
--- (Ubuntu): sudo apt-get install python-psycopg2
--- Activate plpython
CREATE EXTENSION plpythonu;
--- Create the profiling function
CREATE OR REPLACE FUNCTION similarity(text, text) RETURNS numeric AS $$
import difflib
return difflib.SequenceMatcher(None,args[0], args[1]).ratio()
@sthum
sthum / Java8DateTimeConverter.java
Last active June 17, 2016 08:21
Util class to convert between Java 8 DateTime API and the old java.util.Date class
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Date;
/**
* Converts between the new Java 8 DateTime API and the old (not-so-beloved) {@link java.util.Date} class.
* The conversions use the system default locale timezone , otherwise the time will change.
@sthum
sthum / Oracle Java 8 Installation for automation
Last active June 15, 2016 11:35
Oracle Java 8 Installation which sets the licence agreement in advance. This way this procedure can be included in any automated installation. I did use this in a packer build.
sudo apt-get update
# make add-apt-repository available
sudo apt-get install -y software-properties-common python-software-properties
## add java 8 repo
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
# setting to automatically accept the licence to prevent the prompt
curl -s get.sdkman.io | bash && \
source "$HOME/.sdkman/bin/sdkman-init.sh" && \
sdk install groovy