Skip to content

Instantly share code, notes, and snippets.

View wafna's full-sized avatar

jason feingold wafna

  • Lewisburg, PA
View GitHub Profile
@wafna
wafna / gist:a691596b9c6cc12ca16d4fa383fbcf95
Created February 27, 2024 01:24
Create integrationTest source tree in Gradle with Kotlin DSL
val integrationTest = java.sourceSets.create("integrationTest").apply {
compileClasspath += sourceSets.test.get().compileClasspath
runtimeClasspath += sourceSets.test.get().runtimeClasspath
java.srcDirs("src/integration-test/kotlin")
}
tasks.create("integrationTest", Test::class) {
group = "verification"
description = "Runs integration tests."
testClassesDirs = integrationTest.output.classesDirs
interface MyContext {
fun boom()
}
// You can specify and bind the context explicitly...
context(MyContext)
fun contextualizedHigherOrderFunction1(f: MyContext.() -> Unit) {
// see https://github.com/Kotlin/KEEP/blob/master/proposals/context-receivers.md#referencing-specific-receiver
[email protected]()
}
@wafna
wafna / FormatterGenerator.kt
Last active December 12, 2022 19:08
Unit Formatter Generator
/**
* This generates formatting functions for applying aggregating units (e.g. Kilo, Mega)
* to values. If you run out of units it gives up and shows the unit value.
*
* @param base The unit base, e.g. 1024 for bytes, 1000 for metric units of measure.
* @param units the names of the units starting with the base unit (e.g. byte, meter).
*/
fun generateUnitFormatter(base: Int, units: List<String>): (Double, Int) -> String {
check(1 < base)
check(units.isNotEmpty())
@wafna
wafna / screenup.vbs
Created February 14, 2022 18:06
Screen Up Windows
Set WshShell = WScript.CreateObject("WScript.Shell")
While true
WScript.sleep 300000
WshShell.SendKeys "{BREAK}"
Wend
@wafna
wafna / MVar.js
Last active April 26, 2018 00:06
Proxy mutable state with notifications and transformations.
/*
MVar is a facility for data flow among components and APIs.
*/
const assertFunction = (f, msg) => {
if (typeof f !== 'function')
throw new Error('Function required: ' + msg);
};
/**
* Generically produces a new MVar chained after the given MVar.
* @param m The given MVar.