Skip to content

Instantly share code, notes, and snippets.

View KirinDave's full-sized avatar

Dave Fayram KirinDave

View GitHub Profile
package com.banksimple.util
import org.scala_tools.time.Imports._
import org.joda.time.format.{DateTimeFormat,DateTimeFormatter}
class SafeDateTimeFormatter(val self: DateTimeFormatter) extends Proxy {
def safelyParseDateTime(input: String): Option[DateTime] =
try Some(self.parseDateTime(input))
catch { case _ => None }
}
Error locating template /recurse.html.Message: Expected ';'java.lang.RuntimeException: Expected ';'scala.xml.parsing.MarkupParserCommon$class.takeUntilChar(MarkupParserCommon.scala:88) scala.xml.parsing.MarkupParserCommon$class.normalizeAttributeValue(MarkupParserCommon.scala:148) scala.xml.parsing.MarkupParserCommon$class.xAttributeValue(MarkupParserCommon.scala:79) net.liftweb.util.PCDataXmlParser.xAttributeValue(PCDataMarkupParser.scala:98) net.liftweb.util.PCDataXmlParser.xAttributes(PCDataMarkupParser.scala:113) scala.xml.parsing.MarkupParser$class.mkAttributes(MarkupParser.scala:245) net.liftweb.util.PCDataXmlParser.mkAttributes(PCDataMarkupParser.scala:98) net.liftweb.util.PCDataXmlParser.mkAttributes(PCDataMarkupParser.scala:98) scala.xml.parsing.MarkupParserCommon$class.xTag(MarkupParserCommon.scala:47) net.liftweb.util.PCDataXmlParser.xTag(PCDataMarkupParser.scala:98) scala.xml.parsing.MarkupParser$class.element1(MarkupParser.scala:509) net.liftweb.util.PCDataXmlParser.element1(PCDataMarkupParser.sc
<div id="main" class="lift:surround?with=default&at=content">
<div>
This demonstrates Lift's recursive snippets
</div>
<div class="lift:Recurse">
<div id="first" class="lift:FirstTemplate">
The first template.
</div>
package com.banksimple.testing.util
import akka.actor._
class ReplayActor extends Actor {
var lastSeen: List[Any] = List()
override def receive: Receive = {
case 'dump => { self.reply(lastSeen) ; lastSeen = List() }
case a => lastSeen = a :: lastSeen
}
}
@KirinDave
KirinDave / Also.scala
Created February 11, 2011 20:49
begin0 for scala
package com.banksimple.util
private[util] final class Also[T](val origin: T) {
def andAlso(x: T => Unit): T = { x(origin) ; origin }
def andThen(x: => Unit): T = { x ; origin }
}
object Also {
<html>
<head>
<title> Fuck everything! </title>
</head>
<body class="lift:content_id=content">
<div class="lift:surround?with=default;at=content span-24 last" id="content">
<head_merge><title>Headmerge!</title></head_merge>
<div class="span-12"> Fully html5!!!<br>And with some css besides!!!!!!<br>Whee</div>
package com.swipr.lib
import dispatch._
import net.liftweb.json._
import java.net.URL
package Google.ImageSearch {
case class Result(url: String)
case class SearchResponse(results: List[Result])
case class SearchEnvelope(responseData: SearchResponse,
@KirinDave
KirinDave / HordeActor.scala
Created February 20, 2011 17:58
An actor to address a tight-timeline horde problem, where many request for identical (and potentially non-trivial) pieces of data enter the system at once.
package com.swipr.lib
import akka.actor._
import akka.dispatch._
import scala.collection.immutable._
package HordeProtocol {
case class GetOrCreate(key: Any, valueGenerator: () => Any)
case class ClearJob(keyToClear: Any, value: Any)
}
package com.banksimple.util
private[util] final class Effectful[T](val origin: T) {
/**
* A special case of doto, andAlso is useful for
* quick logging or output tasks. Similar in use
* to doto, but only takes one function.
* */
def andAlso(x: T => Unit): T = { x(origin) ; origin }
@KirinDave
KirinDave / erlang-setup.el
Created April 22, 2011 17:26
My toplevel emacs file
;;This is needed for Erlang mode setup
(defun get-erlang-root ()
(if (file-exists-p "/p/lib/erlang")
"/p/lib/erlang"
"/usr/local/lib/erlang"))
(let* ((root-dir (get-erlang-root))
(bin-dir (expand-file-name "bin" root-dir))