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 fpinscala | |
| object Test { | |
| sealed trait Number | |
| sealed trait Positive extends Number | |
| case object Zero extends Positive with Negative | |
| case class Succ[P <: Positive](prev: P) extends Positive |
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
| val danger = "YIKES!" | |
| val secret = "hui840" |
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
| val autoInterpolated = s"problem occurred $danger, id: $secret" | |
| => autoInterpolated: String = problem occurred YIKES!, id: hui840 |
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
| val manualInterpolated = | |
| StringContext( | |
| "problem occurred ", ", id: ", "" | |
| ).s( | |
| danger, secret | |
| ) |
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 Scrubbed(danger: String, safe: String) { | |
| override val toString = safe | |
| } | |
| implicit class Scrubber(val sc: StringContext) extends AnyVal { | |
| def scrub(args: Any*): Scrubbed = { | |
| Scrubbed( | |
| sc.s(args: _*), | |
| sc.s(args.map(_ => "*****"): _*) |
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
| val scrubbed = scrub"problem occurred $danger, id: $secret" | |
| => scrubbed: Scrubbed = problem occurred *****, id: ***** |
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
| val safeLogLine = scrubbed.safe | |
| val secretLogLine = scrubbed.danger | |
| safeLogLine: String = problem occurred *****, id: ***** | |
| secretLogLine: String = problem occurred YIKES!, id: hui840 |
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 publicKey = postman.getEnvironmentVariable('apple-news-keyId') || ''; | |
| var secretKey = postman.getEnvironmentVariable('apple-news-keySecret') || ''; | |
| const decodedKey = CryptoJS.enc.Base64.parse(secretKey) | |
| const date = (new Date()).toISOString().split('.')[0]+"Z"; | |
| var sign = "GET" + request.url + "" + date; | |
| const hmacDigest = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(sign, decodedKey)); | |
| postman.setGlobalVariable("hmac", "HHMAC; key=" + publicKey + "; signature=" + hmacDigest + "; date=" + date); |