Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Mob Programming from my Home Office

Simon Harrer simonharrer

🏠
Mob Programming from my Home Office
View GitHub Profile
@simonharrer
simonharrer / Dockerfile
Created Jun 3, 2018
Automatically add SSL server certificate to list of trusted certificates during build
View Dockerfile
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 Jun 4, 2018
FizzBuzz 4 spaces indent with an increase of 4 spaces with the first three indents without an increase
View FizzBuzzComplex.java
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 Jun 4, 2018
FizzBuzz 4 spaces indent with an increase of 4 spaces
View FizzBuzzComplex.java
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");
View FizzBuzzComplex.java
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 Dec 21, 2016
Frohe Weihnachten PKS WiSe 16/17 - Hier der einzige Lösungsvorschlag seit 6 Jahren AJP und PKS
View ForkJoinHistogramService.java
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 Nov 12, 2020
Java Concurrency Best Practices in Code
View ConcurrencyHelper.java
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 Aug 18, 2016
Turbolinks Best Practices
View turbolinks.md
@simonharrer
simonharrer / duplicate-finder.rb
Created Sep 16, 2015
Finds duplicate files in sibling folders
View duplicate-finder.rb
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 Aug 5, 2015
How to convert a SVG to a PNG in a gradle build script.
View build.gradle
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"
View download-them-all.rb
# ARGS
url = "TODO"
username = "TODO"
password = "TODO"
folder = "TARGET_FOLDER"
# LOGIC
require "fileutils"
FileUtils.rm_rf folder
FileUtils.mkdir folder