Skip to content

Instantly share code, notes, and snippets.


Aaron Schlesinger arschles

View GitHub Profile
arschles / PhotosLoader1.scala
Created Oct 29, 2011
Android PhotosLoader in Scala
View PhotosLoader1.scala
class PhotosLoader extends Actor {
override def act() {
loop {
react {
case photoToLoad:PhotoToLoad =>
val bmp = getBitmap(photoToLoad.url)
if(bmp != null) {
arschles / gist:2288158
Created Apr 3, 2012
Scala PhoneGap Build Client
View gist:2288158
val BaseBuildURL = ""
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)
new BasicHeader(HttpHeaders.AUTHORIZATION, "Basic %s".format(authString)),
new BasicHeader(HttpHeaders.ACCEPT, "*/*"),
arschles / gist:2288251
Created Apr 3, 2012
Making the StackMob Java Client SDK do a synchronous get call
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
arschles /
Created May 25, 2012
HttpService Simple GET Request
public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider provider) {
HttpService http = provider.getHttpService();
String url = "";
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);
arschles /
Created May 25, 2012
HttpService Async GET Requests
public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider provider) {
String url1 = "";
GetRequest req1 = new GetRequest(url1);
String url2 = "";
GetRequest req2 = new GetRequest(url2);
String url3 = "";
GetRequest req3 = new GetRequest(url3);
HttpService http = provider.getHttpService();
arschles / iteratee.scala
Created May 31, 2012
Iteratee recollection from memory
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)
arschles /
Created May 31, 2012
StackMob with Python
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):
arschles / typesafeEquals.scala
Created Jun 20, 2012
How to use === in scalaz
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)
arschles /
Created Jul 5, 2012
OAuth Signing with StackMob Custom Code's HttpService
//goes in src/main/java/com/stackmob/oauthhttpservice
package com.stackmob.oauthhttpservice;
import org.scribe.model.Token;
import org.scribe.builder.api.DefaultApi10a;
class HttpRequestSignerAPI extends DefaultApi10a {
public static class TimeService extends TimestampServiceImpl {
arschles /
Created Jul 11, 2012
Registering an iOS push token from the stackmob-java-client-sdk
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);