Skip to content

Instantly share code, notes, and snippets.

View nitindhar7's full-sized avatar

Nitin Dhar nitindhar7

View GitHub Profile
int controllerForEfficientHandlingOfStrings;
int controllerForEfficientStorageOfStrings;
int a = 1;
int l = 2; // lowercase L
if (a == l) // intention was to compare 'a' with lowercase L
// do something...
int MAX_STUDENT_IN_CLASS = 7;
String accountFirstName;
String accountLastName;
String billingFirstName;
String billingLastName;
// VS.
String firstName1;
String lastName1;
String firstName2;
class Address {
String firstName;
String lastName;
...
}
class Account {
String firstName;
String lastName;
Address billingAddress;
...
@With({Authenticated.class, Notifications.class})
public static Result eventDetails(String eventKey) {
// do something
}
def eventDetails(eventKey: String) = Authenticated andThen
WithNotifications async { implicit request =>
// Events.findEventByKey returns Future[Event]
Events.findEventByKey(eventKey) map { event =>
Ok(eventDetails(request.user, request.notifications, event))
}
}
def myAction = DoSomething andThen DoAnotherThing [… andThen DoAnotherThing …] {
// request.someData and request.someOtherData are available here
}
object Authenticate extends ActionBuilder[AuthRequest] {
def invokeBlock[A](
request: Request[A],
block: (AuthRequest[A]) => Future[Result]
) = block(AuthRequest(findUserFrom(cookie), request))
}
case class AuthRequest[A](
object FetchNotifications
extends ActionTransformer[AuthRequest, NotificationRequest] {
def transform[A](request: AuthRequest[A]) = Future {
request.user.map { user =>
NotificationRequest[A](Some(user), findNotificationsByUser(user), request)
} getOrElse {
NotificationRequest[A](None, None, request)
}
}