This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Download Scala at: http://bit.ly/a5LOj | |
| Download ScalaTest at: http://bit.ly/gH5X0s | |
| Download SBT at: http://bit.ly/cNBQ14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fsc *.scala -classpath scalatest-1.3.jar | |
| scala -cp scalatest-1.3.jar org.scalatest.tools.Runner -p . -o -s BowlingGameSpecs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.collection.mutable._ | |
| class BowlingGame(val reverseRolls: List[Int]) { | |
| def roll(pins: Int) = { | |
| if(pins == 10) | |
| new BowlingGame(0 :: pins :: reverseRolls) | |
| else | |
| new BowlingGame(pins :: reverseRolls) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BowlingGame | |
| def initialize | |
| @all_rolls = [] | |
| end | |
| def roll(pins) | |
| @all_rolls << pins | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.collection.mutable._ | |
| class BowlingGame { | |
| val allRolls = new ListBuffer[Int]() | |
| def roll(pins: Int) = allRolls.append(pins) | |
| def score() = buildFrameScores(allRolls.toList).slice(0,10).sum | |
| def buildFrameScores(rolls: List[Int]):List[Int] = { | |
| if(rolls.isEmpty) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | |
| (1 to 20).map(i => 0).foreach(game.roll) | |
| game.score should equal(0) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.foo.bar; | |
| import android.os.AsyncTask; | |
| import android.util.Log; | |
| public abstract class SimpleTask extends AsyncTask<Void, Void, Boolean> { | |
| private final AsyncTask waitTask; | |
| public SimpleTask(AsyncTask waitTask) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.foo.bar; | |
| import android.os.AsyncTask; | |
| public class LoadDrawingContentTask extends SimpleTask { | |
| private final Location location; | |
| public LoadDrawingContentTask(Location myLocation) { | |
| this.location = myLocation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rgb_values = "ffaaffaabbccdd3322fa352fda2" | |
| decimal_values = [] | |
| rgb_values.each_slice(2) do |pair| | |
| decimal_values << pair.join("").hex | |
| end | |
| File.open('test.jpg', 'wb') do |file| | |
| file.print(decimal_values.pack("c*")) | |
| end |