Skip to content

Instantly share code, notes, and snippets.

David Barri japgolly

Block or report user

Report or block japgolly

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@japgolly
japgolly / copy.sbt
Last active Oct 1, 2019
Scala.JS & SBT
View copy.sbt
// Assumptions:
// 1. You have one or more Scala.JS modules named jsModule1, jsModule2, ...
// 2. You have a web-serving (or otherwise JVM) module that will serve the JS assets
// The only "webby"/JS plugin I use apart from Scala.JS itself, is xsbt-web-plugin,
// and even that, only on my pre-http4s projects.
// xsbt-web-plugin allows me to quickly stop/start a servlet container from SBT.
// The snippet below is for "webappPostProcess" which is an xsbt-web-plugin task but
// if you aren't using it, you can just create a task with the same content and make
// "package" depend on it.
@japgolly
japgolly / 0.deps.gv.svg
Last active Oct 9, 2019
Japgolly libs => Scala 2.13
View 0.deps.gv.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@japgolly
japgolly / upgrade.md
Last active Sep 9, 2019
Scala 2.13 migration notes
View upgrade.md

scalafix

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.6")
import scalafix.sbt.ScalafixPlugin.autoImport.{scalafixDependencies, scalafixSemanticdb}

scalafixDependencies in ThisBuild += "org.scala-lang.modules" %% "scala-collection-migrations" % "2.1.1",
View Template.scala
package shipreq.base.util
import java.util.UUID
import scalaz.Functor
import scalaz.syntax.functor._
import scalaz.Scalaz.Id
/** Takes a potentially slow `String* => String` function and makes it super fast by executing it once,
* turning the result into a template, then using the template for all subsequent calls.
*
@japgolly
japgolly / .bashrc
Created Dec 6, 2018
Graal docker alpine
View .bashrc
export PS1='\n\[\e[32m\]\u@\h: \[\e[33m\]\w\[\e[0m\]\n> '
export BASH=/bin/bash
export SHELL=$BASH
export LS_OPTIONS='--color=auto'
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias la='ls $LS_OPTIONS -la'
@japgolly
japgolly / jetty-web.xml
Created Nov 11, 2018
Graal on Jetty (WEB-INF/jetty-web.xml)
View jetty-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Call name="addSystemClass">
<Arg>org.graalvm.</Arg>
</Call>
</Configure>
View logJvmInfo.scala
def logJvmInfo(): Unit = {
val header: List[String] =
"System Property" :: "Value" :: Nil
val data: List[List[String]] =
sys.props
.filterKeys(_.matches("""^(java\.(runtime|spec|version|vm)|jvmci|os\.).*"""))
.toList
.sorted
.map(x => x._1 :: x._2 :: Nil)
@japgolly
japgolly / SqlTracer-manual.scala
Created Mar 31, 2018
SqlTracer export example
View SqlTracer-manual.scala
import java.io.{Closeable, InputStream, PrintWriter, Reader}
import java.net.URL
import java.sql.{Blob, CallableStatement, Clob, Connection, DatabaseMetaData, Date, NClob, ParameterMetaData, PreparedStatement, Ref, ResultSet, ResultSetMetaData, RowId, SQLWarning, SQLXML, Savepoint, Statement, Struct, Time, Timestamp}
import java.util.{Calendar, Properties}
import java.{sql, util}
import java.util.concurrent.Executor
import java.util.logging.Logger
import javax.sql.DataSource
trait SqlTracer {
View stateful_spa.scala
// Overview of how this works:
// 1. Initialisation data is used to create an instance of LoadedRoot.
// 2. LoadedRoot contains a component which is the virtual top-level component.
// It uses the initialisation data and can be sure that it won't change (a guarantee you don't have with component props).
// It's the only component to have state.
// The state can applies to the entire SPA, all routes.
// It gets told by the router which page to render.
// It can house logic that applies when certain pages change to certain other pages.
// 3. LoadedRoot is passed to Routes.routerConfig.
// Routes.routerConfig creates a config that sends all routes to the LoadedRoot component, using the Page & RouterCtl as props.
View BinCodecGeneric.scala
package shipreq.webapp.base.protocol
import boopickle._
object BinCodecGeneric extends BasicImplicitPicklers with TuplePicklers {
@inline implicit class PicklerExt[A](private val p: Pickler[A]) extends AnyVal {
// ...
You can’t perform that action at this time.