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 / 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]]
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.
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.
@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
@Override
protected void onStop() {
// Release memory held by background bitmaps
AndroidUtils.releaseBackgroundImageMemory(root);
AndroidUtils.releaseBackgroundImageMemory(decorFrame);
super.onStop();
}
@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);
}
@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 *; }
DENSITIES= {
'-mdpi' => 1.0,
'-ldpi' => 0.75,
'-hdpi' => 1.5,
'-xhdpi' => 2.0,
}
def run_cmd(cmd)
puts cmd
system cmd
@japgolly
japgolly / mvnc.sh
Last active October 12, 2015 23:28
Mvn colour script
#!/bin/bash
RESET="\e[0m"
BLACK="\e[0;30m"
RED="\e[0;31m"
GREEN="\e[0;32m"
YELLOW="\e[0;33m"
BLUE="\e[0;34m"
MAGENTA="\e[0;35m"
CYAN="\e[0;36m"