Skip to content

Instantly share code, notes, and snippets.

View JavadocMD's full-sized avatar

Tyler JavadocMD

View GitHub Profile
@JavadocMD
JavadocMD / Login.cs
Created June 20, 2017 23:33
Use of a partial class to implement platform-specific logic in Unity.
namespace Login {
public static partial class Login {
// Call this from the outside to log in
public static void LogIn() {
DoLogIn();
}
// Implementation delegate
@JavadocMD
JavadocMD / sof.scala
Created November 3, 2016 02:15
Sequence of Futures
def details(since: Option[LocalDate], until: Option[LocalDate], page: Int): Future[NumberedDetailsPage] = { ... }
details(since, until, 1).flatMap { page1 =>
val pagesFuture = Future.sequence(
for {
n <- (2 to page1.details.totalPages).toList
} yield {
details(since, until, n)
}
@JavadocMD
JavadocMD / Main.scala
Last active April 26, 2016 22:50
Application of type classes for intersecting Shapes, inspired by http://eli.thegreenplace.net/2016/a-polyglots-guide-to-multiple-dispatch
// Define our shapes.
trait Shape
class Rectangle extends Shape
class Ellipse extends Shape
class Triangle extends Shape
object Shape {
// The method we'll call to perform an intersection.
def intersect[A <: Shape, B <: Shape](a: A, b: B)(implicit ev: Intersection[A,B]): Unit = {
@JavadocMD
JavadocMD / Example.cs
Created August 3, 2015 23:47
UniRx issue
public class GameModel : MonoBehaviour {
public FloatReactiveProperty Score { get; private set; }
void Awake() {
Score = new FloatReactiveProperty(0f).AddTo(this);
}
}
public class ScoreUI : MonoBehaviour {
@JavadocMD
JavadocMD / FileManager.scala
Created June 11, 2015 01:36
Example of combining Observables and Actors for a workflow.
package com.ornithoptergames.psav
import java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import com.beachape.filemanagement.RxMonitor
import com.ornithoptergames.psav.FrameInfoLoader._
import com.ornithoptergames.psav.Messages._
import com.ornithoptergames.psav.RxMessage.Implicits._
import akka.actor.ActorSystem
@JavadocMD
JavadocMD / picks.scala
Last active August 29, 2015 14:15
Picking items from a list one-by-one
// Combining a list of options...
val options = List("a", "b", "c", "d")
// ... with a sequence of "picks" to make...
val choices = List(0, 2, 1, 0)
// ... should yield a re-ordered list as so.
val expects = List("a", "d", "c", "b")
// Assume we don't have to worry about out-of-bounds choices.
// worked example:
// pick 0 from {a,b,c,d} -> a
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture;
uniform sampler2D u_mask;
varying vec4 v_color;
varying vec2 v_texCoord0;
uniform mat4 u_projTrans;
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
varying vec4 v_color;
varying vec2 v_texCoord0;
void main()
def parse(s: String): List[List[Long]] =
s.lines.map(_.split(" ").map(_.toLong).toList).toList
def pairwiseChoose(row: List[Long]): List[Long] =
(row.sliding(2).map { case a :: b :: Nil => max(a, b) }).toList
case class Foo(val x: Int, val y: Int)
class Bar(val f: Foo, val s: String)
object Bar {
def apply(x: Int, y: Int, s: String): Bar = new Bar(Foo(x, y), s)
def unapply(b: Bar): Option[(Int, Int, String)] = Some((b.f.x, b.f.y, b.s))
}
val a = Bar(1, 2, "A")