View PhotosLoader1.scala
import scala.actor._ | |
class PhotosLoader extends Actor { | |
override def act() { | |
loop { | |
react { | |
case photoToLoad:PhotoToLoad => | |
val bmp = getBitmap(photoToLoad.url) | |
if(bmp != null) { |
View gist:2288158
val BaseBuildURL = "https://build.phonegap.com/api/v1" | |
val UTF8Charset = Charset.forName("UTF-8") | |
case class MultipartInfo(contentType: Header, contentEncoding: Option[Header]) | |
val baseHeaders: List[Header] = { | |
val authRaw = "%s:%s".format(phoneGapCreds.username, phoneGapCreds.password) | |
val authBase64 = Base64.encodeBase64(authRaw.getBytes(UTF8Charset)) | |
val authString = new String(authBase64, UTF8Charset) | |
List( | |
new BasicHeader(HttpHeaders.AUTHORIZATION, "Basic %s".format(authString)), | |
new BasicHeader(HttpHeaders.ACCEPT, "*/*"), |
View gist:2288251
package my.package | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.atomic.AtomicReference; | |
import java.util.concurrent.TimeUnit; | |
import java.util.Map; | |
import java.util.HashMap; | |
long requestTimeout = 5; | |
TimeUnit requestTimeoutUnit = TimeUnit.SECONDS;//wait max 5 seconds for StackMob requests to return. if longer, fail |
View simpleget.java
@Override | |
public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider provider) { | |
HttpService http = provider.getHttpService(); | |
String url = "http://stackmob.com"; | |
GetRequest req = new GetRequest(url); | |
HttpResponse resp = http.get(req); | |
Map<String, String> map = new HashMap<String, String>(); | |
map.put("response_code", resp.getCode()); | |
map.put("url", url); | |
return new ResponseToProcess(HttpURLConnection.HTTP_OK, map); |
View asyncget.java
@Override | |
public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider provider) { | |
String url1 = "http://www.bing.com/search?q=kawasaki+ninja"; | |
GetRequest req1 = new GetRequest(url1); | |
String url2 = "http://www.bing.com/search?q=honda+nighthawk"; | |
GetRequest req2 = new GetRequest(url2); | |
String url3 = "http://www.bing.com/search?q=bmw+1300s"; | |
GetRequest req3 = new GetRequest(url3); | |
HttpService http = provider.getHttpService(); |
View iteratee.scala
import scalaz._ | |
import Scalaz._ | |
import scalaz.concurrent._ | |
import java.util.concurrent.atomic._ | |
//the representation of a "chunk" of data (including errors or EOF) | |
//this was the best name I could ever come up with, but it seems like there's a better one | |
sealed trait Chunk { | |
def fold[T](valid: Array[Byte] => T, error: Throwable => T, eof: => T) = this match { | |
case ValidBytes(data) => valid(data) |
View stackmob.py
import oauth.oauth as oauth | |
import httplib | |
import json | |
import sys | |
PUBLIC_KEY = "68023efc-6b09-42d0-9b43-18c531d79a98" | |
PRIVATE_KEY = "f41c5002-64c0-46c1-b249-b667866ba305" | |
class Client: | |
def __init__(self, url, key, secret): |
View typesafeEquals.scala
//declare the data structure and the Equal instance | |
import scalaz._ | |
import Scalaz._ | |
case class MyThing(thing1: String, thing2: String) | |
object MyThing { | |
implicit def MyThingEqual = new Equal[MyThing] { | |
override def equal(t1: MyThing, t2: MyThing) = (t1.thing1 === t2.thing1) && (t1.thing2 === t2.thing2) | |
} |
View HttpRequestSignerAPI.java
//goes in src/main/java/com/stackmob/oauthhttpservice | |
package com.stackmob.oauthhttpservice; | |
import org.scribe.services.TimestampService; | |
import org.scribe.services.TimestampServiceImpl; | |
import org.scribe.model.Token; | |
import org.scribe.builder.api.DefaultApi10a; | |
class HttpRequestSignerAPI extends DefaultApi10a { | |
public static class TimeService extends TimestampServiceImpl { |
View registerIOS.java
StackMob.RegistrationIDAndUser json = new StackMob.RegistrationIDAndUser("a88fqsdg8as87rgq87wrg8as8dg78zDf8a98sdf98asd8fa7sdf", "johnsmith", "ios"); | |
stackmob.postPush("register_device_token_universal", json, newStackMobCallback() { | |
@Override public void success(String responseBody) { | |
//responseBody will be a list of MyObject instances | |
//do something with your objects | |
Logger.debug("stackmob success"); | |
} | |
@Override public void failure(StackMobException e) { | |
//handle the failure | |
Logger.debug("stackmob fail" + e); |
OlderNewer