Skip to content

Instantly share code, notes, and snippets.

@tabdulradi
tabdulradi / Usage.scala
Last active April 19, 2018 12:48
Function that allows values to be discarded in a visible way. Combined with Scalac flags: `-Ywarn-value-discard` (and maybe `-Xfatal-warnings`).
scala> ValueDiscard[Int](5)
scala> ValueDiscard(5)
<console>:12: error: ValueDiscard.type does not take parameters
ValueDiscard(5)
^
@tabdulradi
tabdulradi / scalac-compiler-flags-2.13.sbt
Last active November 24, 2022 07:39
Scala Compiler flags for 2.13. Based on Tpolecat's 2.12 version
scalacOptions ++= Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
// "-language:experimental.macros", // Allow macro definition (besides implementation and application). Disabled, as this will significantly change in Scala 3
"-language:higherKinds", // Allow higher-kinded types
// "-language:implicitConversions", // Allow definition of implicit functions called views. Disabled, as it might be dropped in Scala 3. Instead use extension methods (implemented as implicit class Wrapper(va
object TapirRefined extends TapirRefinedLowPriority {
implicit def posIntsCodecs[CF <: CodecFormat, R](implicit codec: Codec[Int, CF, R]): Codec[PosInt, CF, R] =
refineCodec(codec.validate(Validator.min(0)))
}
trait TapirRefinedLowPriority {
protected def refineCodec[T, CF <: CodecFormat, R, P](
codec: Codec[T, CF, R]
)(implicit refine: Validate[T, P]): Codec[T Refined P, CF, R] =
codec.mapDecode(
@tabdulradi
tabdulradi / README.md
Last active May 14, 2021 13:24
Scala Script Runner

Scala Script Runner

Make sure you have coursier installed

chmod +x test.scala
./test.scala

First time it will download scala-compiler (and depending on your config maybe GraalVM) then cache a bootstrap runner. Next time it will run much faster using the cached runner (depending on you config can be native program!).

@tabdulradi
tabdulradi / shell.nix
Last active January 25, 2022 15:02
Nix Shell for local development on Python projects. Ideal for mixed teams that doesn't have full Nix buy-in
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
python3
];
shellHook = ''
if [ -d ".venv" ]
then
echo "Using existing virtual env"