Skip to content

Instantly share code, notes, and snippets.

@dhoss
dhoss / Client.scala
Created July 29, 2015 21:45
how do i make this concurrent?
// we want to be asynchronous here because we are doing several API calls
def crawlProjectRepos(project: String):Future[List[RepositoryCommitList]] = {
Logger.info("crawling " + project + " by API")
val repos = reposFor(project)
Logger.debug("REPOS " + repos)
for (repo <- repos ) {
Logger.info("REPO STATUS FOR " + repo + " : " + Await.result(callApi(buildCommitUrl(project, repo)), Duration.Inf))
}
val goodRepos = for {
@dhoss
dhoss / Client.scala
Created July 29, 2015 18:48
skip if status != 200
// we want to be asynchronous here because we are doing several API calls
def crawlProjectRepos(project: String):Future[RepositoryCommitList] = {
Logger.info("crawling " + project + " by API")
val repos = reposFor(project)
val commitList:scala.collection.mutable.ListBuffer[Commit] = scala.collection.mutable.ListBuffer[Commit]()
val commits = for {
repo <- repos;
c <- callApi(buildCommitUrl(project, repo));
rc <- breakable {
if ( c.status != 200 ) {
@dhoss
dhoss / Client.scala
Last active August 29, 2015 14:26
json issues
// we want to be asynchronous here because we are doing several API calls
def crawlProjectRepos(project: String) = {
implicit val commitReads: Reads[Commit] = (
(JsPath \ "id").read[Long] and
(JsPath \ "gitId").read[String] and
(JsPath \ "message").read[String] and
(JsPath \ "author" \ "name").read[String] and
(JsPath \ "author" \ "emailAddress").read[String] and
(JsPath \ "authorTimestamp").read[Option[DateTime]](Reads.optionWithNull(jodaDateReads("yyyy-MM-dd'T'HH:mm:ss'Z")))
)(Commit.apply _)
@dhoss
dhoss / gist:206aec529560d257cf40
Created July 25, 2015 19:48
gstreamer issues
go run camrelay.go
libva info: VA-API version 0.37.0
libva info: va_getDriverName() returns -1
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
libva info: VA-API version 0.37.0
libva info: va_getDriverName() returns -1
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
libva info: VA-API version 0.37.0
libva info: va_getDriverName() returns -1
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
@dhoss
dhoss / errors.txt
Created July 23, 2015 18:11
play sbt plugin repo issues
[warn] ==== local: tried
[warn] /root/.ivy2/local/com.typesafe.sbt/sbt-coffeescript/scala_2.10/sbt_0.13/1.0.0/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/com/typesafe/sbt/sbt-coffeescript_2.10_0.13/1.0.0/sbt-coffeescript-1.0.0.pom
[warn] ==== Typesafe repository: tried
[warn] https://repo.typesafe.com/typesafe/releases/com/typesafe/sbt/sbt-coffeescript_2.10_0.13/1.0.0/sbt-coffeescript-1.0.0.pom
[warn] ==== Typesafe Maven Repository: tried
[warn] http://repo.typesafe.com/typesafe/maven-releases/com/typesafe/sbt/sbt-coffeescript_2.10_0.13/1.0.0/sbt-coffeescript-1.0.0.pom
[warn] ==== scalaz-bintray: tried
[warn] http://dl.bintray.com/scalaz/releases/com/typesafe/sbt/sbt-coffeescript_2.10_0.13/1.0.0/sbt-coffeescript-1.0.0.pom
dbf.flatMap { case Nil => api future; case stuff => Future.succes(stuff) }
@dhoss
dhoss / errors.txt
Created July 19, 2015 23:25
gstreamer issues
devin@fartorias:~/go/src/github.com/ziutek/gst/examples$ GST_DEBUG=3 go run live_webm.go
0:00:00.501007625 18266 0x22bb290 WARN structure gststructure.c:195:gst_structure_validate_name: Invalid character ',' at offset 11 in structure name: video/x-raw,format=yuv
(live_webm:18266): GStreamer-CRITICAL **: gst_structure_new_empty: assertion 'gst_structure_validate_name (name)' failed
(live_webm:18266): GStreamer-CRITICAL **: gst_structure_take_value: assertion 'structure != NULL' failed
(live_webm:18266): GStreamer-CRITICAL **: gst_structure_take_value: assertion 'structure != NULL' failed
(live_webm:18266): GStreamer-CRITICAL **: gst_structure_take_value: assertion 'structure != NULL' failed
@dhoss
dhoss / Stash.scala
Created July 17, 2015 21:05
trying to transform JSON
// we want to be asynchronous here because we are doing several API calls
def crawlProjectRepos(project: String) = {
val repos = reposFor(project)
val commits = for (repo <- repos)
yield for (c <- callApi(buildCommitUrl(project, repo)))
// not going to worry about creating a Commit object right now
// this is faster and when it comes time to insert info
// into the db, we can just pull out the values needed
yield Map(repo -> (c \ "values").as[List[JsValue]])
@dhoss
dhoss / Stash.scala
Created July 16, 2015 16:56
trying to catch 404s
def callApi(url:String): Future[JsValue] = {
implicit val context = play.api.libs.concurrent.Execution.Implicits.defaultContext
val urlWithParams = url + "?" + pageSizeParam
val request: WSRequest = ws.url(urlWithParams)
val response = request.withHeaders(
"Accept" -> "application/json",
"Authorization" -> "Basic .....")
.get().map { response =>
if (response.status == 200) {
response.json
@dhoss
dhoss / ModelSpec.scala
Created July 15, 2015 20:43
scala future issues
"crawlProjectRepos" should {
"successfully hit each URL in the list" in new WithApplication {
val crawler = new Stash(25)
for (commitMap <- Await.result(crawler.crawlProjectRepos(project), Duration.Inf)) {
commitMap must not be empty
commitMap must have length(be_<=(25))
for ((repo, commitList) <- commitMap) {
commitList must not be empty
commitList must have length(be_<=(25))
}