After my visit at ScalaDays 2014 where I attend "akka-http: (un)REST for your Actors" talk I started learning about reactive streams in Akka. There were two really good sources. First was talk by Roland Kuhn and Viktor Klang I missed at Scaladays (video) . Second is amazingly well commented code in akka-stream library.
I decided to present reactive streams to my colleges from javeo.eu . There (https://github.com/ppiotrow/javeo-akka-stream) are examples I presented them. Everything should be well documented in README. If something is not clear, then you can propose pull request;)
Saturday, July 12, 2014
Akka testing parrent child relation
Testing child actors is not piece of cake in Akka. Its because this actors often communicate with parent using context.parrent
context.parrent ! FOOMsg("foo")
One of possible and reusable solution is to create:
import akka.testkit.{TestProbe, TestKit}
import org.scalatest.Suite
import akka.actor.{Actor, Props, ActorSystem}
trait TestParentChildRelation {
this: TestKit with Suite =>
def mockParentWithProbe(childProps: Props)
(implicit system: ActorSystem) = {
val proxy = TestProbe()
system.actorOf(Props(new Actor {
val child = context.actorOf(childProps)
def receive = {
case x if sender == child => proxy.ref forward x
case x => child forward x
}
}))
proxy
}
}
The trait can be mixed into test scenario like in example from (Link)
class ProcreatorActorTest
extends TestKit(ActorSystem("ProcreatorTestActorSystem"))
with ImplicitSender
with WordSpecLike
with StopSystemAfterAll
with TestParentChildRelation {
"A Procreator actor" must {
"recombine the genome" in {
val maleGenotype = SampleGenome(Seq(1, 3, 3, 7, 1))
val femaleGenotype = SampleGenome(Seq(9, 8, 7, 6, 5))
val male = TestActorRef(new Phenotype(maleGenotype))
val female = TestActorRef(new Phenotype(femaleGenotype))
val proxy = mockParentWithProbe(Props(
new TestRecombineProcreator(male, female, 1.0)))
val expectedGenome = SampleGenome(Seq(1, 3, 7, 6, 5))
proxy.expectMsg(Descendant(expectedGenome))
}
}
Examples come from https://github.com/ppiotrow/scalagen project. I'm waiting for your feedback
Wednesday, March 5, 2014
Fast access to ssh public key
I took it from github page. It's nice to have shortcut:)
xclip -sel clip < ~/.ssh/id_rsa.pub
Wednesday, February 26, 2014
SQL Case with only nulls problem
Last time client reported some strange SQL error.
It is caused by following statement
It looks for me ok, but the problem is with nulls. When CASE expression returns only nulls, then MSSQL interpreter do not know result type. I can think abount many workarounds for this problem but the best is to add "ELSE MY_COLUMN" expression. Corrected, stable form of statement is now
Now interpreter knowns result type and it works.
None of the result expressions in a CASE specification can be NULL
It is caused by following statement
UPDATE MY_TABLE SET MY_COLUMN = CASE ID WHEN 99 THEN null WHEN 100 THEN null END
It looks for me ok, but the problem is with nulls. When CASE expression returns only nulls, then MSSQL interpreter do not know result type. I can think abount many workarounds for this problem but the best is to add "ELSE MY_COLUMN" expression. Corrected, stable form of statement is now
UPDATE MY_TABLE SET MY_COLUMN = CASE ID WHEN 99 THEN null WHEN 100 THEN null ELSE MY_COLUMN END
Now interpreter knowns result type and it works.
Tuesday, February 25, 2014
Git merge specific file from another branch
No more workarounds! I finally know how to merge changes from only one file from given branch to current branch.
Just do the following:
Just do the following:
git checkout <some-branch> <path-to-specific-file>
Friday, April 26, 2013
[Solved] R SVM test data does not match model
Hi,
Here is my solution to error "test data does not match model !". It occurs, when you try to predict testdata with SVM model from e1071 like bellow
You have to set factor levels of ALL your columns to be exactly the same as in training data, not only class column...
So you can use sth. like:
(edition: thx to Ting Chi)
testset$foocolname <- factor(
testset$foocolname,levels = levels(trainset$foocolname)
)
testset$goocol <- factor(
testset$goocol,levels = levels(trainset$goocol)
)
Edit: some tips
Here is my solution to error "test data does not match model !". It occurs, when you try to predict testdata with SVM model from e1071 like bellow
predict(mySVMmodel, type="class", testset)I found some hint here http://r.789695.n4.nabble.com/Levels-in-new-data-fed-to-SVM-td4654969.html , but in wasn't exactly my case. I lost few hours but I have solution now.
You have to set factor levels of ALL your columns to be exactly the same as in training data, not only class column...
So you can use sth. like:
(edition: thx to Ting Chi)
testset$foocolname <- factor(
testset$foocolname,levels = levels(trainset$foocolname)
)
testset$goocol <- factor(
testset$goocol,levels = levels(trainset$goocol)
)
etc...If it helps, let me know:)
Edit: some tips
- Error "length of 'center' must equal the number of columns of 'x'" might be somehow connected with factor levels problem. I don't know why, but by using tips from the post i solved that error too.
- When you assign some factor levels you might get error "number of levels differs". It means, that left side column contains more factor levels than right side column and your idea is probably wrong.
Subscribe to:
Posts (Atom)