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 / Coyo.scala
Created Mar 12, 2014
Coyoneda natural transformations
View Coyo.scala
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
View JunctionExperiment.scala
package scalaz.stream.merge
import scalaz.\/
import scalaz.stream.merge.Junction._
import scalaz.stream.Process._
object JunctionExperiment {
val debug = !true
View gist:816902779c457f25c87f
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 Aug 29, 2015
Scala implicit search path
View implicits.scala
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 Aug 29, 2015
scalajs-react 0.7.0 migration
View migration.sh
#!/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 Dec 16, 2014
Quick script to decipher long Scala type errors
View blah.scala
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 Feb 28, 2015
Basic bootstrap NavBar model
View gist:78507c5953d8f848f63c
// 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
View 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 Mar 23, 2015
Chandu - CssPager
View CssPager.scala
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 Sep 24, 2015
SBT JVM/JS DependencyLib
View DependencyLib.scala
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
You can’t perform that action at this time.