This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mainLoop() : Unit@cps[Future[Any]] = { | |
while (true) { | |
val fut = Promise.successful(new Array[Byte](1000000*100)).future // 100MB | |
// This shift is the same as Akka DataFlow's DataflowFuture.apply() | |
val result = shift { onComplete: (Array[Byte] => Future[Any]) => | |
fut flatMap onComplete | |
} | |
println(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatMap[S](f: T => Future[S])(implicit executor: ExecutionContext): Future[S] = { | |
val p = Promise[S]() | |
onComplete { | |
case f: Failure[_] => p complete f.asInstanceOf[Failure[S]] | |
case Success(v) => { | |
val tempP = p | |
try { | |
f(v).onComplete({ | |
case f: Failure[_] => tempP complete f.asInstanceOf[Failure[S]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyOpt[T] { | |
private var _name : String = null | |
def name = _name | |
} | |
abstract class BaseConfig { | |
protected def opt[T](unused : Int = 0) : MyOpt[T] = new MyOpt[T] | |
protected def onVerify { | |
val field = classOf[MyOpt[_]].getDeclaredField("_name") | |
field.setAccessible(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x; | |
for (x = 1; x < 10; x++) { | |
twait {; | |
setTimeout(defer(), 100); | |
}; | |
console.log('hello ' + x); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thing = (function() { | |
var private_name; | |
__extends(Thing, EventEmitter); | |
function Thing(name) { | |
private_name = name; | |
} | |
return Thing; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.getSelectedIds = function() { | |
var ids = []; | |
$.each(elem.find(".jfmfs-friend.selected"), function(i, friend) { | |
ids.push({id:$(friend).attr("data-id"), name:$(friend).find('.friend-name').text()}); | |
}); | |
return ids; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for GAE - tries get the image size... not too efficient... | |
# could throw lots of different exceptions, including DeadlineExceededError | |
class ImageBlobHelper(object): | |
@staticmethod | |
def TryGetWidthHeight(blobinfo, read_increments = 32768): | |
total_read = 0 | |
blob_key = blobinfo.key(); | |
data = '' | |
while total_read < blobinfo.size: | |
data_read = blobstore.fetch_data(blob_key, total_read, total_read+read_increments) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see http://github.com/amirshim/plupload/commit/edf12ae91a361c63260e5228ee7fc0e8934819fd | |
// and http://github.com/moxiecode/plupload/issues/issue/73 | |
var preUploadCb = function(file, onComplete) { | |
up = this; | |
up.settings.url = null; | |
$.ajax({ | |
url: '/upload/generate_upload_url', | |
success: function(data) { | |
up.settings.url = data; |