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
function* idMaker(prefix){ | |
let idx = 0; | |
while(true){ | |
yield `${prefix}_${idx++}`; | |
} | |
} | |
let users = idMaker("user"); | |
console.log(users.next()) // {"value":"user_0","done":false} | |
console.log(users.next()) // {"value":"user_1","done":false} |
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
scala> var s: Option[String] = None | |
scala> s = None | |
scala> s.foreach {_ => | |
| s = Some("some") | |
| } | |
scala> 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
package quickstart.action | |
import java.util.concurrent.TimeUnit | |
import scala.util.Random | |
import io.netty.channel.{ChannelFuture, ChannelFutureListener} | |
import io.netty.util.{HashedWheelTimer, TimerTask, Timeout} | |
import xitrum.{Action, SkipCsrfCheck} | |
import xitrum.annotation.GET |
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
scala > for (i <- 0 to 17){ | |
| val token = scala.util.Random.alphanumeric.take(29).map{s => "%02x".format(s.toByte)}.mkString("") + "%06x".format(i) | |
| println(token) | |
| } | |
39514f6965667341367934535a5272513766653353444c565557736942000000 | |
3337534c71664c674a7543657a51427242417376446173455038667044000001 | |
414f696a744c714866376749683551393772794b663074543561687063000002 | |
536e4c5a4c5a69784571757672394e537564446c4f31786a5357594f61000003 | |
65335a46306932495a437351513974514f4875323932516f52396c6e79000004 |
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
git rev-parse --short HEAD |
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 genGen = function(arr, loop){ | |
return (function* (){ | |
var idx = 0; | |
var len = arr.length | |
while(true){ | |
if (len === idx && loop) idx = 0; | |
yield arr[idx++]; | |
} | |
})(); | |
}; |
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
# https://docs.oracle.com/cd/E19416-01/820-5959/6nhaosbus/index.html | |
# http://wiki.eclipse.org/Jetty/Howto/Configure_SSL | |
openssl pkcs12 -export \ | |
-in ./my.crt \ | |
-inkey ./my.key \ | |
-certfile intermediate.crt \ | |
-out ./keystore.pkcs12 \ | |
-name "xitrum" |
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
function createPromise(name){ | |
return new Promise(function(resolve, reject){ | |
setTimeout(function(){ | |
if (Date.now()%2 === 0) { | |
console.log(name+" is reolved"); | |
resolve(name+"_success"); | |
}else{ | |
console.log(name+" is rejected"); | |
reject(name+"_fail"); | |
} |
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
function parse(val){ | |
return Promise.resolve().then(function(){ | |
return JSON.parse(val); | |
}); | |
} | |
function parse2(val){ | |
return new Promise(function(resolve, reject){ | |
try{ | |
resolve(JSON.parse(val)); |
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
encrypt | |
------- | |
$ echo "Hello World" | openssl enc -e -des -base64 -out encrypted -k myKey | |
result | |
------- | |
$ cat encrypted | |
U2FsdGVkX19pZy6kjZ4GTbTNeKeI1lWvoLjrpBqy0bw= | |
decrypt |