Skip to content

Instantly share code, notes, and snippets.

@tomwhoiscontrary
tomwhoiscontrary / Main.java
Last active February 8, 2024 01:03
A simple Java web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
import com.sun.net.httpserver.Filter;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
@tomwhoiscontrary
tomwhoiscontrary / ParseOrdinalDate.java
Last active September 13, 2023 12:59
trying out the nice ordinal formatting and parsing code in https://stackoverflow.com/a/72557618/116639
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@tomwhoiscontrary
tomwhoiscontrary / TransducersTest.java
Created April 5, 2023 17:34
Another go at transducers in Java, this time on top of collectors, although this is not quite right
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
@tomwhoiscontrary
tomwhoiscontrary / LeakDemo.cpp
Created February 1, 2023 14:15
source code for " Memory leak in SofrFutureRateHelper" https://github.com/lballabio/QuantLib/issues/1578
#include <ql/config.hpp>
#include <cmath>
#include <iostream>
#include <ql/settings.hpp>
#include <ql/termstructures/yield/overnightindexfutureratehelper.hpp>
#include <ql/time/date.hpp>
#include <ql/time/frequency.hpp>
@tomwhoiscontrary
tomwhoiscontrary / install-concourse-on-ubuntu.sh
Created August 22, 2016 09:18
A shell script to install Concourse on a systemd-based Ubuntu using the plain binary
#! /bin/bash -eu
EXTERNAL_URL_HOST_NAME="$1"
ADMIN_USERNAME="$2"
ADMIN_PASSWORD="$3"
CONCOURSE_VERSION=${CONCOURSE_VERSION:-v1.1.0}
apt-get update
apt-get install -y postgresql postgresql-contrib
import java.util.Arrays;
import java.util.Random;
public class CalculateStandardArray {
private static final Random RANDOM = new Random();
public static void main(String[] args) {
int numStats = 12;
int numTrials = 10_000_000;
@tomwhoiscontrary
tomwhoiscontrary / ostream_state.cpp
Last active January 16, 2023 19:42
Class to save and restore ostream state in C++, to make floating point format management a bit saner
class ostream_state {
std::ostream::fmtflags flags;
std::streamsize precision = 6;
public:
class Save {
friend ostream_state;
friend std::ostream& operator<<(std::ostream& out, const Save& save) {
save.save(out);
@tomwhoiscontrary
tomwhoiscontrary / tabs.html
Created November 17, 2022 17:59
Pure CSS tabs
<html>
<head>
<style>
.tabs {
/* make this a horizontal flexbox, and make it capable of wrapping */
display: flex;
flex-wrap: wrap;
}
2022-07-10T20:59:32+0100 rife systemd[2415]: Started dbus-:1.2-org.cinnamon.ScreenSaver@3.service.
░░ Subject: A start job for unit UNIT has finished successfully
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit UNIT has finished successfully.
░░
░░ The job identifier is 617.
2022-07-10T20:59:32+0100 rife cinnamon-screensaver[66385]: CsNotificationWatcher: Could not add match rule to bus - GDBus.Error:org.freedesktop.DBus.Error.MatchRuleInvalid: Invalid match rule
2022-07-10T20:59:32+0100 rife /usr/libexec/gdm-x-session[2529]: cinnamon-session[2529]: WARNING: t+169917.09334s: Detected that screensaver has appeared on the bus
1 0.000000
2 0.301030
3 0.477121
4 0.602060
5 0.698970
6 0.778151
7 0.845098
8 0.903090
9 0.954243
10 1.000000