Skip to content

Instantly share code, notes, and snippets.

View hamnis's full-sized avatar

Erlend Hamnaberg hamnis

View GitHub Profile
package unfilteredx
import unfiltered.response.{ContentLength, InternalServerError, ResponseFunction}
import scala.language.implicitConversions
import scala.language.higherKinds
import scala.concurrent.{ExecutionContext, Future}
import d2.{Result, Directive, Directives}
package recsys
import org.apache.spark.SparkContext._
import org.apache.spark.mllib.recommendation.{MatrixFactorizationModel, Rating}
import org.apache.spark.rdd.RDD
import org.jblas.DoubleMatrix
import org.slf4j.LoggerFactory
package object collaborative {
implicit class MatrixFactorizationModelOps(val m: MatrixFactorizationModel) extends AnyVal {
def string[T](req: HttpRequest[T])(implicit codec: Codec = Codec.UTF8) = {
loan(new InputStreamReader(req.inputStream, codec.charSet)) { reader =>
val writer = new java.io.StringWriter
val ca = new Array[Char](4096)
@scala.annotation.tailrec def read() {
val len = reader.read(ca)
if (len > 0) writer.write(ca, 0, len)
if (len >= 0) read
}
read()
#!/bin/bash
jq "{template: .collection.template}"
package emsnav
import dispatch._, Defaults._
import java.net.URI
import net.hamnaberg.json.collection._
import concurrent.Await
import concurrent.duration._
object Main extends App {
val MediaType = "application/vnd.collection+json"
package unfilteredx.logging
import unfiltered.request._
import unfiltered.response._
import unfiltered.Cycle
import com.typesafe.scalalogging.Logger
import org.slf4j.LoggerFactory
object TraceLogging {
def apply[A, B](intent: Cycle.Intent[A, B])(implicit tl: TraceLogger[A, B]) =
@hamnis
hamnis / 0_reuse_code.js
Created June 2, 2014 06:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
import net.hamnaberg.funclite.*;
public class Collect {
public static <A, B> Option<B> collect(A value, Predicate<A> p, Function<A, B> f) {
if (p.apply(value)) {
return Option.fromNullable(f.apply(value));
}
return Option.none();
}
{
"templates": [
{
"data": [
{"name": "synth-id", "value": "urn:uuid:536c2060-c9ea-4781-97d9-12d6f717a88c"},
{"name": "foo", "value": "bar"}
]
},
{
"data": [
diff --git a/spec/ems_spec.rb b/spec/ems_spec.rb
index 9620341..93732ed 100755
--- a/spec/ems_spec.rb
+++ b/spec/ems_spec.rb
@@ -117,14 +117,14 @@ describe 'EMS' do
collection['href'].should eql collection_url
end
- %w(format body state audience slug title lang summary level).each do |field|
+ %w(format body state title lang summary level).each do |field|