Skip to content

Instantly share code, notes, and snippets.

@bennyhuo
bennyhuo / init.gradle.kts
Last active June 27, 2024 03:12
How to config mirrors for repositories in Gradle without changing the source code of your project?
fun RepositoryHandler.enableMirror() {
all {
if (this is MavenArtifactRepository) {
val originalUrl = this.url.toString().removeSuffix("/")
urlMappings[originalUrl]?.let {
logger.lifecycle("Repository[$url] is mirrored to $it")
this.setUrl(it)
}
}
}
@bigjosh
bigjosh / DistributedCounterDemo.ino
Last active December 22, 2020 18:26
Counts the number of connected nodes in a distributed and robust way. More info at https://forum.move38.com/t/yadca-yet-another-distributed-counting-algorithm/468
// SimpleCounter demo
// A simple distributed counter example
//
// On startup, blinks are dim BLUE which shows they are in IDLE mode waiting for a master
//
// Button press a blink to make it master of the cluster. The master will show the current count
// using the 0-342 display format decribed below under showNumber()...
//
// While a blink is actively part of a counting cluster, it will show dim GREEN on the face
// that points to its parent. All parent faces eventually lead back to the master.
@frgomes
frgomes / pattern_matching_on_runtimeClass.scala
Last active May 16, 2023 18:12
Scala - Pattern matching on a runtime class employing ClassTag and stable identifiers
import com.typesafe.config.Config
implicit class ImplicitConfigHelper(val c: Option[Config]) extends AnyVal {
import scala.reflect.ClassTag
import scala.util.control.NonFatal
import ImplicitConfigHelper._
implicit def valueOf[T : ClassTag](prop: String)(implicit ev: ClassTag[T]) : T =
ev.runtimeClass match { // you need stable identifiers here
case String_ => c.get.getString(prop).asInstanceOf[T]
case Int_ => c.get.getInt(prop).asInstanceOf[T]
@jbgi
jbgi / Term.java
Last active September 25, 2023 00:45
Generalized Algebraic Data Types (GADT) in Java
import static java.lang.System.*;
import java.util.function.BiFunction;
import java.util.function.Function;
// Implementation of a pseudo-GADT in Java, translating the examples from
// http://www.cs.ox.ac.uk/ralf.hinze/publications/With.pdf
// The technique presented below is, in fact, just an encoding of a normal Algebraic Data Type
// using a variation of the visitor pattern + the application of the Yoneda lemma to make it
// isomorphic to the targeted 'GADT'.