Skip to content

Instantly share code, notes, and snippets.

View Centaur's full-sized avatar

oldpig Centaur

  • singerdream.com
  • Shanghai
View GitHub Profile

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
import scala.xml.NodeSeq
import net.liftweb.http.js._
import net.liftweb.http.js.jquery._
def $(exp: String): jQuery = $(JE.Str(exp))
def $(exp: JsExp): jQuery = jQuery(exp)
case class jQuery(exp: JsExp) {
private val _jqueryCssSelectRegex = """(^\S)+""".r
private val _matchChar = Set('*', '[', '^', '-')
def sel(exp: String, content: NodeSeq): CssSel = {
val selects = _jqueryCssSelectRegex.findAllMatchIn(exp).map(_.matched).toList
val (init, last) =
if (_matchChar.contains(selects.last.head))
selects.dropRight(2) -> selects.takeRight(2).mkString(" ")
else
@Centaur
Centaur / gist:4070883
Created November 14, 2012 07:52 — forked from non/gist:4064198
Add map + flatMap to Function1-3 with no overhead
object RichF {
implicit class RichF1[A, Z](val f: A => Z) extends AnyVal {
def map[Y](g: Z => Y): A => Y =
(a: A) => g(f(a))
def flatMap[Y](g: Z => A => Y): A => Y =
(a: A) => g(f(a))(a)
}
implicit class RichF2[A, B, Z](val f: (A, B) => Z) extends AnyVal {
def map[Y](g: Z => Y): (A, B) => Y =