function a() {
return new Promise((resolve, reject)=> {
setTimeout(function() { reject('//a') }, 100);
})
}
async function b() {
This file contains hidden or 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 koa = require('koa')(); | |
koa.use(function* (next) { | |
//do something before yielding/passing to next generator function in line which will be 1st event in downstream | |
console.log("===1==="); | |
console.log("A"); | |
yield next; | |
// do something when the execution returns upstream, this will be last event in upstream | |
console.log("B"); |
This file contains hidden or 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
Future.sequence( | |
Option.empty[Seq[Int]].getOrElse(throw new RuntimeException("mA")).map(Future.apply(_)) | |
) recover { | |
case e: Throwable => throw new RuntimeException("mB") | |
} | |
// // Exiting paste mode, now interpreting. | |
// java.lang.RuntimeException: mA |
<TouchableHighlight
style={styles.button}
onPress = {this._handleSubmit`()`}> // would cuz [self executeBlockOnJavaScriptQueue:RCTProfileBlock((^{
<Text style={styles.buttonText}>Search</Text>
</TouchableHighlight>
This file contains hidden or 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
case class Page[A](items: Seq[A], page: Int, offset: Long, total: Long) { | |
lazy val prev = Option(page - 1).filter(_ >= 0) | |
lazy val next = Option(page + 1).filter(_ => (offset + items.size) < total) | |
} |
This file contains hidden or 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
/** | |
* queryStringをFakeRequestに入れるユーティリティ | |
* FakeRequest().copy(queryString = qs)にすると、戻り値が | |
* Iteratee[Array[Byte], Result] となるため、これを Future[B] へ fold します | |
* | |
* //usage: | |
* // val actual = controller.purchase()(FakeRequest().copy( | |
* // queryString = validBuyingRequestParams)) fold toFuture | |
*/ | |
def toFuture[B](step: Step[Array[Byte], B]): Future[B] = step match { |
This file contains hidden or 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
package operator | |
object Functional { | |
class PipedObject[T] private[Functional] (value:T) | |
{ | |
def |>[R] (f : T => R) = f(this.value) | |
} | |
implicit def toPiped[T] (value:T) = new PipedObject[T](value) | |
} |
This file contains hidden or 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
object NameParser2 extends RegexParsers { | |
case class Name(first: String, last: String) | |
def name:Parser[String] = "[a-zA-Z]+".r | |
def fullName = rep(name) ^^ { names => | |
Name(names.head, names(1)) | |
} | |
def parse(input: String) = parseAll(fullName, input) match { | |
case Success(result, _) => | |
result | |
case failure : NoSuccess => scala.sys.error(failure.msg) |
This file contains hidden or 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
#!/bin/bash | |
REMOTE=play@SERVER_IP | |
REMOTE_APP=/home/play/PROJECT_NAME/ | |
sbt stage || exit 1; | |
rsync -va target/ $REMOTE:$REMOTE_APP/target; | |
ssh $REMOTE "cd $REMOTE_APP; ./stop.sh"; | |
ssh $REMOTE "cd $REMOTE_APP; ./start.sh"; |
This file contains hidden or 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 is an example of how to scrape the web using PhantomJS and jQuery: | |
//source: http://snippets.aktagon.com/snippets/534-How-to-scrape-web-pages-with-PhantomJS-and-jQuery | |
//http://phantomjs.org/ | |
var page = new WebPage(), | |
url = 'http://localhost/a-search-form', | |
stepIndex = 0; | |
/** | |
* From PhantomJS documentation: |