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 / 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 / random_text_generator.rb
Last active April 5, 2022 22:25
Generate random text files
require "literate_randomizer"
require "fileutils"
$lr = LiterateRandomizer.create
FileUtils.rm_rf "data"
Dir.mkdir "data"
def generate(folder, level = 4)
return if level == 0
@simonharrer
simonharrer / Calculator.java
Created October 31, 2012 09:32
Simple Calculator as a Java Webservice
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class Calculator {
public static void main(String[] args) {
Calculator.calculate(1, 1, "ADD");
Calculator.calculate(2, 3, "MULT");
Calculator.calculate(5, 2, "asdf");
@simonharrer
simonharrer / gist:4016692
Created November 5, 2012 11:11
Validating against multiple XSD files using the classpath
String path = "my/test/path/to/file.xml";
SchemaFactory sFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sFactory.newSchema(new Source[]{
new StreamSource(getClass().getResourceAsStream("/path/to/schema1.xsd")),
new StreamSource(getClass().getResourceAsStream("/path/to/schema2.xsd"))
});
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File(path)));
@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 / 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 / ReceiveReply.md
Created November 30, 2012 12:14
Oracle SOA Suite 11g - Deployment Archives and Scripts

Oracle SOA Suite 11g - Deployment Archives and Scripts

This article sheds some light on the question: "How to get a BPEL process packaged and deployed to the Oracle SOA Suite 11g automatically without any IDE?"

The BPEL process

The BPEL process has to be very simple as the task focus on packaging and deployment. I chose the ReceiveReply test from the betsy test suite which receives an integer and echos it back to the caller. Here is some pseudo code on how it works:

ReceiveReply: int -> int
@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;