Skip to content

Instantly share code, notes, and snippets.

@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"
@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!).

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 / 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
@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 / keybase.md
Created October 7, 2017 09:44
keybase.md

Keybase proof

I hereby claim:

  • I am tabdulradi on github.
  • I am tabdulradi (https://keybase.io/tabdulradi) on keybase.
  • I have a public key ASBkIdYjb4IRe7DXOtrp_1ZSev9WYKBiZ8R-iSWKWa8kAAo

To claim this, I am signing this object:

@tabdulradi
tabdulradi / range-long-bug.scala
Last active November 19, 2016 21:24
Scala Range.Long min/max bug
scala> Range.Long.inclusive(111, 999, 1).max
res27: Long = 999
scala> Range.Long.inclusive(111, 999, -1).max
res28: Long = 111
scala> Range.Long.inclusive(111, 999, 1).min
res29: Long = 111
scala> Range.Long.inclusive(111, 999, -1).min
@tabdulradi
tabdulradi / troy-abstract.md
Last active November 15, 2016 11:09
Troy Abstract

Introducing Troy: The schema-safe Cassandra toolkit.

Troy is an open source macro-based Cassandra driver, similar to Slick and Quill, provides type-safe & compile-time checking for database queries. Nevertheless, it doesn't impose a DSL to express the queries in Scala. Instead, it allows developers to write plain Cassandra-query-language (CQL) queries within Scala code, complete with schema validation. In addition, it provides cross-validation against the previous versions, ensuring safe and smooth schema migrations.

It is worth noting that Troy doesn't connect to Cassandra during compilation. Instead, the schema is provided as CQL scripts, checked-in within same code base, consisting of plain CREATE TABLE CQL statements. That get's loaded at compile-time into a light-weight Schema engine capable of analysing queries and providing information about column types. Those CQL scripts can be written as increments, by adding new scripts containing `ALTER TA

@tabdulradi
tabdulradi / CompositeRouter.scala
Last active March 5, 2018 06:08
Utility Play routes that makes it prettier to combine routes together
class CompositeRouter(routers: Seq[Router]) extends SimpleRouter {
override def documentation: Seq[(String, String, String)] =
routers.flatMap(_.documentation)
override def routes: Router.Routes =
routers.map(_.routes).fold(Router.empty.routes)(_ orElse _)
}
object CompositeRouter {
def fromPrefixedRoutes(routers: (String, Router.Routes)*): CompositeRouter =
@tabdulradi
tabdulradi / ComposingRoutes.scala
Last active May 23, 2016 12:35
Cake Blog: All you need to know about Play SIRD
val service1 = Router.from {
case GET(p"hello/$to") => ???
}
val service2 = Router.from {
case GET(p"echo/$msg") => ???
}