Skip to content

Instantly share code, notes, and snippets.

@freekh
freekh / ftlb.scala
Created October 12, 2011 18:35
n00b fault tolerant load balancing
package akka.training
import akka.actor.Supervisor
import akka.config.Supervision._
import akka.actor.Actor
import akka.actor.Actor._
import akka.routing._
import akka.config.Supervision.OneForOneStrategy
import akka.actor.RemoteActorRef
import akka.actor.ActorRef
@freekh
freekh / akkaCacheSBT.scala
Created October 13, 2011 14:38
Typesafe Akka SBT Cache 1.2
set name := "akka training"
set scalaVersion := "2.9.1"
set resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
set libraryDependencies ++= Seq("se.scalablesolutions.akka" % "akka-actor" % "1.2", "se.scalablesolutions.akka" % "akka-actor" % "1.2", "se.scalablesolutions.akka" % "akka-remote" % "1.2", "se.scalablesolutions.akka" % "akka-testkit" % "1.2", "se.scalablesolutions.akka" % "akka-stm" % "1.2", "org.scalatest" %% "scalatest" % "1.6.1" % "test", "junit" % "junit" % "4.5" % "test")
session save
@freekh
freekh / PresCode.scala
Created November 23, 2011 08:59
Akka Presentation: GOTO Prague 2011
import akka.actor._ //Actor
import akka.actor.Actor._ //actorOf
import akka.dispatch._ //Futures
import java.util.concurrent.CountDownLatch //Need for demo
//Create an Actor here...
class AnActor(var state : String) extends Actor {
@freekh
freekh / gist:1594123
Created January 11, 2012 10:45
Akka libraryDependencies
set libraryDependencies ++= Seq("se.scalablesolutions.akka" % "akka-actor" % "1.3-RC6", "se.scalablesolutions.akka" % "akka-actor" % "1.3-RC6", "se.scalablesolutions.akka" % "akka-remote" % "1.3-RC6", "se.scalablesolutions.akka" % "akka-testkit" % "1.3-RC6", "se.scalablesolutions.akka" % "akka-stm" % "1.3-RC6", "org.scalatest" %% "scalatest" % "1.6.1" % "test", "junit" % "junit" % "4.5" % "test")
session save
@freekh
freekh / FirstActor.scala
Created January 11, 2012 13:00
First Akka actor
//your first actor
class MyActor extends akka.actor.Actor {
def receive = { //when a message is received...
case m =>println(m.toString) //...print it out
}
}
val actorRef = akka.actor.Actor.actorOf[MyActor].start() //start the actor
actorRef ! "Congratulations from your first Akka actor" //send a message
actorRef ! akka.actor.PoisonPill //the actor will stop when this message is received
@freekh
freekh / InitVC.m
Created February 9, 2012 09:56
Init code in View controller
_asyncWrapper1 = [[AsyncURLWrapper alloc] initWithRequest:request2 delegate:self retries:5];
_asyncWrapper2 = [[AsyncURLWrapper alloc] initWithRequest:request1 delegate:self retries: 5];
@freekh
freekh / FinishCallback.m
Created February 9, 2012 10:07
Finish callback
- (void) didFinish: (NSData*) data sender: (AsyncURLWrapper*) blob
{
if (blob == _asyncWrapper1) {
NSLog(@"data 1: %@", data);
}
if (blob == _asyncWrapper2) {
NSLog(@"data 2: %@", data);
}
}
@freekh
freekh / ViewController.m
Created February 9, 2012 10:13
All callbacks
#pragma mark - AsyncURLWrapper delegates
- (void) didFinish: (NSData*) data sender: (AsyncURLWrapper*) blob
{
if (blob == _asyncWrapper1) {
NSLog(@"string from wrapper 1: %@", [AsyncURLWrapper asUTF8String:data]);
}
if (blob == _asyncWrapper2) {
NSLog(@"string from wrapper 2: %@", [AsyncURLWrapper asUTF8String:data]);
}
}
@freekh
freekh / AsyncURLWrapper.h
Created February 9, 2012 10:15
AsyncURLWrapper
#import <Foundation/Foundation.h>
@class AsyncURLWrapper;
@protocol AsyncURLWrapperDelegate <NSObject>
@optional
- (void) didFinish: (NSData*) data sender: (AsyncURLWrapper*) urlWrapper response: (NSHTTPURLResponse*) response;
- (void) didFail: (NSError*) error sender: (AsyncURLWrapper*) urlWrapper;
- (void) beforeRetry: (NSError*) error sender: (AsyncURLWrapper*) urlWrapper;
- (void) didUpdateProgress: (float) percentCompleted sender: (AsyncURLWrapper*) urlWrapper;
@freekh
freekh / infscroll.m
Created February 13, 2012 16:46
Infinity scroll
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y ==
self.table.contentSize.height - self.table.frame.size.height)
|| (self.table.contentSize.height - self.table.frame.size.height ) < 0) {
//When table is dragged this will be enabled
[self loadMoreElements];
}
}