This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* © 2012 Typesafe Inc. | |
* | |
* Extracted from http://doc.akka.io/docs/akka/2.1.0-RC2/scala/io.html | |
*/ | |
import akka.actor._ | |
import akka.util.{ ByteString, ByteStringBuilder } | |
import java.net.InetSocketAddress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datomisca._ | |
import scala.concurrent._ | |
import scala.concurrent.duration.Duration | |
import datomisca.executioncontext.ExecutionContextHelper._ | |
object TxReportQuery { | |
object PersonSchema { | |
object ns { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create attribute to record comment | |
val comment = Attribute(new Namespace("meta") / "comment", SchemaType.string, Cardinality.one) | |
Datomic.transact(comment) | |
// data from txReportQueue | |
val txr:datomisca.TxReport = ... | |
// assert "sent email" on all the transactions | |
Datomic.transact(txr.txData.map{case DDatom(_,_,_,tx,_) => tx}.distinct. | |
map{id => SchemaEntity.add(FinalId(id))(Props() + (comment-> "sent email"))}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package baudot; | |
import java.util.Arrays; | |
import rx.Observable; | |
import rx.Observable.OnSubscribeFunc; | |
import rx.Observer; | |
import rx.Subscription; | |
import rx.util.functions.Func1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Recursive { | |
public static void main(String[] args) throws InterruptedException { | |
final Scheduler scheduler = Schedulers.newThread(); | |
Observable<Character> obs = Observable | |
.create(new OnSubscribeFunc<Character>() { | |
@Override | |
public Subscription onSubscribe( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CamelBlocking { | |
public static void main(String[] args) throws InterruptedException { | |
CamelContext camelContext = new DefaultCamelContext(); | |
ReactiveCamel rx = new ReactiveCamel(camelContext); | |
Observable<String> observable = rx.toObservable( | |
"stream:in?scanStream=true", String.class); | |
observable.toBlockingObservable().forEach(new Action1<String>() { | |
@Override | |
public void call(String m) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Editor = React.createClass({ | |
getInitialState: function() { | |
return {value: 'Hello!'}; | |
}, | |
handleChange: function(event) { | |
var caretPos = this.getDOMNode().selectionStart; | |
var msg = {text:event.target.value,caret:caretPos}; | |
$.ajax({url: "/text", type: "POST", | |
data: JSON.stringify(msg), | |
contentType:"application/json; charset=utf-8", dataType:"json", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def text = Action(parse.json) { request => | |
val caret = (request.body \ "caret").as[Int] | |
val text = (request.body \ "text").as[String] | |
val trimmed = text.filterNot(_ == 'a') | |
Ok(Json.obj("caret" -> (caret-(text.length-trimmed.length)), "text" -> trimmed)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val size: Codec[Int] = new Codec[Int] { | |
private val marker = 255 | |
override def sizeBound = uint(8).sizeBound | uint(32).sizeBound | |
override def encode(value: Int) = if (value < marker) | |
uint(8).encode(value) | |
else | |
(uint(8) ~ uint(32)).encode(marker ~ value) | |
override def decode(bits: BitVector) = { | |
uint(8).decode(bits) match { | |
case Attempt.Successful(DecodeResult(value, remainder)) if value == marker => int(32).decode(remainder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scodec.Codec | |
import scodec.codecs._ | |
import scodec.bits.ByteVector | |
import scodec.bits.BitVector | |
import scodec.Attempt | |
import scodec.DecodeResult | |
object SerialProtocol { | |
sealed trait Parity |
OlderNewer