Skip to content

Instantly share code, notes, and snippets.

/*
Circular Equalizer
Copyright (C) 2023 Hannah Kolbeck
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@hkolbeck
hkolbeck / SharingIsCaring.kt
Last active June 22, 2023 19:44
A sketch of a system for sharing buffers where they pass through a broadcast and are only returned to the pool once all expected consumers have handled them
package industries.hannah.pixelblaze.sensor
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import java.io.Closeable
import java.util.*
import java.util.concurrent.ArrayBlockingQueue
import java.util.concurrent.ConcurrentHashMap
@hkolbeck
hkolbeck / CachingRwLock.kt
Last active June 20, 2023 07:15
Kotlin and Rust Read-Write locks where readers never block, though values may be stale
package industries.hannah.cachelock
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.locks.Condition
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock
/**
* A Read-Write lock designed to allow readers to proceed unblocked while writers are manipulating the guarded
* data. As a first go-round this requires that all operations take place in a provided lambda. Unlike Rust

Hannah's Learn-A-New-Language Exercises

Tag Server

Write a REST backend exposing a user tagging API. Exactly how to store the data backing the API is left as an exercise for the user, and depends on whether there are storage technologies you're interested in exploring. I frequently just use in-memory data structures.

package com.urbanairship.goro.task;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import java.io.BufferedReader;
import java.io.BufferedWriter;
#!/bin/bash
set -e
PATTERN=`echo $@ | tr ' ' '|'`
if [ -z "${PATTERN}" ]; then
cat -
exit $?
fi
package testing.integration;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.shade.com.google.common.collect.ImmutableList;
import org.apache.storm.shade.com.google.common.collect.Maps;
import org.apache.storm.trident.TridentTopology;
import org.apache.storm.trident.operation.TridentCollector;
import org.apache.storm.trident.state.BaseStateUpdater;
java.lang.RuntimeException: java.lang.UnsupportedOperationException: nth not supported on this type: AddressedTuple
at org.apache.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:464) ~[storm-core-1.0.2.jar:1.0.2]
at org.apache.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:430) ~[storm-core-1.0.2.jar:1.0.2]
at org.apache.storm.disruptor$consume_batch_when_available.invoke(disruptor.clj:73) ~[storm-core-1.0.2.jar:1.0.2]
at org.apache.storm.disruptor$consume_loop_STAR_$fn__7509.invoke(disruptor.clj:83) ~[storm-core-1.0.2.jar:1.0.2]
at org.apache.storm.util$async_loop$fn__624.invoke(util.clj:484) [storm-core-1.0.2.jar:1.0.2]
at clojure.lang.AFn.run(AFn.java:22) [clojure-1.7.0.jar:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_92]
Caused by: java.lang.UnsupportedOperationException: nth not supported on this type: AddressedTuple
at clojure.lang.RT.nthFrom(RT.java:933) ~[clojure-1.7.0.jar:?]
for pom in `git ls-tree -r --name-only --full-tree ${COMMIT} | grep 'pom.xml$'`; do
DIR=`dirname ${pom}`
if [ ${DIR} != '.' ]; then
mkdir ${TMP_DIR}/${DIR}
fi
git show ${COMMIT}:${pom} > ${TMP_DIR}/${pom}
done
__________________
\ ) \
\ ( ( \
\ ) \
( ( \
/----------------) /\ -(-------------
//---------------/( // | (`' / |
// /_ -.;_/ \\--._ / __|
// //(_;-// | \ \-'.\ / / ||
// // ( `.__ _ ___,') / / ||