Skip to content

Instantly share code, notes, and snippets.

@arturaz
arturaz / Matching.scala
Created September 22, 2013 09:59
Matching ADT with Scala
private def getLeaderboardName(kind: Kind, lbKind: LeaderboardKind) = kind match {
case kg @ Kind.Global =>
LeaderboardName(s"lb_${leaderboardKindToString(lbKind)}", lbKind)
case Kind.World(w) =>
LeaderboardName(s"lb_w${w}_${leaderboardKindToString(lbKind)}", lbKind)
case Kind.Level(w, l, b) =>
LeaderboardName(
s"lb_w${w}_l$l${if (b) "b" else "")}_${leaderboardKindToString(lbKind)}",
lbKind
)
@arturaz
arturaz / ADT.cs
Created September 22, 2013 09:55
Defining same ADT in C# and Scala
public abstract class Kind {
public class Global : Kind {}
public class World : Kind {
public readonly int world;
public World(int world) {
this.world = world;
}
}
using System;
using UnityEngine;
class TestCallback {
public static AndroidJavaObject apply<T1, T2>(Action<T1, T2> action) {
var cb = new AndroidJavaObject("TestCallback");
cb.Call("setRunnable", new AndroidJavaRunnable(() => {
var p1 = cb.Call<T1>("getParam1");
var p2 = cb.Call<T2>("getParam2");
action.Invoke(p1, p2);
using System;
using UnityEngine;
namespace com.tinylabproductions.u3d_gps_bridge {
public class ConnectionCallbacks : AndroidJavaProxy {
public ConnectionCallbacks() :
base("com.tinylabproductions.u3d_gps_bridge.ConnectionCallbacks")
{}
public Action OnConnected = delegate {};
@arturaz
arturaz / gist:6112400
Created July 30, 2013 12:13
Scala project preparation for dist archive
val chiShape = RootProject(file("vendor/chi-shape"))
val kdTree = RootProject(file("vendor/kdtree"))
val messaging = RootProject(file("vendor/messaging"))
val datadog = RootProject(file("vendor/datadog-metrics-client"))
val logbackLayout = RootProject(file("vendor/logback-layout"))
dist <<= (
dist,
packageBin in Compile in chiShape,
@arturaz
arturaz / ubuntu-install-java7.yml
Last active December 15, 2015 10:09
Ansible task file for installing java7 on ubuntu.
---
- name: ensuring add-apt-repository is installed
apt: pkg=python-software-properties state=latest
- name: adding webupd8 ppa for java7 installer
apt_repository: repo=ppa:webupd8team/java
- name: updating apt cache
apt: update_cache=yes
case class ViewRow[K, V, D](id: String, key: K, value: V, doc: Option[D])
def viewRowFormat[K : Format, V : Format, D : Format] = (
(__ \ 'id).format[String] ~
(__ \ 'key).format[K] ~
(__ \ 'value).format[V] ~
(__ \ 'doc).formatNullable[D]
).apply(ViewRow.apply, unlift(ViewRow.unapply[K, V, D]))
@arturaz
arturaz / gist:5007515
Created February 21, 2013 19:41
Serialising case class with Either to JSON in play framework 2.1 scala
package models
import play.api.libs.json._
import play.api.libs.json.Json._
import play.api.libs.functional.syntax._
import org.apache.commons.codec.binary.Base64
/**
* Created with IntelliJ IDEA.
* User: arturas
@arturaz
arturaz / json.scala
Last active December 14, 2015 00:38
object Model {
trait Mutation[A]{
val doc: A
}
case class Upsert[A](doc: A) extends Mutation[A]
case class Delete[A](doc: A) extends Mutation[A]
// Json format
package com.wierd
import org.openqa.selenium
import org.scalatest.selenium.Firefox
object FFTest extends Firefox {
def main(args: Array[String]): Unit = {
webDriver.manage.window.setSize(new selenium.Dimension(1200, 800))