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
value1 = if condition | |
# stuff | |
# stuff | |
true | |
else | |
# stuff | |
# stuff | |
false | |
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
int myFunction(int x) | |
{ | |
if (x > 10) | |
return x; | |
if (x < 10) | |
return x + 1; | |
if (x = 10) | |
return 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
class Person(firstName: String, lastName: String, age: Int) { | |
def fullName(implicit val titleProvider: () => String): String = { | |
val title = titleProvider() | |
LIST_STUFF_IN_SCOPE() | |
/* | |
This should list: | |
firstName, lastName, age, title, titleProvider | |
*/ |
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
append: aString to: anotherString | |
^ anotherString, ' ', aString | |
"..." | |
#('I' 'like' 'milk') inject: '' into: self class blockFor: #append. | |
" as opposed to " | |
#('I' 'like' 'milk') inject: '' into: [:sentence :word | self append: word to: sentence] |
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 add a, b | |
a + b | |
end | |
three = add 1, 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
Counting objects: 55, done. | |
Delta compression using up to 8 threads. | |
Compressing objects: 100% (49/49), done. | |
error: RPC failed; result=22, HTTP code = 411 | |
fatal: The remote end hung up unexpectedly | |
Writing objects: 100% (51/51), 7.83 MiB | 6.21 MiB/s, done. | |
Total 51 (delta 11), reused 0 (delta 0) | |
fatal: The remote end hung up unexpectedly | |
fatal: expected ok/error, helper said '4004s˥?kM+?J?W??z?/?k?ǣ)#?[??ww??J?a??' |
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 play.api.libs.json._ | |
implicit object userToJson extends Writes[User] { | |
def writes(user: User): JsonValue = JsonObject(Seq( | |
"possiblyTotallyUnrelatedFieldName" -> JsString(user.name) | |
//, ... | |
)) | |
} |
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 test = Action { | |
val page = new Page("public/test.html") { | |
$("p").clone(3) | |
} | |
Ok(page) | |
} |
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 Pool[T](values: Iterator[T], width: Int, height: Int) { | |
class Cell[T](value: T, neighbours: => Seq[Cell[T]]) { | |
lazy val Seq(top, right, bottom, left) = neighbours | |
} | |
val cells = for (x <- 0 until width) yield ( | |
for (y <- 0 until height) yield | |
new Cell(values.next, Seq(cellAt(x, y - 1), cellAt(x + 1, y), cellAt(x, y + 1), cellAt(x - 1, y)))) | |
def cellAt(x: Int, y: Int): Cell[T] = cells(translate(x, width))(translate(y, height)) |
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
val in: InputStream | |
val buffer: Array[Byte] | |
val stream: Stream[Array[Byte]] = | |
Stream.continually(in.read(buffer)).takeWhile(-1 !=).map(buffer take) | |
val iterator: Iterator[Array[Byte]] = | |
Iterator.continually(in.read(buffer)).takeWhile(-1 !=).map(buffer take) | |
stream.foreach(println) // the byte arrays stay | |
iterator.foreach(println) // the byte arrays go (some time) |