Skip to content

Instantly share code, notes, and snippets.

View Narigo's full-sized avatar

Joern Bernhardt Narigo

View GitHub Profile
@Narigo
Narigo / JavaPersistorTestClient.java
Created August 2, 2012 08:12
Asynchronous testing...
package vertx.mods.tests.verticles.java;
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@Narigo
Narigo / SessionHelper.java
Created August 18, 2012 12:13
Vert.x Session Manager Helper class
package com.campudus.gorilla;
import java.util.Set;
import org.jboss.netty.handler.codec.http.Cookie;
import org.jboss.netty.handler.codec.http.CookieDecoder;
import org.jboss.netty.handler.codec.http.CookieEncoder;
import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.EventBus;
import org.vertx.java.core.eventbus.Message;
@Narigo
Narigo / SomeAsyncTests.scala
Created August 29, 2012 22:57
Scala ways to handle event based stuff?
package com.campudus.scalasnippets
import actors.Actor._
import java.util.concurrent.atomic.AtomicInteger
import scala.annotation.tailrec
object SomeAsyncTests {
def asyncFunction(i: Int)(doWhenDone: => Unit) = actor {
println("doing stuff " + i)
package tests;
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.RouteMatcher;
import org.vertx.java.deploy.Verticle;
public class HttpClientExample extends Verticle {
public void start() {
@Narigo
Narigo / ReactiveMongoTest.scala
Created February 22, 2013 16:24
Figured it out - shouldn't wait for "insertFuture" but wait for the end of the new future returned by insertFuture.andThen(...). Same for the result of the find in the end: The future needs to wait until the "res" future/promise is done (Await.result(res)), otherwise it would show up "None".
package reactivemongotest
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
import org.junit.Test
import reactivemongo.api.MongoConnection
import reactivemongo.bson.BSONDocument
import reactivemongo.bson.BSONInteger
@Narigo
Narigo / ReactiveMongoTest.scala
Last active December 14, 2015 06:49
Cannot query nested documents (Line #39)
package reactivemongotest
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
import org.junit.Test
import reactivemongo.api.MongoConnection
import reactivemongo.bson.BSONDocument
import reactivemongo.bson.BSONInteger
@Narigo
Narigo / caller_example.js
Created March 11, 2013 15:46
vertx event bus addition
eventBus.replaceData("address", "read-action", "replace-action", {
"id" : 15
},
// action on replace computation
function (readData) {
var replacedData = readData;
replacedData.nickname = replacedData.nickname.toLowerCase();
return replacedData;
},
// action on success
trait MessageHelpers {
type Validated[T] = Either[List[String], T]
type Decoder[T] = Message[JsonObject] => Validated[T]
def validatedMap[X, Y](v: Validated[X], f: X => Y): Validated[Y] = v match {
case Left(errors) => Left(errors)
case Right(x) => Right(f(x))
}
private def missingField[T](field: String): T => Validated[T] = { maybe =>
@Narigo
Narigo / build.sbt
Created April 4, 2013 12:44
This works if you change line 10 (var dbVar = database) to val dbVar = database
// Set the project name to the string 'My Project'
name := "SBTProject"
// The := method used in Name and Version is one of two fundamental methods.
// The other method is <<=
// All other initialization methods are implemented in terms of these.
version := "1.0"
scalaVersion := "2.10.1"
@Narigo
Narigo / #vertx.log
Last active December 17, 2015 03:58
This is working now.. with another ExecutionContext
[19:20:14] <purplefox> Narigo: ok found the problem
[19:20:24] <purplefox> Narigo: the problem is you're playing with threads in your verticle
[19:20:38] <purplefox> Narigo: you're using a fork join
[19:20:49] <purplefox> Narigo: and calling deployVerticle on the result of that
[19:20:56] <purplefox> Narigo: which is not the vert.x thread
[19:21:16] <purplefox> Narigo: so vert.x doesn't know what verticle you're in
[19:21:28] <purplefox> Narigo: basically - don't use other threads in verticles
[19:21:38] <purplefox> Narigo: you're also opening yourself up to race conditions
[19:22:15] <purplefox> Narigo: I'll add some better exceptions in vert.x so you'll get a better message next time you do this
[19:22:37] <purplefox> Narigo: "deploVerticle called from a non Vert.x thread. You are a very naughty boy!!"