Skip to content

Instantly share code, notes, and snippets.

View agemooij's full-sized avatar

Age Mooij agemooij

View GitHub Profile
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
class StackSpec extends FlatSpec with ShouldMatchers {
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.pop() should equal (2)
#import "ActionViewController.h"
@implementation ActionViewController
@synthesize startButton;
@synthesize stopOrContinueButton;
- (IBAction) startButtonPressed {
NSLog(@"start button pressed");
@agemooij
agemooij / gist:349566
Created March 30, 2010 20:37
Some Gradle code
repositories {
....
add(new org.apache.ivy.plugins.resolver.URLResolver()) {
name = "GitHub"
addArtifactPattern 'http://github.com/asikkema/adoptimizer/downloads/[organization]-[module]-[revision].[ext]'
}
}
@agemooij
agemooij / MongoRepository.scala
Created December 30, 2010 12:13
A base trait for creating and managing a mongoDB connection/collection
package com.agemooij.mongodb
import com.mongodb.casbah.Imports._
trait MongoRepository {
protected val host = "localhost"
protected val port = 27017
protected val databaseName = "agemooij"
protected val collectionName: String
@agemooij
agemooij / gist:768208
Created January 6, 2011 17:20
Possible problem with Salat serialization of Scala case class ?
package com.agemooij.test
import java.util.Date
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import com.mongodb.casbah.Imports._
object LinearFit2 {
case class Point(x: Double = 0.0, y: Double = 0.0) {
def +(that: Point): Point = Point(this.x + that.x, this.y + that.y)
}
implicit def tupleToPoint(tuple: (Double, Double)): Point = Point(tuple._1, tuple._2)
def through (points : Point*) : Point = through(points.toList)
def through (points : List[Point]) : Point = {
val total = points.foldLeft(Point())(_ + _)
@agemooij
agemooij / akkaLogAndReceive.scala
Created June 21, 2012 16:28
Akka: logging any received message
scala> :paste
// Entering paste mode (ctrl-D to finish)
def wrap(partial: PartialFunction[Any, Unit]): PartialFunction[Any, Unit] = new PartialFunction[Any, Unit] {
def isDefinedAt(a: Any): Boolean = partial.isDefinedAt(a)
def apply(a: Any): Unit = {
println("----> received " + a)
partial.apply(a)
}
}
@agemooij
agemooij / SprayAdaptiveGzipSupport.scala
Created October 20, 2012 16:32
SprayAdaptiveGzipSupport
trait SprayAdaptiveGzipSupport extends directives.EncodingDirectives {
import spray.httpx.encoding._
def withAdaptiveCompressionSupport: Directive0 =
(decodeRequest(NoEncoding) | decodeRequest(Gzip) | decodeRequest(Deflate)) &
(encodeResponse(NoEncoding) | encodeResponse(Gzip) | encodeResponse(Deflate))
}
object SprayAdaptiveGzipSupport extends SprayAdaptiveGzipSupport
[info] Compiling 1 Scala source to /Users/age/Development/src/agemooij/riak-scala-client/target/scala-2.10/test-classes...
01/19 23:59:09 DEBUG [akka://default/user/test-server]: SERVER: Starting akka://default/user/test-server on localhost/127.0.0.1:17249
01/19 23:59:09 INFO [akka://default/user/io-bridge]: akka://default/user/io-bridge started
01/19 23:59:09 DEBUG [akka://default/user/io-bridge]: SERVER: Executing Bind(localhost/127.0.0.1:17249,100,LogMark(SERVER))
01/19 23:59:09 INFO [akka://default/user/test-server]: SERVER: akka://default/user/test-server started on localhost/127.0.0.1:17249
01/19 23:59:09 DEBUG [akka://default/user/http-client/$a]: Opening connection 1 to localhost:17249
01/19 23:59:09 DEBUG [akka://default/user/io-bridge]: Executing Connect(localhost/127.0.0.1:17249,None,())
01/19 23:59:09 DEBUG [akka://default/user/io-bridge]: Connection request registered
01/19 23:59:09 DEBUG [akka://default/user/io-bridge]: SERVER: New connection accepted on localhost/127.0.0.1:17249
01/19 23:59:0