This file contains 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
struct StudentCourseRecord { firstExamScore, secondExamScore, totalScore }; | |
struct StudentSemesterRecord { course1, course2 }; | |
var q; | |
var r; | |
r = new StudentSemesterRecord; | |
r.course1 = new StudentCourseRecord; | |
r.course1.firstExamScore = 25; | |
r.course1.secondExamScore = 35; | |
r.course1.totalScore = r.course1.firstExamScore + r.course1.secondExamScore; | |
r.course2 = r.course1; |
This file contains 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 x; | |
var y; | |
var r; | |
x = 2; | |
y = 3; | |
while (y) { | |
r = r + x, | |
y = y - 1 | |
}; |
This file contains 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
struct ListNode { value, next }; | |
n = new ListNode; | |
n.value = 5; | |
n.next = 0; | |
{ n.value = 7, n }.next = 12; |
This file contains 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 RootPlan extends Plan { | |
val logger = Logger(classOf[RootPlan]) | |
val creationDate = new java.util.Date | |
val eTag = hashCode.toString | |
val Head = Ok ~> Vary("Accept-Charset", "Accept-Encoding", "Accept-Language", "Accept") | |
val Caching = | |
CacheControl("max-age=3600") ~> | |
LastModified(DateUtils.formatDate(creationDate)) ~> |
This file contains 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
open System | |
open Sql | |
let x = " | |
SELECT x, y, z | |
FROM t1 | |
LEFT JOIN t2 | |
INNER JOIN t3 ON t3.ID = t2.ID | |
WHERE x = 50 AND y = 20 | |
ORDER BY x ASC, y DESC, z |
This file contains 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 = { |
This file contains 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 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 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 zeroTo: GenericCoalgebra[Int, Option, Int] = n => { | |
require { n >= 0 } | |
if (n == 0) (0, None) | |
else (n, Some(n - 1)) | |
} | |
val treeFromInt: GenericCoalgebra[Int, List, Int] = n => { | |
require { n >= 0 } | |
if (n == 0) (0, List.empty) | |
else (n, List(n - 1, n - 1)) |
This file contains 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
// long download: https://downloads.gradle.org/distributions/gradle-2.3-src.zip | |
// short download: https://repo1.maven.org/maven2/com/ning/async-http-client/1.9.20/async-http-client-1.9.20.jar | |
// dependencies: see build.sbt | |
// usage: val f = download(url, localFileName) | |
// to cancel (if desired): f.cancel(true) | |
import com.ning.http.client._ | |
import com.ning.http.client.listener._ |