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
| var shared = 0 | |
| val lock = new java.lang.Object | |
| def unsafe = | |
| val local = shared | |
| Thread.sleep(0) | |
| shared = local + 1 | |
| def safe = | |
| lock.synchronized: |
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 scalaz._ // general scalaz support | |
| import syntax.monoid._ // monoid syntax as used below | |
| import std.anyVal._ // some instances to work with | |
| import std.list._ // some more instances | |
| import std.option._ // some more instances | |
| import syntax.std.option._ // postfix methods for options | |
| object monoidExample { | |
| val res0 = ∅[Int] // or: mzero[Int] | |
| val res1 = 3 |+| 4 // or: 3 `mappend` 4 |
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.scalacheck.Properties | |
| import org.scalacheck.Prop.forAll | |
| object IntAbelianGroup extends Properties("Int") { | |
| property("Associativity") = forAll { (a: Int, b: Int, c: Int) => | |
| (a + b) + c == a + (b + c) | |
| } | |
| } | |
| // Closure |
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
| *.suo | |
| *.obj | |
| *.pdb | |
| *.user | |
| *.vspscc | |
| *.bak | |
| *.cache | |
| *.log | |
| *.lib | |
| [Bb]in |
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
| a.out | |
| *.swp | |
| *.o | |
| *.orig | |
| *.hi | |
| *.lkshs | |
| *.iml | |
| .idea/ | |
| dist/ | |
| out/ |
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 | |
| # put in ~/.curlrc: user=BintrayUser:BintrayAPIKey | |
| ORG=$1 | |
| PACKAGE=$2 | |
| curl -i -H "Content-Type: application/json" -d "{ \"name\":\"${PACKAGE}\",\"labels\":[\"android\",\"scala\",\"cse\",\"mobile\",\"oop\",\"designpatterns\"],\"website_url\":\"http://lucoodevcourse.github.io\",\"issue_tracker_url\":\"https://github.com/${ORG}/${PACKAGE}/issues\",\"github_repo\":\"${ORG}/${PACKAGE}\",\"github_release_notes_file\":\"README.md\",\"public_download_numbers\":true,\"public_stats\":true,\"vcs_url\":\"https://github.com/${ORG}/${PACAKGE}\",\"licenses\":[\"MIT\"] }" https://bintray.com/api/v1/packages/${ORG}/generic |
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 pi(n: Long): Double = { | |
| var i = 0L | |
| var c = 0L | |
| while (i < n) { | |
| val x = math.random | |
| val y = math.random | |
| if (x * x + y * y <= 1) c += 1 | |
| i += 1 | |
| } | |
| 4.0 * c / n |
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 | |
| # Download and run this script in a Codio terminal. | |
| # (Workaround for Codio included at the bottom.) | |
| # | |
| # You should set these variables in /home/codio/.bashrc: | |
| # | |
| # export ANDROID_HOME=$HOME/android-sdk-linux | |
| # export LD_LIBRARY_PATH=$HOME/lib32:$LD_LIBRARY_PATH | |
| # |
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 lines = scala.io.Source.stdin.getLines | |
| var count = 0 | |
| for (l <- lines) { | |
| println(l) | |
| count += 1 | |
| } | |
| println("count = " + count) |
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
| scala> def f(i: Int) = i * i | |
| f: (i: Int)Int | |
| scala> Iterator.iterate(2)(f) | |
| res11: Iterator[Int] = non-empty iterator | |
| scala> res11 takeWhile { _ < 10 } foreach { println } | |
| 2 | |
| 4 |