Skip to content

Instantly share code, notes, and snippets.

View benjishults's full-sized avatar

Benjamin Shults benjishults

  • SmartThings Inc.
View GitHub Profile
@benjishults
benjishults / coroutine cancellation
Created October 12, 2023 20:29
Demonstrating that all coroutines are canceled even though I'm throwing away all the [kotlinx.coroutines.CancellationException]s
import kotlinx.coroutines.*
/**
* Demonstrating that all coroutines are canceled even though I'm throwing away all the [kotlinx.coroutines.CancellationException]s
*/
suspend fun main() {
try {
coroutineScope {
val job1 = launch {
val job4 = launch {
@benjishults
benjishults / Auditable.kt
Created July 8, 2021 19:46
Auditable trait
package benjishults.traits
import java.time.Instant
interface Auditable {
val created: Instant
val lastModified: Instant
companion object : (Instant, Instant?) -> Auditable {
override fun invoke(created: Instant, lastModified: Instant?): Auditable =
@benjishults
benjishults / PrimitiveRecursiveArithmetic.kt
Created July 8, 2021 19:24
Primitive Recursive Arithmetic
package benjishults.pra
// when people claim it takes 300 pages to prove that 2+2=4, show them this:
// definition of non-negative integers
sealed interface NonNegativeInteger {
// every non-negative integer has a successor
fun successor(): PositiveInteger =
PositiveInteger(this)
@benjishults
benjishults / karabiner.json
Last active September 23, 2022 16:20
for PC keyboard
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false,
"unsafe_ui": false
},
"profiles": [
{
"complex_modifications": {
@benjishults
benjishults / keybase.md
Created September 24, 2019 20:16
keybase.md

Keybase proof

I hereby claim:

  • I am benjishults on github.
  • I am benjishults (https://keybase.io/benjishults) on keybase.
  • I have a public key whose fingerprint is 1974 71B9 AF07 216D A15C 52C2 32FA 983E 9B0D EF24

To claim this, I am signing this object:

@benjishults
benjishults / pullUpstream.sh
Created April 5, 2019 13:34
pull upstream
#!/bin/bash
# put this file in the folder containing your repo folders.
# when run, it will try to do a git pull upstream of the current branch of each repo and print a message on each failure.
pushd . &> /dev/null
for dir in $( find . -maxdepth 1 -type d -print )
do
popd &> /dev/null
pushd "$dir" &> /dev/null
@benjishults
benjishults / checkStash.sh
Last active April 5, 2019 13:33
check whether there is a stash in the current branch
#!/bin/bash
# put this file in the folder containing your repo folders.
# when run, it will check whether there is a stash in the current branch
pushd . &> /dev/null
for dir in $( find . -maxdepth 1 -type d -print )
do
popd &> /dev/null;
pushd "$dir" &> /dev/null;
@benjishults
benjishults / Application.java
Created December 31, 2018 18:08
Application second pass in enum refactor demo
public static void main(String[] args) {
Path file = Path.of(args[0]);
processorFactory(file).processFile(file);
}
@benjishults
benjishults / TextProcessor.java
Created December 31, 2018 18:06
TextProcessor in enum refactor demo
public class TextProcessor implements Processor {
@Override
public void processFile(Path file) {
System.out.println("process text file");
}
}
@benjishults
benjishults / DocumentType.java
Created December 31, 2018 18:05
DocumentType second pass in enum refactor demo
public enum DocumentType implements Processor {
TXT("txt", "text") {
@Override
public void processFile(Path file) {
System.out.println("process text file");
}
},
MD("md", "markdown") {
@Override
public void processFile(Path file) {