Skip to content

Instantly share code, notes, and snippets.

@tonvanbart
tonvanbart / House.java
Last active March 24, 2023 23:17
How to capture constructor arguments while Mockito is mocking the constructed class. Not pleasant but it works.
class Dog {
String name;
public Dog(String name) {
this.name = name;
}
public String bark() {
return name + " says: Woof!";
@tonvanbart
tonvanbart / csvconvert.go
Last active May 4, 2022 20:45
Quick example Golang hack to convert a CSV file to XML and JSON.
package main
import (
"encoding/csv"
"encoding/json"
"encoding/xml"
"fmt"
"log"
"os"
"strconv"
@tonvanbart
tonvanbart / Tryout.java
Last active January 28, 2022 16:56
Try out various Java enum (mis)uses
package io.axual.connect.plugins.kafka;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class Tryout {
@Test
@tonvanbart
tonvanbart / people.go
Created January 17, 2022 15:08
Small Go program to read number of people in space from a webservice
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
type Astronaut struct {
@tonvanbart
tonvanbart / proxy_example.py
Last active March 28, 2021 13:56
Example Python GoF proxy
from abc import ABC, abstractmethod
class ProxySubject(ABC):
"""
The interface we will use in our proxy and subject.
"""
@abstractmethod
def do_stuff(self, arg):
@tonvanbart
tonvanbart / kcst.py
Last active February 7, 2021 21:42
Python script to check the status of all Kafka connectors on a given host
#!/usr/bin/python
# check the status of Kafka connectors on a given host
import urllib2
import json
import sys, getopt
def main(argv):
hostname = ""
@tonvanbart
tonvanbart / Main.java
Created August 22, 2019 11:55
Flink job showing how to create a Flink source from a websocket connection.
package com.kpn.datalab.mab;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.api.common.restartstrategy.RestartStrategies;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
@tonvanbart
tonvanbart / AggregationTestIT.java
Created May 20, 2019 11:40
Flink streaming average example
package com.kpn.datalab.mab;
import org.apache.flink.api.common.functions.AggregateFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
import org.apache.flink.streaming.api.windowing.assigners.TumblingProcessingTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.junit.Test;
@tonvanbart
tonvanbart / Probeersel.java
Last active March 6, 2018 22:32
Quick try-out of property resolution in Spring tests. As it turned out there was an application.properties in src/test/resources which was masking the one in src/main. @Autowiring the ApplicationContext enables browsing the contents in a debugger to see what's going on.
package testing;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.test.context.ContextConfiguration;
@tonvanbart
tonvanbart / readcookie.sh
Created May 15, 2017 09:18
Quick reference on how to extract XSRF token cookie value and store it for later use in a bash script.
#!/bin/sh
if [ "$#" -ne 1 ]; then
echo Usage is: $0 base-url where base-url is up to and including gateway/api
exit 0
fi
XSRF_COOKIE="$(curl $1/provisioning/health -I 2>/dev/null | grep Set-Cookie | sed -e 's/^Set-Cookie: XSRF-TOKEN=\([^;]*\);\(.*\)/\1/')"
echo found cookie: $XSRF_COOKIE