Skip to content

Instantly share code, notes, and snippets.

View karthik20522's full-sized avatar
๐Ÿ‘Š

Karthik Srinivasan karthik20522

๐Ÿ‘Š
View GitHub Profile
@karthik20522
karthik20522 / SCp.scala
Created May 25, 2019 06:46
select count(name) from users
case class Count(val field: String)
def count: Parser[Count] = "select" ~ "count" ~> "(" ~> ident <~ ")" ^^ {
case exp => Count(exp)
}
//output: Count("name")
@karthik20522
karthik20522 / ScalaParserCombinators.scala
Created May 25, 2019 06:45
select name,age from users
def select: Parser[Select] = "select" ~ repsep(ident, ",") ^^ {
case "select" ~ f => Select(f: _*)
}
//output: Select(List[String]("name", "age"))
import scala.util.parsing.combinator._
import scala.util.parsing.combinator.syntactical._
case class Select(val fields: String*)
case class From(val table: String)
def selectAll: Parser[Select] = "select" ~ "*" ^^^ (Select("*")) //output: Select("*")
def from: Parser[From] = "from" ~> ident ^^ (From(_)) //output: From("users")
case class Terms(
termIds: List[Int],
status: Int = 0)
case class DesiredTermDetails(
ancestors: Boolean = false,
category: Boolean = false,
children: Boolean = false,
translations: Boolean = true,
mappingSynonyms: Boolean = false,
@karthik20522
karthik20522 / soap.scala
Created May 25, 2019 03:45
Calling SOAP Service in Scala
import spray.client.pipelining._
import akka.actor.{ ActorRefFactory }
import spray.http._
import spray.httpx._
import scala.concurrent.Future
import scala.xml._
class KeywordService(keywordServiceURL: String, implicit val actorRefFactory: ActorRefFactory) {
import actorRefFactory.dispatcher
val esReindexActor = system.actorOf(Props(new ElasticsearchReIndexerActor(
"localhost:9200",
"localhost:9200",
"inputIndex",
"outputIndex",
"someType",
doNothing)), name = "esReIndexer")
esReindexActor ! "init"
@karthik20522
karthik20522 / reindex_elasticsearch.scala
Last active May 25, 2019 03:23
ReIndexing Elasticsearch in Scala
import org.json4s._
import org.json4s.JsonDSL._
import spray.client.pipelining._
import spray.http._
import spray.httpx._
import spray.httpx.encoding._
import scala.concurrent._
import scala.concurrent.duration._
import akka.actor._
import scala.collection.mutable.ListBuffer
@karthik20522
karthik20522 / rabbitmq.sh
Created May 24, 2019 08:18
Trivial bash script for upgrading RabbitMQ service
function check_rmq_version {
rmq_version=$(sudo rabbitmqctl status | grep "rabbit," | cut -d',' -f3 | cut -d'}' -f1 | tr -d '"')
echo && echo " Version = $rmq_version" && echo
}
function stop_rmq {
echo "Stopping RabbitMQ..."
sudo service rabbitmq-server stop
}
@karthik20522
karthik20522 / aws_restart.sh
Last active May 24, 2019 03:41
Trivial bash Script to restart services in AWS
#!/bin/bash
set -e
function usage {
echo >&2 "Usage: $0 [ -e environment -n service_name -a action ]"
exit 1
}
while getopts ":n:e:a:" FLAG; do
case $FLAG in
@karthik20522
karthik20522 / index.js
Last active March 23, 2017 20:30
hackathon.js
/*
npm install async
npm install request
npm install fs
npm install shuffle-array
npm install string-format
usage: node index.js fileWithMasterIds.txt
*/