Skip to content

Instantly share code, notes, and snippets.

{"created_at":"Wed Mar 03 06:41:53 +0000 2021","id":1367002268105588738,"id_str":"1367002268105588738","text":"Was ein schlechter hashtag? #socialLp12345","source":"\u003ca href=\"https:\/\/mobile.twitter.com\" rel=\"nofollow\"\u003eTwitter Web App\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1338498629976399881,"id_str":"1338498629976399881","name":"lptweet","screen_name":"lptweet3","location":null,"url":null,"description":null,"translator_type":"none","protected":false,"verified":false,"followers_count":0,"friends_count":0,"listed_count":0,"favourites_count":0,"statuses_count":29,"created_at":"Mon Dec 14 14:58:46 +0000 2020","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":null,"contributors_enabled":false,"is_translator":false,"profile_background_color":"F5F8FA","profile_background_image_url":"","profile_background_image_url_https":"","profile
@tobnee
tobnee / UriBuilder.scala
Created June 30, 2016 09:07
query builder helper for play
object UriBuilder {
def base(base: String) = new UriBuilder(base, Vector.empty, Vector.empty)
}
case class UriBuilder(
base: String, path: Vector[String], query: Vector[(String, String)]) {
def path(segments: String*): UriBuilder =
new UriBuilder(base, segments.toVector, Vector.empty)
@tobnee
tobnee / FoldEnvolve.scala
Created September 4, 2015 16:39
Event evolutions as fold over evolution functions
val evolutions = List(
(v: JsObject) => v + ("a" -> JsString("foo")),
(v: JsObject) => v + ("b" -> JsNumber(2)),
(v: JsObject) => v - "a"
)
//evolutions: List[play.api.libs.json.JsObject => play.api.libs.json.JsObject] = List(<function1>, <function1>)
evolutions.foldLeft(Json.obj("msg" -> "Nice Evolution"))((value, evolution) => evolution(value))
sealed trait Drink
case object Beer extends Drink
case object Wine extends Drink
case class OrderDrinkV1(drink: Drink)
case class DrinkOrderedV1(drink: Drink)
@tobnee
tobnee / T2f.scala
Created May 7, 2015 14:16
Trait to function pimping
trait X { def execute() }
implicit class XtoFunction(val x: X) extends Function0[Unit] {
def apply() = x.execute()
}
val g = new X{ def execute() = println("foo") }
g()
@tobnee
tobnee / Global.scala
Last active August 29, 2015 14:16
Simple CORS in Play Framework
import filter.EnableCORS
import play.api.mvc
import play.api.mvc.{RequestHeader, Result, WithFilters}
import scala.concurrent.Future
object Global extends WithFilters(EnableCORS) {
override def onHandlerNotFound(request: RequestHeader): Future[Result] = {
request.method match {
case "OPTIONS" if request.headers.get("Origin").isDefined => preflightResponse
@tobnee
tobnee / poly.scala
Created July 9, 2014 15:14
poly functions / map over HLists in shapeless
def publish = {
val a AEvent("a")
val b = BEvent("b")
a :: b :: a :: HNil
}
def use = {
object handler extends Poly1 {
implicit def caseA = at[AEvent](_.toString)
implicit def caseB = at[BEvent](_.toString)
type Result = String
type Error = String
sealed trait DError
case object NotFound extends DError
case class ValidationErrors(err: Set[Error]) extends DError
val id = "10"
val data = "data"
@tobnee
tobnee / Global.scala
Created February 27, 2014 15:57
A simple way to use Play Filters to enforce some basic authentication rules. Based on this pattern more elaborate rules can be implemented.
object Global extends WithFilters(
new OpenIdAuthFilter,
new RoleBasedPathAccessFilter(a => Some(User("user", "ADMIN")), "ADMIN", routes.Admin.index())
) {
}

####Kommentar zu M. Nygard - Maneuverable Web Architecture:

Was kann man mitnehmen aus einem Talk von M. Nygard? Viel, aber nie das was man erwartet. Zugegeben ist die Analogie zu den Kampfpiloten recht weit hergeholt und hat in erster Linie wenig mit Architekturen zu tun. Nygard hat aber genauer hingeschaut und anschaulich erklärt, wie sich Kampfpiloten physikalische Kräfte zu nutzen machen um ihre Dogfights in den Lüften zu gewinnen. Das zielgerichtete Freisetzen und Aufnehmen von Impulsen, um sich in dem Raum der physikalischen Gesetze optimal zu bewegen, verbindet Nygard mit dem Schlüsselwort der Manövrierfähigkeit.

Die Architektur eines IT-Systems bewegt sich ebenfalls in einem Raum. Oftmals in einem turbulenten Projektgeschäft mit ständig wechselnden Anforderungen. Nygard forciert hier das Ziel: eine Architektur so zu gestallten, dass sie Impulse steuern kann. Es geht dabei um Kontrolle von Tempo, Anpassung und Wachstum.

Diese Ideen sind nicht völlig neu, wenn auch anschaulich dargestellt. Als E