Skip to content

Instantly share code, notes, and snippets.

View klaeufer's full-sized avatar
:octocat:

Konstantin Läufer klaeufer

:octocat:
View GitHub Profile
@klaeufer
klaeufer / test2.txt
Created October 20, 2011 18:13
Loyola University Chicago Comp 373/473 Project 2a Sample Test Case 2
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;
@klaeufer
klaeufer / test1.txt
Created October 20, 2011 18:16
Loyola University Chicago Comp 373/473 Project 2a Sample Test Case 1
var x;
var y;
var r;
x = 2;
y = 3;
while (y) {
r = r + x,
y = y - 1
};
@klaeufer
klaeufer / test4.txt
Created October 20, 2011 21:13
Loyola University Chicago Comp 373/473 Project 2a Sample Test Case 4
struct ListNode { value, next };
n = new ListNode;
n.value = 5;
n.next = 0;
{ n.value = 7, n }.next = 12;
@klaeufer
klaeufer / unfiltered-simple-caching.scala
Created March 19, 2011 23:25
Simple Unfiltered example for providing OPTIONS, HEAD, and conditional GET
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)) ~>
@klaeufer
klaeufer / LexerOnly.fs
Created April 3, 2012 01:15
Lexer-only example for F# lexing and parsing example from F# Programming Wikibook
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
@klaeufer
klaeufer / ThreadSafety.scala
Last active December 16, 2015 08:59
Unsafe and safe concurrent threads for experimenting in the Scala REPL
var shared = 0
val lock = new java.lang.Object
def unsafe = {
val local = shared
Thread.sleep(0)
shared = local + 1
}
def safe = {
@klaeufer
klaeufer / monoidExample.scala
Last active December 30, 2015 19:59
minimal scalaz monoid example
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
@klaeufer
klaeufer / IntAbelianGroupScalaCheck.scala
Created December 9, 2013 22:10
minimal ScalaCheck example
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
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))
@klaeufer
klaeufer / asyncDownloader.sc
Last active May 4, 2016 20:19
Example of asynchronous, cancelable downloading using the Ning AsyncHttpClient (see also https://trello.com/c/KTUBorWF/78-project-4)
// 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._