Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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>
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
@tomwhoiscontrary
tomwhoiscontrary / index.txt
Created June 12, 2022 20:11
Upgrading from Fedora 34 to Fedora 36
Following https://docs.fedoraproject.org/en-US/quick-docs/dnf-system-upgrade/
# main upgrade
dnf upgrade --refresh
dnf install dnf-plugin-system-upgrade
dnf system-upgrade download --releasever=36
dnf system-upgrade reboot
# refresh all locally modified config files
dnf install rpmconf
@tomwhoiscontrary
tomwhoiscontrary / HasFeature.java
Created April 26, 2022 15:37
Back on my bullshit once more. The minimal, getter-only version of lambda-property-matcher.
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.UncheckedIOException;
import java.lang.invoke.SerializedLambda;
import java.util.Objects;