Skip to content

Instantly share code, notes, and snippets.

View japgolly's full-sized avatar
☠️
Non-existant

David Barri japgolly

☠️
Non-existant
View GitHub Profile
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 December 6, 2018 09:07
Graal docker alpine
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 November 11, 2018 08:16
Graal on Jetty (WEB-INF/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>
@japgolly
japgolly / logJvmInfo.scala
Created November 11, 2018 06:55
logJvmInfo()
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 March 31, 2018 09:46
SqlTracer export example
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 {
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 {
// ...
@japgolly
japgolly / boopickle.scala
Last active October 23, 2017 06:30
Fixpoint type serialisation
// Can't use the usual morphisms, cata = depth-first, ana = breadth-first evaluation order.
// You'd think there'd be a way to describe the effects and execute them in different order but I stopped trying.
def pickleFix[F[_]: Functor](implicit p: Pickler[F[Unit]]): Pickler[Fix[F]] =
new Pickler[Fix[F]] {
override def pickle(f: Fix[F])(implicit state: PickleState): Unit = {
// val fUnit = Functor[F].void(f.unfix)
// p.pickle(fUnit)
// Functor[F].map(f.unfix)(pickle)
@japgolly
japgolly / min.css
Created October 15, 2017 00:41
Sample ScalaCSS > 26
._b0{color:#000}._b2{color:#c00}._b3 svg{max-width:100%}._b4{width:24px !important;text-align:center !important}._b5{padding-bottom:1rem;padding-top:0.5rem}._b6:first-child{margin-top:0 !important}._b6:not(:first-child){margin-top:1.8em !important}._b6{margin-bottom:0.2em !important;padding-top:0.8em !important;padding-bottom:0.3em !important}._b7{margin-top:0 !important}._b8{cursor:pointer}._b9{text-align:center;padding-top:2.7em !important;height:6.8em !important;-moz-flex-grow:0 !important;-webkit-flex-grow:0 !important;-ms-flex-grow:0 !important;-o-flex-grow:0 !important;flex-grow:0 !important}._ba{font-size:3rem !important}._bb{border-color:red !important}._bc{margin-bottom:1em}._bc tr:nth-child(odd) td._s{background-color:#fffde8}._bc tr:nth-child(even) td._s{background-color:#def2fc}._bc tr:nth-child(odd) td._d{background-color:#fcf8e3}._bc tr:nth-child(even) td._d{background-color:#d9edf7}._bd{font-family:monospace;background-color:#fff}._be{font-family:monospace;white-space:nowrap;color:#f39}._bf{t
@japgolly
japgolly / eg.scala
Last active September 1, 2017 14:32
An Example of Functional Programming
// http://japgolly.blogspot.com.au/2014/09/an-example-of-functional-programming.html
sealed trait Validity
case object Valid extends Validity
case class Invalid(e1: String, en: List[String]) extends Validity
case class Validator[A](f: A => Validity) {
@inline final def apply(a: A) = f(a)
def +(v: Validator[A]) = Validator[A](a =>
@japgolly
japgolly / CallbackReusability.scala
Last active August 20, 2017 00:04
Callback Reusability
import japgolly.scalajs.react._
import japgolly.scalajs.react.extra._
import japgolly.scalajs.react.vdom.html_<^._
object NotReusable {
final case class Props(name: String, update: Callback)
final class Backend($: BackendScope[Props, Unit]) {
def render(p: Props): VdomElement =