Skip to content

Instantly share code, notes, and snippets.

View wlk's full-sized avatar
🐒

Wojciech Langiewicz wlk

🐒
View GitHub Profile
import akka.actor.SupervisorStrategy.Restart
import akka.actor.{Actor, ActorInitializationException, ActorSystem, OneForOneStrategy, Props}
object Main extends App {
var attempt: Int = 0
class FailingActor extends Actor {
if (attempt == 0) {
// throw exception only for the first time, simulating first attempt to create an actor that fails
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "uuid-schema",
"description": "Validation for UUID",
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
}
case class Author(id: UUID, name: String, dateOfBirth: DateTime, dateOfDeath: Option[DateTime], createdAt: DateTime, updatedAt: DateTime)
def toJsonapi(author: Author) = {
ResourceObject(
`type` = author.`type`,
id = Some(author.id),
attributes = authorAttributes(author),
relationships = authorRelationships(author),
links = List(Links.Self(selfLink(author))
)
{
"data": {
"id": "1",
"type": "authors",
"attributes": {
"name": "J. R. R. Tolkien",
"date_of_birth": "1892-01-03",
"date_of_death": "1973-09-02",
"created_at": "2017-06-18 11:30:16",
"updated_at": "2017-06-18 11:30:16"
{
"data": {
"id": "1",
"type": "authors",
"attributes": {
"name": "J. R. R. Tolkien",
"date_of_birth": "1892-01-03",
"date_of_death": "1973-09-02",
"created_at": "2017-06-18 11:30:16",
"updated_at": "2017-06-18 11:30:16"
{
"data": {
"id": "1",
"type": "chapters",
"attributes": {
"title": "A Long-expected Party",
"ordering": 1,
"created_at": "2017-06-18 11:30:17",
"updated_at": "2017-06-18 11:30:17"
},
{
"data": {
"id": "1",
"type": "books",
"attributes": {
"date_published": "1954-07-29",
"title": "The Fellowship of the Ring",
"created_at": "2017-06-18 11:30:16",
"updated_at": "2017-06-18 11:30:16"
},
{
"data": {
"id": "1",
"type": "authors",
"attributes": {
"name": "J. R. R. Tolkien",
"date_of_birth": "1892-01-03",
"date_of_death": "1973-09-02",
"created_at": "2017-06-18 11:30:16",
"updated_at": "2017-06-18 11:30:16"
package uk.co.real_logic;
import static java.lang.System.out;
/*
Original exercise did during "Lock Free Workshop" by Martin Thompson: http://www.real-logic.co.uk/training.html
*/
public final class PingPong {
private static final int REPETITIONS = 100_000_000;
import scala.util.Random
object Suit extends Enumeration {
val Clubs, Spades, Hearts, Diamonds = Value
}
object Rank extends Enumeration {
val Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace = Value
}