Skip to content

Instantly share code, notes, and snippets.

diff --git a/src/OnboardingWebTests/ControllerTests/CompanyControllerTest.cs b/src/OnboardingWebTests/ControllerTests/CompanyControllerTest.cs
index e52a78a..01d9055 100644
--- a/src/OnboardingWebTests/ControllerTests/CompanyControllerTest.cs
+++ b/src/OnboardingWebTests/ControllerTests/CompanyControllerTest.cs
@@ -1,6 +1,7 @@
using System.IO;
using System.Linq;
using System.Web.Mvc;
+using Moq;
using NUnit.Framework;
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 / NetworkParser.scala
Created January 22, 2011 16:25
wpa_supplicant.conf parser in scala
package com.nevercertain.wifipasswords
import scala.collection.JavaConversions._
object NetworkParser {
def parse(networksString: String): Seq[WifiNetwork]= {
val networkSections = networksString.split("network=").filter(_.trim.size > 0)
networkSections.map((networkSection: String) => {
val name = parseToken(networkSection, "ssid")
@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)
@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"
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] {