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 / 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 / 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._
@klaeufer
klaeufer / install-android-sdk-ubuntu.sh
Last active January 8, 2018 04:31
installation script for Android SDK and JDK 8 on Ubuntu (Cloud9)
#!/bin/sh
# installation script for Android SDK and JDK 8 on Ubuntu
# for Android development with gradlew-based projects
# tested on Cloud9
ANDROID_HOME=$HOME/lib/android-sdk-linux
ANDROID_SDK_VERSION=24.4.1
ANDROID_BUILD_TOOLS_VERSION=23.0.2
ANDROID_API_LEVEL=22
@klaeufer
klaeufer / install-sbt-ubuntu.sh
Last active April 2, 2017 14:24
installation script for Scala sbt and JDK 8 on Ubuntu (Codenvy)
#!/bin/sh
# installation script for Scala sbt on Ubuntu
# tested on Codenvy
sudo apt-get update
sudo apt-get install -y apt-transport-https
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
// http://underscore.io/blog/posts/2015/04/14/free-monads-are-simple.html
// updated version for scalaz 7.2.x where Free automatically applies the
// Coyoneda transform
import scalaz.{Free, ~>, Id}
import scalaz.std.list._
import scalaz.syntax.traverse._
type UserId = Int
type UserName = String
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))
// see also https://www.implicitdef.com/2015/11/19/comparing-scala-http-client-libraries.html
// task: use the prime checker webservice
// https://github.com/LoyolaChicagoCode/primenumbers-spray-scala
// to count the number of primes within a given range
/* instructions: create a build.sbt file in your project root folder containing the following lines:
scalaVersion := "3.3.3"
@klaeufer
klaeufer / install-android.sh
Created January 14, 2017 01:59
install Android SDK on Codenvy (Ubuntu)
#!/bin/sh
export ANDROID_HOME=/projects/Android/sdk
mkdir -p $ANDROID_HOME
cd $ANDROID_HOME
wget https://dl.google.com/android/repository/tools_r25.2.3-linux.zip
unzip -q tools_r25.2.3-linux.zip
$ANDROID_HOME/tools/bin/sdkmanager --update
@klaeufer
klaeufer / extract-summary.py
Last active January 14, 2017 02:31
Basic testing metrics for Android and Maven
#!/usr/bin/env python
from bs4 import BeautifulSoup
soup = BeautifulSoup(open("target/site/surefire-report.html"), "html.parser")
table = soup.find("table")
headings = [th.get_text() for th in table.find("tr").find_all("th")]
row = table.find_all("tr")[1]
dataset = [td.get_text() for td in row.find_all("td")]