Skip to content

Instantly share code, notes, and snippets.

@tgpfeiffer
tgpfeiffer / gist:3014487
Created June 28, 2012 22:49
Creating an LDAP user using Scala/Lift and LDAPProtoUser
/*
* This code shows in a prototypical manner how to create a user
* in an LDAP directory using the code from the lift-ldap package,
* including salted SHA1 (SSHA) passwords.
*
* The Java code from
* http://stackoverflow.com/questions/8176001/trouble-creating-active-directory-users-with-java
* was used as a template, kudos!
*/
@tgpfeiffer
tgpfeiffer / gist:3156517
Created July 21, 2012 17:38
Setting an XML namespace in Scala
/*
* Let's assume we have an XML fragment in Scala like:
* <entry xmlns="http://www.w3.org/2005/Atom">
* <content xmlns="http://mysite.com/xml/someSchema">
* Hello <name>you</name>!
* </content>
* </entry>
* Then (_ \ "content") will leave you with:
* <content xmlns="http://mysite.com/xml/someSchema" xmlns="http://www.w3.org/2005/Atom">
* Hello <name>you</name>!
@tgpfeiffer
tgpfeiffer / Zinnia2Ikiwiki.scala
Created October 11, 2012 22:08
Convert a Django-Zinnia blog to Ikiwiki
import java.io._
import java.util.Date
import java.text.SimpleDateFormat
import scala.io.Source
import net.liftweb.json._
import net.liftweb.util.Helpers._
object Zinnia2Ikiwiki extends Application {
@tgpfeiffer
tgpfeiffer / BsonMetadata.scala
Created November 3, 2012 13:36
Lift: CRUD interface for "foreign keys" using a multiselect and select2
// ...
object author extends ObjectIdRefListField(this, MongoTerm)
with One2ManyCRUD[BsonMetadata, MongoTerm] {
override def options = MongoTerm.findAll(("category" -> "person")).map(x => (x.id.is, x.title))
}
// ...
@tgpfeiffer
tgpfeiffer / BsonMetadata.scala
Created November 3, 2012 21:52
Lift: CRUD interface for "foreign keys" using an AJAX auto-complete and select2
// ...
object author extends ObjectIdRefListField(this, MongoTerm)
with One2ManyCRUD[BsonMetadata, MongoTerm] {
override def searchMeta = MongoTerm
override def definingQuery = ("category" -> "person")
}
// ...
@tgpfeiffer
tgpfeiffer / MailSender.scala
Created November 30, 2012 15:19
Send Email from Lift
tryo {
MyMailer.sendMail(
MyMailer.From("info@mysite.de"),
MyMailer.Subject(subject),
(MyMailer.MessageHeader("Date", now.toGMTString()) ::
MyMailer.PlainPlusBodyType(formattedContent, "utf-8") ::
MyMailer.XHTMLMailBodyType(htmlContent) ::
recipients.map(MyMailer.To(_))
): _*)
} match {
@tgpfeiffer
tgpfeiffer / FilmTranslation.scala
Created January 3, 2013 13:31
Mapper inheritance
import scala.xml.Text
import scala.annotation.tailrec
import net.liftweb.mapper._
import net.liftweb.sitemap._
import net.liftweb.common._
import net.liftweb.http._
import net.liftweb.util.Helpers._
import net.liftweb.sitemap.Menu.ParamExtractor
import eu.vismath.web.lib._
import org.scalatest._
import org.scalatest.time._
import org.scalatest.selenium._
import org.openqa.selenium._
import org.mortbay.jetty.Server
import org.mortbay.jetty.webapp.WebAppContext
import org.apache.log4j.Logger
trait JettySetup extends FlatSpec
with BeforeAndAfterAll
@tgpfeiffer
tgpfeiffer / Content.scala
Created January 23, 2013 17:12
How to add generic versioning to Lift's MongoDB classes.
/**
* Carries some page content.
*/
class Content extends MongoRecord[Content]
with ObjectIdPk[Content]
with Versioned[Content, ContentRevision] {
def meta = Content
def revisionMeta = ContentRevision
// ...
}
@tgpfeiffer
tgpfeiffer / EndlessList.scala
Last active October 3, 2016 15:25
AJAX loading of new items in Lift (with Non-AJAX fallback)
class EndlessList {
/**
* Gets a "page" (e.g., 10 items) of content entities from the database.
*/
def getPage(page: Int): (Seq[Content], Boolean) = {
val realPage: Int = if (page < 1) 1 else page
val limit = 10
val contents = Content.findAll(
(/* conditions */),