Skip to content

Instantly share code, notes, and snippets.

Avatar

Adil Akhter adilakhter

View GitHub Profile
View send_to_logstash.py
import socket
import json
import sys
HOST = 'logging.developmentci.rebb.baseless.nl'
PORT = 1514
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
View updatescript.py
import socket
import json
import sys
HOST = 'logging.developmentci.rebb.baseless.nl'
#HOST = '127.0.0.1'
PORT = 1514
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
View eventstream.scala
//Message and event classes
case class UpdateAccountBalance(userId:Long, amount:Long)
case class BalanceUpdated(userId:Long)
//Actor that performs account updates
class AccountManager extends Actor{
val dao = new AccountManagerDao
def receive = {
case UpdateAccountBalance(userId, amount) =>
View coalesce.scala
def coalesce(x:List[String], y:List[Int]):List[(String, Int)] =
(x zip y).groupBy(_._1)
.values
.map{_.reduce((i,j) => (i._1, (i._2 + j._2)))}
.toList
.sorted
View main.scala
lazy val oDataQuery: PackratParser[SourceNode]={
serviceURL ~ resourcePath ~ opt(queryOperationDef) ^^ {
case uri ~ path ~ None => ODataQuery(uri, path, QueryOperations(Seq.empty))
case uri ~ path ~ Some(exp) => ODataQuery(uri, path,QueryOperations(exp))
}
}
@adilakhter
adilakhter / expressionTree
Created Apr 9, 2014
OData URI Expression Tree
View expressionTree
ODataQuery(
URL("http://odata.io/odata.svc"),
ResourcePath("Schema",Number("231"),ResourcePath("Customer",EmptyExp(),EmptyExp())),
QueryOperations(
List(Top(Number("2")),
Filter(
EqualToExp(
CallExp(
Property("concat")
, List(Property("City"), Property("Country"))
View ODataUriParserTests_Select.scala
test("Parse /Products?$select=Name"){
val uri = "http://services.odata.org/OData.svc/Products?$select=Name,Price"
val actual = p.parseThis(mainParser,uri).get
val expectedAst =
ODataQuery(
URL("http://services.odata.org/OData.svc"),
ResourcePath("Products",EmptyExp(),EmptyExp()),
QueryOperations(List(Select(List(Property("Name"), Property("Price"))))))
View ExpressionParser.scala
lazy val expression: PackratParser[Expression] =
expression ~ ("add" ~> termExpression) ^^ {case l ~ r => PlusExp(l, r)} |
expression ~ ("sub" ~> termExpression) ^^ {case l ~ r => MinusExp(l, r)} |
termExpression
lazy val termExpression: PackratParser[Expression] =
termExpression ~ ("mul" ~> factor) ^^ {case a ~ b => MultiplyExp(a, b)} |
termExpression ~ ("div" ~> factor) ^^ {case a ~ b => DivideExp(a, b)} |
termExpression ~ ("mod" ~> factor) ^^ {case a ~ b => ModExp(a, b)} |
factor
View resourcePath.scala
lazy val resourcePath: PackratParser[Expression] =(
"/" ~> idn ~ ("(" ~> predicate <~ ")") ~ opt(resourcePath) ^^ {
case Property(name) ~ keyPredicate ~ None => ResourcePath(name, keyPredicate, EmptyExp())
case Property(name) ~ keyPredicate ~ Some(expr) => ResourcePath(name, keyPredicate, expr)
}
| "/" ~> idn~ opt(resourcePath) ^^ {
case Property(e)~None => ResourcePath(e, EmptyExp(), EmptyExp())
case Property(e)~Some(expr) => ResourcePath(e, EmptyExp(), expr)
}
)
View ODataUriParser.scala
test("Parse /Customers?$top=2&$filter=concat(City, Country) eq 'Berlin, Germany'"){
val uri = "http://odata.io/odata.svc/Schema(231)/Customer?$top=2&$filter=concat(City, Country) eq 'Berlin, Germany'"
val actual = p.parseThis(mainParser,uri).get
println(uri + "=>" + actual)
val expectedAst=
ODataQuery(
URL("http://odata.io/odata.svc"),
ResourcePath("Schema",Number("231"),ResourcePath("Customer",EmptyExp(),EmptyExp())),
QueryOperations(
You can’t perform that action at this time.