Skip to content

Instantly share code, notes, and snippets.

@pfn
pfn / gist:1690765
Created Jan 27, 2012
listener queue with weak reference to anonymous functions
View gist:1690765
object E {
class O {
val listeners = new ArrayBuffer[E.H]
}
trait RO {
implicit val __ERO__ = new O
}
type H = PartialFunction[Any,Any]
}
abstract class E {
View gist:1762813
def using[A <: { def close() }](closeable: => A)(f: A => Unit) {
var c: Option[A] = None
try {
c = Option(closeable)
c foreach f
} finally {
c foreach(_.close)
}
}
@pfn
pfn / AndroidConversions.scala
Created Feb 7, 2012
AndroidConversions.scala
View AndroidConversions.scala
package com.hanhuy.android.irc
import android.app.Activity
import android.app.ActionBar
import android.content.Intent
import android.content.Context
import android.content.BroadcastReceiver
import android.content.res.Configuration
import android.os.AsyncTask
import android.os.Build
@pfn
pfn / EventBus.scala
Created Feb 15, 2012
EventBus.scala
View EventBus.scala
package com.hanhuy.android.irc
import model.BusEvent
import AndroidConversions._
import android.os.{Handler, Looper}
import android.util.Log
import scala.collection.mutable.{ArrayBuffer,SynchronizedBuffer}
@pfn
pfn / build.scala
Created Feb 24, 2012
multi-project build.scala
View build.scala
import sbt._
import sbt.Keys._
import AndroidKeys._
/*
* this represents a multi-project structure like:
* - root-project (wrapper/meta project)
* `- lite (android project)
* `- common (android library-project)
@pfn
pfn / build.sbt
Created Apr 26, 2012
sbt configuration for testing with robolectric
View build.sbt
import AndroidKeys._
libraryDependencies ++= Seq(
"com.pivotallabs" % "robolectric" % "1.1" % "test",
"junit" % "junit" % "4.8.2" % "test",
"xpp3" % "xpp3" % "1.1.4c" % "test",
"org.scalatest" %% "scalatest" % "1.7.1" % "test"
)
seq(androidBuildSettings: _*)
View RobolectricSuite.scala
import org.scalatest.Suite
import org.scalatest.Reporter
import org.scalatest.Stopper
import org.scalatest.Filter
import org.scalatest.Tracker
import org.scalatest.Distributor
import com.xtremelabs.robolectric.Robolectric
import com.xtremelabs.robolectric.ApplicationResolver
import com.xtremelabs.robolectric.RobolectricConfig
@pfn
pfn / jdb.bat
Created Sep 25, 2012
jdb over adb for android
View jdb.bat
@echo off
setlocal
adb kill-server
adb start-server
for /f "delims=" %%i in ('adb jdwp') do set pid=%%i
adb -d forward tcp:29882 jdwp:%pid%
jdb -J-Duser.home=. -connect com.sun.jdi.SocketAttach:hostname=localhost,port=29882 -sourcepath %*
@pfn
pfn / elo.py
Created Dec 7, 2012
slightly revised elo simulation.
View elo.py
#!/usr/bin/python
import random
def simulate():
start = 1200
elo = start
elo40 = elo
elo100 = elo
elo500 = elo
k = 80
@pfn
pfn / build.scala
Last active Dec 11, 2015
another multi-project/complex build.scala for android
View build.scala
import sbt._
import sbt.Keys._
import AndroidKeys._
object ComplexBuild extends Build {
lazy val rootSettings = Seq(
packageT in Compile <<= packageT in Android in app,
packageRelease <<= packageRelease in Android in app,
packageDebug <<= packageDebug in Android in app,