Skip to content

Instantly share code, notes, and snippets.

View maowug's full-sized avatar
🏠
Working from whitehouse

u.go maowug

🏠
Working from whitehouse
View GitHub Profile
@maowug
maowug / asyc.md
Last active March 21, 2016 10:10
asyc try-catch
function a() {
  return new Promise((resolve, reject)=> {
    setTimeout(function() { reject('//a') }, 100);
  })
}

async function b() {
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");
@maowug
maowug / gist:88124aeed2eb66af48d4
Last active December 18, 2015 04:18
fseq doesnt wrap it
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
@maowug
maowug / gist:f758bd57dc7ec550f2ca
Created November 16, 2015 13:29
react-native bug1
<TouchableHighlight
  style={styles.button}
  onPress = {this._handleSubmit`()`}> // would cuz   [self executeBlockOnJavaScriptQueue:RCTProfileBlock((^{
  <Text style={styles.buttonText}>Search</Text>
</TouchableHighlight>
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)
}
/**
* 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 {
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)
}
@maowug
maowug / NameParser2.scala
Created September 10, 2015 00:13
Calculator parser and NameParser2
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)
@maowug
maowug / deploy.sh
Last active September 7, 2015 11:58 — forked from gre/deploy.sh
Super-small scripts for easy PlayFramework deployment
#!/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";
@maowug
maowug / jQueryPhantomScrape.js
Created August 31, 2015 11:42 — forked from crazy4groovy/jQueryPhantomScrape
Scrape the web using PhantomJS and jQuery
//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: