Skip to content

Instantly share code, notes, and snippets.

def lastModifiedDate(app: ApplicationInfo) = (new File(app.sourceDir)).lastModified()
val sortedApps = repository.all.sortWith(lastModifiedDate(_) > lastModifiedDate(_))
VS
private List<ApplicationInfo> getApplicationsSortedByDate(List<ApplicationInfo> apps) {
Comparator<ApplicationInfo> dateComparator = new Comparator<ApplicationInfo>() {
public int compare(ApplicationInfo appInfo1, ApplicationInfo appInfo2) {
long date1 = new File(appInfo1.sourceDir).lastModified();
def createRemoteViews(): RemoteViews = {
val views = new RemoteViews(context.getPackageName(), R.layout.latest_apps)
views.removeAllViews(R.id.buttons)
dao.latestApps.take(4) foreach (appInfo => views.addView(R.id.buttons, createAppRemoteView(appInfo)))
views.setViewVisibility(R.id.buttons, android.view.View.VISIBLE)
return views
}
package com.nevercertain.pro.latestapps
import android.content._
import android.app._
import android.appwidget._
import android.util.Log
import java.util.Calendar
import java.text.SimpleDateFormat
import collection.JavaConversions._
@jbrechtel
jbrechtel / NetworkParserSpecs.scala
Created January 22, 2011 16:49
Specs for NetworkParser.scala
package com.nevercertain.wifipasswords
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.Spec
class NetworkParserSpecs extends Spec with ShouldMatchers {
val singleNetwork = """
network={
ssid="Futurama"
psk="Bite my shiny metal ass"
@jbrechtel
jbrechtel / lambdas.scala
Created January 22, 2011 16:35
lambdas (anonymous functions) in scala
val nums = List(10,21,23,35,40)
//signature of filter: def filter (p: (A) ⇒ Boolean) : Seq[A]
nums.filter(_ > 25) //List(35, 40)
nums.filter((x: Int) => (x % 5) == 0) //List(10,35,40)
def even(x: Int) = (x % 2) == 0
nums.filter(even) //List(10,40)
package com.nevercertain.wifipasswords
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.Spec
class WifiNetworkSpecs extends Spec with ShouldMatchers {
describe("comparing a network") {
it("should be equal to a network whose name differs only in case") {
val network1 = new WifiNetwork("R", "111", NetworkType.OPEN)
val network2 = new WifiNetwork("r", "111", NetworkType.OPEN)
package com.nevercertain.wifipasswords
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.Spec
class NetworkParserSpecs extends Spec with ShouldMatchers {
it("should create a WEP network with the expected password") {
val wepNetwork = """
network={
ssid="joes wifi"
trait Ordered[A] {
def compare(that: A): Int
def < (that: A): Boolean = (this compare that) < 0
def > (that: A): Boolean = (this compare that) > 0
def <= (that: A): Boolean = (this compare that) <= 0
def >= (that: A): Boolean = (this compare that) >= 0
}
}
class Person(val name: String) extends Ordered[Person] {
Download Scala at: http://bit.ly/a5LOj
Download ScalaTest at: http://bit.ly/gH5X0s
Download SBT at: http://bit.ly/cNBQ14
import org.scalatest.Spec
import org.scalatest.matchers.ShouldMatchers
class BowlingGameSpecs extends Spec with ShouldMatchers {
describe("Playing a game") {
it("should have a score of zero for a game with all zero rolls") {
val game = new BowlingGame(List(0,0,0,0,0,0,0,0,0,0)
game.score should equal(0)
}