Skip to content

Instantly share code, notes, and snippets.

View deanh's full-sized avatar

Harry Dean Hudson deanh

  • Ableton
  • Berlin, DE
View GitHub Profile
<!DOCTYPE html>
<html>
<head></head>
<body>
<script src="http://connect.soundcloud.com/sdk-2.0.0.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
client_id: 'YOUR_CLIENT_ID',
});
class List
attr_reader :head, :tail
def self.from_ar ar
if h = ar.shift
self.new h, self.from_ar(ar)
end
end
def initialize head, tail = nil
get("/a/:id", operation(getA)) {
val id = params("id")
val idType = params.getOrElse("id_type", "a_id")
new AsyncResult {
val is: Future[_] = resolveId(id, idType) flatMap { aid =>
val frm = future { s /*}oing something more in the real code */ }map { s =>
responseMetaData(s.id)
}
frm flatMap { rm =>
oa@:~/oa$ curl -XGET 'http://api.openaura.com/v1/classic/artists/47?id_type=oa%3Aartist_id&api_key=YOUR_API_KEY'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3439 0 3439 0 0 15900 0 --:--:-- --:--:-- --:--:-- 28188
{
"request_info": {
"oa_anchor_id": "528fde50e4b084ba1571c831",
"request_id": "809FF3B14C169677C6E08D333E0114E8DFA0559B",
"timestamp": "2014-03-11T19:58:22.355Z"
},
before() {
contentType = "image/gif"
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate")
response.setHeader("Pragma", "no-cache")
response.setHeader("Expires", "0")
}
get("/request_code/:id.gif") {
val id = params("id")
(! 613)-> curl -XGET 'http://api.openaura.com/search/artists?q=taylor&limit=5&api_key=YOUR_API_KEY'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 523 0 523 0 0 1131 0 --:--:-- --:--:-- --:--:-- 1330
[ { oa_artist_id: '47',
name: 'Taylor Swift',
musicbrainz_id: '20244d07-534f-4eff-b4d4-930878889970' },
{ oa_artist_id: '13791',
name: 'Gillian Taylor',
musicbrainz_id: '6cfddc45-bf8b-46a5-b471-297b25b55fa9' },
(! 612)-> curl -XGET 'http://api.openaura.com/search/artists?q=taylor&api_key=YOUR_KEY'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 10738 0 10738 0 0 61448 0 --:--:-- --:--:-- --:--:-- 81348
[ { oa_artist_id: '47',
name: 'Taylor Swift',
musicbrainz_id: '20244d07-534f-4eff-b4d4-930878889970' },
{ oa_artist_id: '13791',
name: 'Gillian Taylor',
musicbrainz_id: '6cfddc45-bf8b-46a5-b471-297b25b55fa9' },
package net.openaura.util
import com.twitter.util.{Future => FinagleFuture}
import scala.concurrent.{Promise, ExecutionContext, Future}
object FinagleImplicits {
implicit def finagleFuture2AkkaFuture[A](future: FinagleFuture[A])(implicit executor: ExecutionContext): Future[_] = {
val promise = Promise[A]
future onSuccess { result =>
promise.success(result)
@deanh
deanh / gist:6429841
Last active December 22, 2015 06:18
get("/thing/:id", operation(getThingAuraById)) {
val id = params("id")
val Some(limit) = ParamValidator.asInteger(params.getOrElse("limit", "100"))
val Some(offset) = ParamValidator.asInteger(params.getOrElse("offset", "0"))
ParamValidator.asInteger(id) match {
case Some(id) => {
new AsyncResult { val is =
// this returns a Finagle Future - I want an implicit in scope here to do the
// conversion
auraClient.auraByThingId(id, limit = limit, offset = offset) map { aura =>
@deanh
deanh / gist:6164844
Created August 6, 2013 14:13
Recursive Merge Sort.
// merge calls itself recursively
def merge(l1: List[Int], l2: List[Int]): List[Int] = {
// termination cases
if (l1.length == 0 && l2.length == 0) return Nil
if (l1.length == 0) return l2.head :: merge(Nil, l2.tail)
if (l2.length == 0) return l1.head :: merge(Nil, l1.tail)
l1.head.compare(l2.head) match {
case -1 => l1.head :: merge(l1.tail, l2)
case _ => l2.head :: merge(l2.tail, l1)
}