Skip to content

Instantly share code, notes, and snippets.

View david-bakin's full-sized avatar

David Bakin david-bakin

View GitHub Profile
@david-bakin
david-bakin / jackson-jsr-310-instant-issues.java
Last active October 22, 2015 21:48
Illustrates two problems with Jackson :jackson-datatype-jsr310 v2.6.2 when dealing with java.time.Instant.
package com.bakins_bits;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.assertj.core.api.StrictAssertions.assertThat;
import static org.assertj.core.api.StrictAssertions.fail;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
@david-bakin
david-bakin / Either.java
Created November 7, 2015 03:40
Either type for Java
package com.bakins_bits.types;
import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.google.common.base.Preconditions;
@david-bakin
david-bakin / Result.java
Created November 11, 2015 05:03
Java Result class - union (sum) type of a success type and a failure type, with a "pattern matching" functional interface
package com.bakins_bits.types;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.google.common.base.Preconditions;
@david-bakin
david-bakin / shanselman-profile.json
Last active May 5, 2020 23:14 — forked from shanselman/settings.json
Microsoft Terminal settings/profile from [Scott Hanselman](https://www.youtube.com/watch?v=j0PPcUUtHlw)
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"globals": {
"alwaysShowTabs": true,
"defaultProfile": "{79285a8e-036c-446f-8a9c-78994e34cf85}",
"initialCols": 120,
"initialRows": 30,
"requestedTheme": "dark",
"keybindings": [
{
@david-bakin
david-bakin / template-inheriting-from-its-own-specialization.cc
Created January 12, 2021 17:05
Odd example of a template inheriting from its own specialization
#include <iostream>
#include <string>
// Template which inherits from its own specialization, as I first saw in
// https://stackoverflow.com/a/28213747/751579, which surprised me
template <typename T>
struct Foo : public Foo<decltype(T::x)> {
T xxx;
};
@david-bakin
david-bakin / grab-my-kindle-books.js
Last active June 28, 2022 05:35
Grab list of all Kindle books purchased from the currently logged in Amazon account - saves as a JSON file.
// Grab list of all kindle books purchased from the currently logged in
// Amazon account. Lets you save this list as a JSON file.
// The following data should be run in the console while viewing the page https://read.amazon.com/
// Kindle booklist fetch derived from jkubecki/ExportKindle.js
// (https://gist.github.com/jkubecki/d61d3e953ed5c8379075b5ddd8a95f22)
// console.save grabbed from DevTools Snipppets
// (https://bgrins.github.io/devtools-snippets/#console-save)
@david-bakin
david-bakin / Auto.h
Last active August 6, 2022 17:53
O'Dwyer's Auto macro - hygenic scope guard w/ zero overhead
#pragma once
# O'Dwyer's Auto macro - hygenic scope guard w/ zero overhead
# https://quuxplusone.github.io/blog/2018/08/11/the-auto-macro/
#
# "This scope guard has perfect codegen with zero overhead (at `-O2`) on all major compilers."
# "Because it requires no explicit captures, no novel variable name, no special treatment for `this`,
# it is highly suited for mechanically generated code."
# "It is portable all the way back to C++11."
@david-bakin
david-bakin / gist:3b18a507ba4e2c825b26c01a85c8f858
Last active January 28, 2023 21:41
Electrum 4.3.4 "Balance" does _not_ include amount in change addresses
Electrum's "History" page - showing transactions in and out - has a total at the bottom called "Balance", which,
obviously, shows how much BTC is in the wallet.
Except it doesn't. Because it doesn't include any amount that is in change addresses.
@david-bakin
david-bakin / JacksonInterfaceCustomDeserializerMCVE.java
Created June 27, 2023 17:17
JacksonPolymorphicTypeHandlingOnInterfaceWithCustomDeserializer
/*
* Copyright (C) 2023 Bakin's Bits
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the “Software”), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
@david-bakin
david-bakin / OneArrayElementPerLineNoWhitespacePrettyPrinter.java
Created July 1, 2023 02:29
Jackson pretty printer that prints objects compactly (no whitespace) and array elements one-per-line
/* Looks like this:
{"todo":[
{"isbn":"0064632105"},
{"isbn":"007001115X"},
{"isbn":"0070079749"},
...
*/
public static class OneArrayElementPerLineNoWhitespacePrettyPrinter extends DefaultPrettyPrinter {
public OneArrayElementPerLineNoWhitespacePrettyPrinter() {}