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 / .gitignore
Created November 12, 2014 18:47
.gitignore for F# development
*.suo
*.obj
*.pdb
*.user
*.vspscc
*.bak
*.cache
*.log
*.lib
[Bb]in
@klaeufer
klaeufer / .gitignore
Created November 12, 2014 18:47
.gitignore for Haskell development
a.out
*.swp
*.o
*.orig
*.hi
*.lkshs
*.iml
.idea/
dist/
out/
@klaeufer
klaeufer / createBintrayPackage.sh
Created November 22, 2014 16:52
Create Bintray package using curl and REST API
#!/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
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
@klaeufer
klaeufer / install-android-sdk.sh
Last active August 29, 2015 14:16
Android SDK install script for Ubuntu on Codio
#!/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
#
val lines = scala.io.Source.stdin.getLines
var count = 0
for (l <- lines) {
println(l)
count += 1
}
println("count = " + count)
@klaeufer
klaeufer / gist:867abb57dddc1b247b52
Last active August 29, 2015 14:17
Scala Iterator loop idiom (stateless): repeatedly apply an endofunction until a condition is met
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
@klaeufer
klaeufer / gist:350ae39af27d19b156c2
Last active August 29, 2015 14:17
Scala Iterator loop idiom (stateful): repeatedly produce a value until a condition is met
Iterator continually {
// ...
reader.readLine()
} takeWhile {
Option(_).isDefined
} foreach {
processExpr
}
replaces
@klaeufer
klaeufer / gist:5c9dbd6cc60e4f76cde5
Last active August 29, 2015 14:17
Initial neo4j explorations in Scala
// libraryDependencies += "org.neo4j" % "neo4j" % "2.2.0-RC01"
// libraryDependencies += "com.jsuereth" %% "scala-arm" % "1.4"
import org.neo4j.graphdb._
import org.neo4j.graphdb.factory._
import resource._
import scala.collection.JavaConversions._ // for using ResourceIterator in a for comprehension
val graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("db1")
@klaeufer
klaeufer / test3.txt
Created October 20, 2011 18:05
Loyola University Chicago Comp 373/473 Project 2a Sample Test Case 3
struct ListNode { value, next };
var n;
var h;
var s;
n = new ListNode;
h = n;
n.value = 2;
n.next = new ListNode;
n = n.next;
n.value = 3;