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.jasonwhaley.tictactoe | |
| sealed abstract class GameState { | |
| val nextTurn : TicTacToeSpace | |
| val message : String | |
| val isGameFinished : Boolean | |
| } | |
| case class XMovesNext extends GameState { |
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
| def getGameState(board: TicTacToeBoard): GameState = { | |
| board.getWinner match { | |
| case Some("X") => return new XWins | |
| case Some("O") => return new OWins | |
| case _ => //noop | |
| } | |
| board.spacesUsed match { | |
| case 9 => return new StaleMate | |
| case number if number % 2 == 0 => return new XMovesNext | |
| case _ => return new OMovesNext |
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
| def getWinner() : Option[String] = { | |
| val topRow = List( grid(0)(0), grid(0)(1), grid(0)(2) ) | |
| val middleRow = List( grid(1)(0), grid(1)(1), grid(1)(2) ) | |
| val bottomRow = List( grid(2)(0), grid(2)(1), grid(2)(2) ) | |
| val leftColumn = List( grid(0)(0), grid(1)(0), grid(2)(0) ) | |
| val middleColumn = List( grid(0)(1), grid(1)(1), grid(2)(1) ) | |
| val rightColumn = List( grid(0)(2), grid(1)(2), grid(2)(2) ) | |
| val diagonalTopLeft = List( grid(0)(0), grid(1)(1), grid(2)(2)) | |
| val diagonalTopRight = List( grid(2)(0), grid(1)(1), grid(0)(2)) |
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
| String[] qa = new String[] {"Who was the first pres of the USA","George Washington"}; | |
| //... and later on | |
| String question = qa[0]; | |
| String answer = qa[1]; |
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
| #!/bin/bash | |
| rootDirectory="$1" | |
| stringToMatch="$2" | |
| for jarfile in $(find "$rootDirectory" -name '*.jar') | |
| do | |
| grepOut=$(jar tvf "$jarfile" | grep "$stringToMatch") | |
| if [[ $grepOut ]] | |
| then |
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
| [whaley@sunspot ~/inbox] | |
| > ./findInJar ~/opt/jetty-6.1.15 Main | |
| Matching file(s) found in /Users/whaley/opt/jetty-6.1.15/lib/jetty-6.1.15.jar | |
| org/mortbay/jetty/Main.class | |
| Matching file(s) found in /Users/whaley/opt/jetty-6.1.15/lib/jsp-2.0/ant-1.6.5.jar | |
| org/apache/tools/ant/Main.class | |
| org/apache/tools/ant/helper/ProjectHelper2$MainHandler.class | |
| Matching file(s) found in /Users/whaley/opt/jetty-6.1.15/lib/jsp-2.0/jasper-compiler-jdt-5.5.15.jar | |
| org/eclipse/jdt/internal/compiler/batch/Main$1.class | |
| org/eclipse/jdt/internal/compiler/batch/Main$2.class |
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 itertools | |
| import boto | |
| ec2 = boto.connect_ec2() | |
| chain = itertools.chain.from_iterable | |
| existing_instances = list(chain([res.instances for res in ec2.get_all_instances()])) | |
| print existing_instances #gives you a list of all instances | |
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
| > | |
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
| koan("Using Option to avoid if checks for null") { | |
| //the ugly version | |
| def makeFullName(firstName: String, lastName: String) = { | |
| if (firstName != null) { | |
| if (lastName != null) { | |
| firstName + " " + lastName | |
| } else { | |
| null | |
| } | |
| } else { |
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
| def gcd(a : Int, b : Int) : Int = { | |
| (a,b) match { | |
| case (_,0) => a | |
| case (0,_) => b | |
| case (_,_) => gcd(math.min(a,b), math.abs(a - b)) | |
| } | |
| } |