Skip to content

Instantly share code, notes, and snippets.

View dcaoyuan's full-sized avatar

Caoyuan Deng dcaoyuan

View GitHub Profile
@dcaoyuan
dcaoyuan / akka-http-client.scala
Created August 26, 2016 12:23
akka-http-client-example
val uri = "http://www.yahoo.com"
val reqEntity = Array[Byte]()
val respEntity = for {
request <- Marshal(reqEntity).to[RequestEntity]
response <- Http().singleRequest(HttpRequest(method = HttpMethods.POST, uri = uri, entity = request))
entity <- Unmarshal(response.entity).to[ByteString]
} yield entity
val payload = respEntity.andThen {
@dcaoyuan
dcaoyuan / JPQLMetadataEvaluator.scala
Last active August 28, 2015 09:23
Building projection schema
package chana.jpql
import chana.jpql.nodes._
import chana.schema.SchemaBoard
import org.apache.avro.Schema
import org.apache.avro.SchemaBuilder
import org.apache.avro.SchemaBuilder.FieldAssembler
import scala.collection.immutable
sealed abstract class MetaNode {
function entityStateNotity(id, record, fieldName, fields, print, http_get, http_post) {
var arr = record.get(fieldName);
var lastAction = arr[arr.length-1].get('action');
http_post.apply('http://localhost:8080/kwafer/insert/'+id, '.entityState\n{"' +
lastAction.get('opKey') + '": "' +
lastAction.get('opValue') + '"}')
}
val p1: Function[(Int, Int), String] = {
x => "OK"
}
val p2: Function[(Int, Int), String] = {
x =>
x match {
case (a: Int, b: Int) => "OK"
}
}
function calc() {
var llt = account.get("lastLoginTime");
llt += 1;
account.put("lastLoginTime", llt);
llt = account.get("lastLoginTime");
notify(llt)
}
function notify(value) {
print(id + ":" + value);
private boolean isApplicationBroughtToBackground() {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
package spray.can.websocket.frame
import akka.util.ByteIterator
import akka.util.ByteString
import scala.annotation.tailrec
object FrameParser {
var frameSizeLimit: Long = Long.MaxValue
/**
val observer = new Observer[OnEvent] {
override def onNext(value: OnEvent) {
case OnEvent("Hi!", args, context) =>
if (value.packet.hasAckData) {
value.ack("[]")
}
value.reply("welcome", List(Msg("Greeting")).toJson.toString)
}
}
@dcaoyuan
dcaoyuan / ActorBasedPrime.scala
Created September 11, 2012 18:01
Actor Based Prime: should private (make them final) each case class and extended Reactor for performance
import System.{currentTimeMillis => now}
import collection.mutable.ArrayBuffer
import actors.Actor
import scala.actors.Reactor
/**
* @author <a href="mailto:[email protected]">zhongl<a>
*/
object ActorBasedPrime extends App {
@dcaoyuan
dcaoyuan / gist:1022007
Created June 12, 2011 21:32
erase method of implicit parameter
scala> def p(implicit i:Int) = print(i)
p: (implicit i: Int)Unit
scala> p(i)
3
scala> def p = print("no implicit p(i) any more")
p: Unit
scala> p
no implicit p(i) any more