Skip to content

Instantly share code, notes, and snippets.

View tjweir's full-sized avatar

Tyler Weir tjweir

View GitHub Profile
object MyPayPalPDT extends PayPalPDT {
override def pdtPath = "paypal_complete"
def paypalAuthToken = Props.get("paypal.authToken") openOr "cannot find auth token from props file"
def pdtResponse: PartialFunction[(PayPalInfo, RequestState), LiftResponse] = {
case _ => println("--- in pdtResponse"); DoRedirectResponse("/account_admin/index");
}
}
We have HTTP Basic Auth and HTTP Digest Auth support in Lift. The
authentication is implemented as a partial function that you implement
like so:
LiftRules.httpAuthProtectedResource.prepend {
case (ParsePath("api" :: _, _, _, _)) => Full(AuthRole("admin"))
}
LiftRules.authentication = HttpBasicAuthentication("lift") {
case (username, password, req) => {
/*
Here's some code to serve an image out of the database. Here's the Mapper
definition:
*/
class Image extends LongKeyedMapper[Image] with IdPK {
def getSingleton = Image
object image extends MappedBinary(this)
object lookup extends MappedUniqueId(this, 32) {
class Trace {
def head(script:JsCmd) = <head>{Script(script)}</head>
def render(xhtml: NodeSeq): NodeSeq = {
val id = S.attr("id").openOr("")
val event = S.attr("event").openOr("keyup")
val msg = S.attr("msg").openOr("You typed")
def logit = new JsExp with JQueryRight {
First there is a snippet using the bind functionality.
var image : FileParamHolder = _
bind("widget", xhtml,
"image" -> fileUpload(image = _)
}
Now write out:
# Bash snippet to open new shells in most recently visited dir.
# Useful if you want to open a new terminal tab at the present
# tab's location.
#
# Put this in your .bashrc or whatever.
pathed_cd () {
if [ "$1" == "" ]; then
cd
else
[merge]
tool = mvim
[mergetool "mvim"]
cmd = <path to mvim>mvim -d -g "$LOCAL" "$MERGED" "$REMOTE"
keepBackup = false
trustExitCode = false
/**
* api helpers
*/
implicit def boxNodeSeqToNodeSeq(in: Box[NodeSeq]): NodeSeq = {
in match {
case Full(n) => n
case Failure(msg, _, _) => <error>{msg}</error>
case _ => <error></error>
}
// Copied from Apple's SeismicXML code sample
// When the user taps a row in the table, display the USGS web page that displays details of the earthquake they selected.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Earthquake *earthquake = (Earthquake *)[earthquakeList objectAtIndex:indexPath.row];
PLActionSheet *sheet = [[PLActionSheet alloc] initWithTitle: @"Display Map"];
[sheet addButtonWithTitle: @"Show USGS Site in Safari" block: ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: [earthquake USGSWebLink]]];
}];
//
// Events.h
// TWI
//
// Created by Shaun Harrison on 3/18/09.
// Copyright enormego 2009. All rights reserved.
//
#import <UIKit/UIKit.h>