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
@japgolly
japgolly / Coyo.scala
Created March 12, 2014 07:53
Coyoneda natural transformations
object ForScalaz {
type CoyonedaF[F[_]] = ({type A[α] = Coyoneda[F, α]})
def FG_to_CFG[F[_], G[_] : Functor, A](t: F ~> G): (CoyonedaF[F]#A ~> G) = {
type CF[A] = Coyoneda[F, A]
type CG[A] = Coyoneda[G, A]
val m: (CF ~> CG) = FG_to_CFCG(t)
val n: (CG ~> G) = CF_to_F
val o: (CF ~> G) = n compose m
@japgolly
japgolly / JunctionExperiment.scala
Created March 30, 2014 10:01
JunctionExperiment
package scalaz.stream.merge
import scalaz.\/
import scalaz.stream.merge.Junction._
import scalaz.stream.Process._
object JunctionExperiment {
val debug = !true
@japgolly
japgolly / gist:816902779c457f25c87f
Last active August 29, 2015 14:02
CodecJson.xmap
case class Username(value: String)
implicit val usernameCodec = implicitly[CodecJson[String]].xmap(Username.apply)(_.value)
// ------------------------------------------------------------------------------------------------
// Would like to eventually like to do something like this:
// (Basically a replacement the {@@, T with U} hack which has caused me too many problems)
trait TaggedType { type U; def value: U }
trait TaggedTypeCtor[T <: TaggedType] { def apply(u: T#U): T }
@japgolly
japgolly / implicits.scala
Last active August 29, 2015 14:07
Scala implicit search path
package lib {
trait O[A]
object O {
import F.I
implicit val Il = null.asInstanceOf[I[Long]]
implicit val Ol = null.asInstanceOf[O[Long]]
}
trait T {
@japgolly
japgolly / migration.sh
Last active August 29, 2015 14:11
scalajs-react 0.7.0 migration
#!/bin/bash
find . -name '*.scala' -exec perl -pi -e '
s/(?!<[a-zA-Z0-9_"])onblur(?![a-zA-Z0-9_"])/onBlur/g;
s/(?!<[a-zA-Z0-9_"])onchange(?![a-zA-Z0-9_"])/onChange/g;
s/(?!<[a-zA-Z0-9_"])onclick(?![a-zA-Z0-9_"])/onClick/g;
s/(?!<[a-zA-Z0-9_"])ondblclick(?![a-zA-Z0-9_"])/onDblClick/g;
s/(?!<[a-zA-Z0-9_"])onfocus(?![a-zA-Z0-9_"])/onFocus/g;
s/(?!<[a-zA-Z0-9_"])onkeydown(?![a-zA-Z0-9_"])/onKeyDown/g;
s/(?!<[a-zA-Z0-9_"])onkeyup(?![a-zA-Z0-9_"])/onKeyUp/g;
@japgolly
japgolly / blah.scala
Created December 16, 2014 08:35
Quick script to decipher long Scala type errors
import scala.language._
import scala.annotation.tailrec
object Blah {
val errmsg = """
[error] found : blah.webapp.client.lib.ui.Editor[(blah.webapp.base.data.Validators.blar.scala.S, (String, String, blah.webapp.base.data.ImplicationRequired)),blah.webapp.client.app.ui.CfgBlars.fields.FieldValue,scalaz.effect.IO,blah.webapp.client.app.ui.CfgBlars.storesAndState.S,blah.webapp.client.app.ui.CfgBlars.fields.Field,scalaz.effect.IO[Unit],(japgolly.scalajs.react.vdom.ReactVDom.Tag, japgolly.scalajs.react.vdom.ReactVDom.Tag, japgolly.scalajs.react.vdom.prefix_<^.Tag)]
[error] (which expands to) blah.webapp.client.lib.ui.Editor[((Stream[blah.webapp.base.data.CustomBlar], Option[blah.webapp.base.data.CustomBlar.Id]), (String, String, blah.webapp.base.data.ImplicationRequired)),blah.webapp.client.app.ui.CfgBlars.fields.FieldValue,scalaz.effect.IO,blah.webapp.client.app.ui.CfgBlars.storesAndState.State,blah.webapp.client.app.ui.CfgBlars.fields.Field,scalaz.effect.IO[Unit],(japgolly.scalajs.react.vdom.ReactV
@japgolly
japgolly / gist:78507c5953d8f848f63c
Created February 28, 2015 21:30
Basic bootstrap NavBar model
// In Link & MenuItem, when onClick is None it means it should be disabled.
// This enforces the invariant that disabled items cannot be clicked.
// If you want something clickable but you want it to do nothing then pass it
// a callback that does nothing: Some(IO(()))
sealed trait NavItem
case class Link(label: String, onClick: Option[IO[Unit]], active: Boolean) extends NavItem
case class DropdownMenu(items: NonEmptyList[MenuItem]) extends NavItem
@japgolly
japgolly / ConsoleIO.scala
Created March 4, 2015 22:37
ConsoleIO.scala
package shipreq.webapp.client.lib
import org.scalajs.dom.console
import scala.annotation.elidable
import scala.scalajs.js
import scalaz.effect.IO
import js.{UndefOr, undefined}
trait ConsoleIO {
def info (msg: js.Any, extra: js.Any*) : IO[Unit]
@japgolly
japgolly / CssPager.scala
Created March 23, 2015 07:48
Chandu - CssPager
import japgolly.scalajs.react._, vdom.prefix_<^._, ScalazReact._
import japgolly.scalacss.Defaults._
import japgolly.scalacss.ScalaCssReact._
import shapeless.syntax.singleton._
object CssPager {
type CLICKEVENT = Int => Unit
object Style extends StyleSheet.Inline {
@japgolly
japgolly / DependencyLib.scala
Last active September 24, 2015 18:16
SBT JVM/JS DependencyLib
import sbt._
import scala.languageFeature._
import org.scalajs.sbtplugin.ScalaJSPlugin
import ScalaJSPlugin.autoImport._
object DependencyLib {
sealed trait HasDialect
sealed trait HasJvm extends HasDialect
sealed trait HasJs extends HasDialect