Skip to content

Instantly share code, notes, and snippets.

View pr1001's full-sized avatar

Peter Robinett pr1001

View GitHub Profile
@pr1001
pr1001 / README.md
Created October 17, 2011 19:01
A proposed README file for the Lift framework repository

The Lift Web Framework

Lift is the most powerful, most secure web framework available today. There are Seven Things that distinguish Lift from other web frameworks.

Lift applications are:

  • Secure -- Lift apps are resistant to common vulnerabilities including many of the OWASP Top 10
  • Developer centeric -- Lift apps are fast to build, concise and easy to maintain
  • Scalable -- Lift apps are high performance and scale in the real world to handle insane traffic levels
  • Interactive like a desktop app -- Lift's Comet support is unparalled and Lift's ajax support is super-easy and very secure
class Page(val id: String) extends Iterable[Page] {
def URLMatch(req: Request): Option[Page] = {
req match {
case r if urlParamMatches(r) => Some(this)
case r if urlPatternMatches(r) => Some(this)
case r if parent.isDefined => parent.get.URLMatch(r)
case _ => None
}
}
}
@pr1001
pr1001 / gist:1040156
Created June 22, 2011 14:08
Some helpers written for Where's My Bike (http://labs.bubblefoundry.com/wheresmybike/) making it easier to declare Backbone.js models
// helper
WMB.capitalize = function capitalize(str) {
return str.charAt(0).toLocaleUpperCase() + str.substring(1).toLocaleLowerCase();
}
// Base Mode, with collection syncing
WMB.BaseModel = Backbone.Model.extend({
initialize: function() {
var modelName = WMB.capitalize(this.name);
var pluralName = modelName + "s";
@pr1001
pr1001 / Marius 2009.scala
Created June 18, 2011 00:13
Proposed Javascript DSLs
JsFunc('myFunc, 'param1, 'param2) {
JsIf('param1 __< 30) {
Var('home) := Wrap(234 __- 3) __/ 2 `;`
Var('someArray) := JsArray(1, 2, 3, 4, 5) `;`
'myFunc(1, 2, "do it", 'home) `;`
$("#myID") >> 'attr("value", "123") `;`
} ~
JsForEach(Var('i) in 'someArray) {
'console >> 'log("Hi there " __+ 'i) `;`
} ~
@pr1001
pr1001 / examples.scala
Created June 16, 2011 00:13
Towards a more friendly DSL for Lift's Javascript representations
val test = j_var ("test") := j_true
val test2 = j_var ('test2) := j_false
1 j_< 2
JsVar("k") j_<= 10
val a: JsVar = 'a
a++
val clause1 = j_if (j_true) {
@pr1001
pr1001 / Session.scala
Created February 28, 2011 09:30
A Lift extended session model.
import net.liftweb.mapper.{MetaProtoExtendedSession, ProtoExtendedSession}
import net.liftweb.common.Box
class Session extends ProtoExtendedSession[Session] {
def getSingleton = Session // what's the "meta" server
}
object Session extends Session with MetaProtoExtendedSession[Session] {
type UserType = User
@pr1001
pr1001 / Session.scala
Created February 27, 2011 23:47
Testing Lift ExtendedSessions
import org.scalatest.fixture.FixtureFlatSpec
import org.scalatest.matchers.ShouldMatchers
import net.liftweb.mapper._
import net.liftweb.common.{Empty, Full, Logger}
import net.liftweb.http.{LiftSession, S}
import net.liftweb.util.StringHelpers
class SessionSpec extends FixtureFlatSpec with ShouldMatchers {
@pr1001
pr1001 / Event.scala
Created February 10, 2011 11:29
A grammar-based event logging system in Scala using Lift's Mapper ORM. See the following blog post of a conceptual explanation: http://www.bubblefoundry.com/blog/2010/08/grammar-based-event-logging/
package com.mobtest {
package model {
import net.liftweb.mapper._
import net.liftweb.common.{Box, Full, Empty}
class Event extends LongKeyedMapper[Event] with IdPK with CreatedUpdated {
def getSingleton = Event // companion object
object subject extends MappedLong(this)
<?php
require_once('cap.php');
require_once('form.php');
$form = new Form('cap_test.php', function() {
print '<p>Called first</p>';
});
$x_id = $form->text('x', function($x) {
return $x * $x;
<?php
/**
* @author Peter Robinett <peter@bubblefoundry.com>
* @since 2010-08-03
*/
function array2NewArray (array $arr) {
return new NewArray($arr);
}