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 org.photon.login | |
| import com.twitter.util.Future | |
| import org.photon.common.Async | |
| import java.sql.{PreparedStatement, Timestamp, ResultSet} | |
| import org.joda.time.Instant | |
| trait RepositoryComponentImpl[T, RepoT] { | |
| implicit def timestamp2instant(t: java.sql.Timestamp) = new Instant(t.getTime) | |
| implicit def instant2timestamp(i: org.joda.time.Instant) = new Timestamp(i.getMillis) |
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
| macro $do { | |
| rule { { $y:expr } } => { | |
| $y | |
| } | |
| rule { { $x:ident <- $y:expr $rest ... } } => { | |
| λ['>=']($y, function($x) { | |
| return $do { $rest ... } | |
| }); | |
| } | |
| } |
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
| macro sexp { | |
| rule {()} => { | |
| ; | |
| } | |
| rule {($p)} => { | |
| $p | |
| } | |
| rule {($x $y)} => { | |
| $x($y); | |
| } |
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
| macro $do { | |
| rule {($($x = $y) (,) ...) $body} => { | |
| (function ($x (,) ...) $body)($y (,) ...) | |
| } | |
| rule {$name ($($x = $y) (,) ...) $body} => { | |
| (function $name ($x (,) ...) $body)($y (,) ...) | |
| } | |
| } | |
| $do (a = 1, b = 2) { |
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
| macro to_string { | |
| case $x => { (JSON.stringify({ $x: 0 }).slice(2, -4)) } | |
| } | |
| macro enum { | |
| case [ $val:ident (,) ... ] => { | |
| (function () { | |
| var e = { | |
| $( $val : (to_string $val) ) (,) ... | |
| }; |
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
| // y-combinator | |
| macro $y { | |
| rule {( $var )} => { | |
| function(){ | |
| return function (f){ | |
| return f(f) | |
| }(function(f){ | |
| return $var(function(x){ | |
| return f(f)(x); | |
| }) |
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
| macro null_helper { | |
| rule {($processed ...) ($rest)} => { | |
| $processed (.) ... . $rest | |
| } | |
| rule {($processed ...) ($rest_head $rest ...)} => { | |
| $processed (.) ... . $rest_head | |
| && null_helper ($processed ... $rest_head) ($rest ...) | |
| } | |
| } |
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
| macro $do { | |
| rule {($($x = $y) (,) ...) $body} => { | |
| (function ($x (,) ...) $body)($y (,) ...) | |
| } | |
| rule {$name ($($x = $y) (,) ...) $body} => { | |
| (function $name ($x (,) ...) $body)($y (,) ...) | |
| } | |
| } | |
| macro $var { |
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
| my @a = ('99 bottles', 'take one down', '98 bottles'); | |
| for @a { | |
| say "$^a of beer on the wall, $^a of beer.$^b, $^c of beer on the wall.".tc; | |
| } | |
| my @b = ('99 bottles', 'take one down', '98 bottles'), ('98 bottles', 'take one down', '97 bottles'); | |
| say @b.perl; | |
| for @b { | |
| say "$^a of beer on the wall, $^a of beer.$^b, $^c of beer on the wall.".tc; | |
| } |
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
| import slick.jdbc.{GetResult, PositionedResult} | |
| import scala.annotation.implicitNotFound | |
| import scala.reflect.runtime.universe.TypeTag | |
| /** | |
| * A type class that allows the user of GenericGetResult to support their own type. | |
| * This is mostly used to support `newtype`s (like wrappers around UUIDs). | |
| * | |
| * A user just has to use the helper to make the type known to GenericGetResult. |