Skip to content

Instantly share code, notes, and snippets.

View kcleereman's full-sized avatar

Kevin Cleereman kcleereman

  • Terracotta
  • Boise ID
View GitHub Profile
def annotate(text: String, field: String): String = {
def prependHttp(s: String): String = if (!(s.startsWith("http://") || s.startsWith("https://"))) "http://" + s else s
{
val preprocessed = text.replaceAll(System.getProperty("line.separator"), " ")
pattern.findAllMatchIn(preprocessed).toList.map(m => {
Option(m.subgroups(0)).flatMap(token => {
symbolCode.get(token.slice(0, 1)).map(sym => Seq(sym, field, m.start(1).toString, m.end(1).toString, token, token.substring(1)))
}).getOrElse(Seq.empty[String]).mkString("|")
}) ++ urls.findAllMatchIn(preprocessed).toList.filterNot(m => {
def totalsByItemQ(itemType: String, itemIds: Seq[Int]) = {
val dbItemType = itemType.toDBItemType
val idList = itemIds.mkString(",")
sql"""
select subject_id, subject_type, NULL AS user_id, count(id), 'likes' from likes where subject_type=$dbItemType and subject_id in (#$idList) group by subject_id, subject_type
union
select subject_id, subject_type, NULL AS user_id, count(id), 'follows' from follows where subject_type=$dbItemType and subject_id in (#$idList) group by subject_id, subject_type
union
select recipient_id, recipient_type, NULL AS user_id, count(id), 'posts' from posts where recipient_type=$dbItemType and recipient_id in (#$idList) group by recipient_id, recipient_type
union
def compareJsValue(mapped: JsValue, rendered: JsValue): Boolean = {
(mapped, rendered) match {
case (m: JsArray, r: JsArray) => compareJsArray(m, r)
case (JsBoolean(m), JsBoolean(r)) => m == r
case (JsNull, JsNull) => true
case (JsNumber(m), JsNumber(r)) => m == r
case (m: JsObject, r: JsObject) => compareJsObject(m, r)
case (JsString(m), JsString(r)) => m == r
case (m: JsUndefined, r: JsUndefined) => true
case _ => {
@kcleereman
kcleereman / gist:8542753
Last active January 4, 2016 00:39
copyMap macro
package com.sport195.api
import play.api.libs.json._
import scala.language.experimental.macros
object ImplicitConversions {
import java.sql.Timestamp
import java.sql.Date
implicit val x = scala.language.implicitConversions
object Dependencies {
...
val googleApi = "com.google.api-client" % "google-api-client" % "1.17.0-rc"
val googleJackson = "com.google.api-client" % "google-api-client-jackson2" % "1.17.0-rc"
val gdata = "com.google.gdata" % "core" % "1.47.1"
...
}
trait BallerUploadService extends UploadService {
...
private val youTubeService: YouTubeService = {
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleOAuthConstants
val devKey = ""
val service = new YouTubeService("Blank", devKey)