Skip to content

Instantly share code, notes, and snippets.

View simonharrer's full-sized avatar
🏠
Mob Programming from my Home Office

Dr. Simon Harrer simonharrer

🏠
Mob Programming from my Home Office
View GitHub Profile
@simonharrer
simonharrer / Dockerfile
Created June 3, 2018 19:08
Automatically add SSL server certificate to list of trusted certificates during build
FROM openjdk:8-jdk-alpine
ENV EMAIL_HOSTNAME="smtp.gmail.com"
ENV EMAIL_PORT="587"
RUN apk add --no-cache openssl
RUN openssl s_client -showcerts -connect $EMAIL_HOSTNAME:$EMAIL_PORT -starttls smtp </dev/null 2>/dev/null | openssl x509 -outform DER > my-certificate.der
RUN echo yes | $JAVA_HOME/bin/keytool -import -trustcacerts -file my-certificate.der -alias my-certificate -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit
@simonharrer
simonharrer / FizzBuzzComplex.java
Last active June 4, 2018 07:27
FizzBuzz 4 spaces indent with an increase of 4 spaces with the first three indents without an increase
class FizzBuzz {
public static void main(String[] args) {
if (args != null && args.length == 1) {
try {
int number = Integer.parseInt(args[0]);
for (int i = 1; i < number; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
@simonharrer
simonharrer / FizzBuzzComplex.java
Last active June 4, 2018 07:27
FizzBuzz 4 spaces indent with an increase of 4 spaces
class FizzBuzz {
public static void main(String[] args) {
if (args != null && args.length == 1) {
try {
int number = Integer.parseInt(args[0]);
for (int i = 1; i < number; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
@simonharrer
simonharrer / FizzBuzzComplex.java
Last active June 4, 2018 07:26
FizzBuzz4Spaces
class FizzBuzz {
public static void main(String[] args) {
if (args != null && args.length == 1) {
try {
int number = Integer.parseInt(args[0]);
for (int i = 1; i < number; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
@simonharrer
simonharrer / ForkJoinHistogramService.java
Last active December 21, 2016 13:35
Frohe Weihnachten PKS WiSe 16/17 - Hier der einzige Lösungsvorschlag seit 6 Jahren AJP und PKS
package de.uniba.wiai.dsg.pks.assignment1.histogram.threaded.forkjoin;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@simonharrer
simonharrer / ConcurrencyHelper.java
Last active May 18, 2022 14:18
Java Concurrency Best Practices in Code
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
class ConcurrencyHelper {
@simonharrer
simonharrer / turbolinks.md
Last active August 18, 2016 13:20
Turbolinks Best Practices
@simonharrer
simonharrer / duplicate-finder.rb
Created September 16, 2015 15:21
Finds duplicate files in sibling folders
result = {}
Dir.glob("*").each do |dir|
result[dir] = Dir.glob("#{dir}/**/*").to_a.select {|p| File.file?(p)}.map {|p| p[dir.length..-1]}
end
puts "#{result.count} dirs found"
result.each do |key, value|
result.each do |key2, value2|
@simonharrer
simonharrer / build.gradle
Created August 5, 2015 12:41
How to convert a SVG to a PNG in a gradle build script.
configurations {
rasterizer
}
dependencies {
rasterizer 'org.apache.xmlgraphics:batik-rasterizer:1.7'
rasterizer 'org.apache.xmlgraphics:batik-codec:1.7'
}
task svg2png(type: org.gradle.api.tasks.JavaExec) {
classpath configurations.rasterizer
main "org.apache.batik.apps.rasterizer.Main"
# ARGS
url = "TODO"
username = "TODO"
password = "TODO"
folder = "TARGET_FOLDER"
# LOGIC
require "fileutils"
FileUtils.rm_rf folder
FileUtils.mkdir folder