Skip to content

Instantly share code, notes, and snippets.

View GenerateBeanCaseClass.scala
import java.beans.Introspector
import java.nio.file.{Files, Paths}
object GenerateBeanCaseClass extends App {
val typeRenderings = Map[Class[_], String](
classOf[String] -> "String",
classOf[Boolean] -> "Boolean",
classOf[Int] -> "Int"
)
View PartialState.scala
package chesednow.requests.sjs
import japgolly.scalajs.react.Callback
import japgolly.scalajs.react.vdom.VdomNode
import cats.implicits._
import monocle.{Iso, Prism}
trait PartialStateBase[V] {
type State
@nafg
nafg / SlickMetaGenPlugin.scala
Last active Aug 17, 2020
Simple code generator for Slick using Scalameta rather than strings, as an SBT plugin
View SlickMetaGenPlugin.scala
import java.sql.Types
import scala.annotation.tailrec
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import scala.meta._
import slick.dbio.DBIO
import slick.jdbc.meta.{MColumn, MQName, MTable}
View gist:2d37164b0b5501b417a6002dcaab4303
[1/547] mill.scalalib.ZincWorkerModule.compilerInterfaceClasspath
[2/547] mill.scalalib.ZincWorkerModule.classpath
[4/547] shared_common.js.upstreamCompileOutput
[5/547] shared_common.js.sources
[6/547] shared_common.js.generatedSources
@nafg
nafg / paramCodec.scala
Last active Mar 10, 2020
Deriving circe with Magnolia but only as a fallback
View paramCodec.scala
import scala.language.experimental.macros
import scala.reflect.ClassTag
import io.circe.{Decoder, Encoder, Json}
import magnolia._
class ParamEncoder[T](val underlying: Encoder[T]) extends AnyVal
trait ParamEncoderLowPriority {
type Typeclass[T] = ParamEncoder[T]
@nafg
nafg / gen-instructions.sbt
Last active Apr 1, 2020
Auto-generate your library's install instructions in README
View gen-instructions.sbt
val generateInstallInstructions = taskKey[Unit]("Generate install instructions in README.md")
generateInstallInstructions := {
val info = Def.task((projectID.value, description.value, (publish / skip).value)).all(ScopeFilter(inAnyProject)).value
val lines =
for ((moduleId, descr, noPublish) <- info.sortBy(_._1.name) if !noPublish) yield {
"// " + descr + "\n" +
s"""libraryDependencies += "${moduleId.organization}" %%% "${moduleId.name}" % "${moduleId.revision}""""
}
View groupme.sc
import scala.util.{Failure, Success}
import $ivy.`io.circe::circe-core:0.12.3`
import $ivy.`io.circe::circe-generic:0.12.3`
import $ivy.`io.circe::circe-parser:0.12.3`
import io.circe.{Decoder, Encoder}
import io.circe.generic.auto._
import io.circe.syntax._
import io.circe.parser
import requests.BaseSession
View some.scala
class SomeClass {
private def get(url: String): Future[Option[String]] =
for {
serviceResponse <- sendGetRequest(url)
} yield maybeBody(url, serviceResponse)
private def maybeBody(url: String, response: HttpResponse[String]): String =
if (response.is2xx) Some(response.body)
else None
View Webpack.sc
import java.io._
import java.util.zip.ZipInputStream
import geny.Generator
import mill._
import mill.define.{Target, Task}
import mill.scalajslib._
object WebpackLib {