Skip to content

Instantly share code, notes, and snippets.

View arschles's full-sized avatar
🎯
Focusing

Aaron Schlesinger arschles

🎯
Focusing
View GitHub Profile
@arschles
arschles / single-consumer-mailbox.scala
Created April 18, 2014 00:28
single consumer mailbox example
import akka.actor.{Props, Actor, ActorSystem}
class A extends Actor {
override def receive = {
case other => println(other)
}
}
object Main extends App {
val system = ActorSystem("main")
@arschles
arschles / handlerwrap.go
Last active August 29, 2015 14:23
go handler wrapping
func myHandlerFunc(i int) http.HanderFunc {
return func(w http.ResponseWriter, r *http.Request) {
str := fmt.Sprintf("hello %d", i)
w.Write([]byte(str))
}
}
@arschles
arschles / readline.go
Created July 15, 2015 16:21
golang read a file line by line
import (
"bufio"
"os"
)
func main() {
f := os.Open("somefile")
defer f.Close
rdr := bufio.NewReader(f)
for {
var (
ErrInvalidCommand = errors.New("invalid command")
ErrInvalidNumArgs = errors.New("wrong num args")
ErrInvalidInt = errors.New("invalid int")
)
const (
create = "CREATE"
modify = "MODIFY"
set = "SET"
package main
import "github.com/gorilla/mux"
func main() {
r := mux.NewRouter()
r.HandleFunc("/reservations/{key}", func1).Methods("POST")
r.HandleFunc("/values/{key}/{lock_id}", func2).Queries("release", "").Methods("POST")
r.HandleFunc("/values/{key}", func3).Methods("PUT")
@arschles
arschles / PhotosLoader1.scala
Created October 29, 2011 20:11
Android PhotosLoader in Scala
import scala.actor._
class PhotosLoader extends Actor {
override def act() {
loop {
react {
case photoToLoad:PhotoToLoad =>
val bmp = getBitmap(photoToLoad.url)
if(bmp != null) {
@arschles
arschles / gist:2288251
Created April 3, 2012 00:27
Making the StackMob Java Client SDK do a synchronous get call
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
arschles / asyncget.java
Created May 25, 2012 19:29
HttpService Async GET Requests
@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();
@arschles
arschles / simpleget.java
Created May 25, 2012 19:28
HttpService Simple GET Request
@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);
@arschles
arschles / iteratee.scala
Created May 31, 2012 00:16
Iteratee recollection from memory
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)