bash
cd ~
git clone https://github.com/pedrolamas/klipper-virtual-pins.git
./klipper-virtual-pins/install.sh
This is a collection of the things I believe about software development. I have worked for years building backend and data processing systems, so read the below within that context.
Agree? Disagree? Feel free to let me know at @JanStette.
Keep it simple, stupid. You ain't gonna need it.
| object RuntimeUtils { | |
| def requestThreadDump: String = { | |
| // Get the PID of the current JVM process | |
| val selfName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName() | |
| val selfPid = selfName.substring(0, selfName.indexOf('@')) | |
| // Attach to the VM | |
| import com.sun.tools.attach.VirtualMachine | |
| import sun.tools.attach.HotSpotVirtualMachine; | |
| val vm = VirtualMachine.attach(selfPid); |
| // Alternative to sealed abstract case class pattern for Scala 2.12.2+ | |
| // Benefits: | |
| // - 1 final class instead of 1 sealed class + anonymous subclass | |
| // - portable to Scala 3 regardless of opaque types | |
| // - less boilerplate | |
| final case class Angle private (toDegrees: Int) { | |
| // Define our own `copy` method to suppress synthetic one | |
| // Add private to prevent it from being used | |
| def copy(degrees: Int = toDegrees): Angle = Angle.fromDegrees(degrees) |
| /* | |
| scalaVersion := "2.12.7" | |
| resolvers += Resolver.sonatypeRepo("snapshots") | |
| libraryDependencies += "co.fs2" %% "fs2-core" % "1.0.1-SNAPSHOT" | |
| */ | |
| import cats._ | |
| import cats.implicits._ | |
| import cats.effect._ |
| @ import $ivy.{`com.chuusai::shapeless:2.3.3`} | |
| import shapeless._, ops.hlist.Align, ops.hlist.SelectAll, SelectAll._ | |
| class Transform[T] { | |
| // The fun stuff. Given an S, returns a T, if S has the right (subset of) fields | |
| def apply[S, SR <: HList, TR <: HList](s: S)( | |
| implicit | |
| genS: LabelledGeneric.Aux[S, SR], |
There exist several DI frameworks / libraries in the Scala ecosystem. But the more functional code you write the more you'll realize there's no need to use any of them.
A few of the most claimed benefits are the following:
| val tree = "a.b().c".parse[Term].get | |
| pretty(tree) | |
| Term.Select( | |
| Term.Apply( | |
| Term.Select( | |
| Term.Name("a"), | |
| Term.Name("b") | |
| ), |
| package fix | |
| import scalafix._ | |
| import scala.meta._ | |
| case object Viewbounds_v1_0 extends Rule("Viewbounds_v1_0") { | |
| def eliminateViewBound(defn: Defn.Def): Option[Defn.Def] = { | |
| def makeimplicit(i: Int, from: Name, to: Type): Term.Param = { |
| -- Note: There is a more complete explanation at https://github.com/hwayne/lets-prove-leftpad/tree/master/idris | |
| import Data.Vect | |
| -- `minus` is saturating subtraction, so this works like we want it to | |
| eq_max : (n, k : Nat) -> maximum k n = plus (n `minus` k) k | |
| eq_max n Z = rewrite minusZeroRight n in rewrite plusZeroRightNeutral n in Refl | |
| eq_max Z (S _) = Refl | |
| eq_max (S n) (S k) = rewrite sym $ plusSuccRightSucc (n `minus` k) k in rewrite eq_max n k in Refl | |
| -- The type here says "the result is" padded to (maximum k n), and is padding plus the original |