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 / proguard-dev.cfg
Last active December 12, 2015 08:49
Proguard configs
# Dalvik VM specific
-dontpreverify
# Dev-only
-dontobfuscate
-dontoptimize
# My stuff
-keep public class golly.** { public protected *; }
-keep public class com.beardedlogic.** { public protected *; }
@japgolly
japgolly / BaseActivity.java
Created April 16, 2013 09:37
onGlobalLayout()
protected static final int IGNORE_BACKGROUND_WIDTH_CHANGES = 1 << 1;
protected static final int IGNORE_BACKGROUND_HEIGHT_CHANGES = 1 << 2;
private View globalLayoutView;
protected int globalLayoutWidth = -1, globalLayoutHeight = -1;
private int globalLayoutFlags = 0;
protected void addGlobalLayoutListener(View globalLayoutView) {
addGlobalLayoutListener(globalLayoutView, 0);
}
@Override
protected void onStop() {
// Release memory held by background bitmaps
AndroidUtils.releaseBackgroundImageMemory(root);
AndroidUtils.releaseBackgroundImageMemory(decorFrame);
super.onStop();
}
@japgolly
japgolly / BandData.scala
Last active December 22, 2015 07:08
KeyedLens example
case class Person(name: String)
case class Guitar(strings: Int, tuning: String, gauges: List[Double])
case class Band(name: String,
members: Map[Person, Guitar],
otherPeopleWhoSupportTheGuitarists: Set[Person]) // Just ask Yngwie
// Sample data
val bandNameL = lensg[Band, String](b => n => b.copy(name = n), _.name)
val guitarTuningL = lensg[Guitar, String](g => t => g.copy(tuning = t), _.tuning)
// KeyedLens #1: Here Person is a key.
val guitarL = KeyedLens[Band, Person, Guitar](
b => p => newValue => b.copy(members = b.members + (p -> newValue)),
b => p => b.members(p))
// KeyedLens #2: Here Int is the key.
import scalaz.{LensFamily, Lens}
import Lens.{lensg, lensFamilyg}
object LensFns {
/**
* A lens that requires a key be provided to extract B from A.
*
* @tparam A The record type.
* @tparam K The field key type.
@japgolly
japgolly / blah.scala
Created September 24, 2013 01:14
Recursive types experimentation
object `^_^` {
trait Token
trait Value extends Token
trait P[A <: Token, B <: Value] extends Token
trait I[T <: Token]
// Conversions
implicit def AB_A[A <: Value, B <: Value](i: I[P[A, B]]): I[A] = i.asInstanceOf[I[A]]
implicit def AB_B[A <: Token, B <: Value](i: I[P[A, B]]): I[B] = i.asInstanceOf[I[B]]
@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 }