Skip to content

Instantly share code, notes, and snippets.

View grommitz's full-sized avatar

Martin Charlesworth grommitz

View GitHub Profile
@grommitz
grommitz / removeExpiredCerts.sh
Created September 20, 2020 23:59
Remove expired certificates from a keystore
#!/usr/bin/env bash
# remove expired certs from a keystore
# set FN to the keystore file
# set the regex to identify expired certs. in my example anything mentioning 2019 is considered expired.
FN=cacerts.jks
echo "finding expired certs..."
ALIASES=`keytool -list -v -keystore $FN -storepass changeit | grep -i 'alias\|until' | grep --before=1 'until.*2019' | grep Alias | awk -F': ' '{print $2}' | sort`
@grommitz
grommitz / JavaUtilBase64VsSunMiscBASE64
Last active March 28, 2018 16:43
Test to prove that java.util.Base64 class works identically to sun.misc.BASE64
@Test
public void testBase64() throws IOException {
String s = "the CAT sat on the MAT";
String enc = "dGhlIENBVCBzYXQgb24gdGhlIE1BVA==";
String sunMiscVersion = new String(new sun.misc.BASE64Decoder().decodeBuffer(enc), "utf8");
String commonsVersion = new String(Base64.getDecoder().decode(enc), "utf8");
Assert.assertThat(commonsVersion, is(sunMiscVersion));
Assert.assertThat(commonsVersion, is(s));
@grommitz
grommitz / RomanNumerals.kt
Created December 20, 2017 23:18
kata for converting an arabic integer to roman numerals see https://www.youtube.com/watch?time_continue=953&v=vX-Yym7166Y where it is done in ruby
import org.junit.Test
import kotlin.test.assertEquals
// kata for converting an arabic integer to roman numerals
// see https://www.youtube.com/watch?time_continue=953&v=vX-Yym7166Y
// where it is done in ruby
private val constants: Map<Int, String> = hashMapOf(
1 to "I",
4 to "IV",
@grommitz
grommitz / gist:9f0fdd38c10a0bb61e88
Last active December 20, 2017 23:23 — forked from raoulDoc/gist:fd997c5248285f903d65
fancy uses of collect in java 8 streams - done at a meetup with Raoul Gabriel Urma
@Test
public void mapEachTraderToTheSumOfTheirTransactions() {
//TODO: Create a Map<String, Integer> that maps each Trader's name with the sum of all its Transactions’ values
Map<String, Integer> mapNameToSumValue = new HashMap<>();
mapNameToSumValue =
transactions.stream()
.collect(groupingBy(transaction -> transaction.getTrader().getName(),
summingInt(transaction -> transaction.getValue())