Skip to content

Instantly share code, notes, and snippets.

@linqing
linqing / FaqSnippet.scala
Created November 20, 2011 15:18
FaqSnippet
package ebb
package snippet
import net.liftweb.http._
import net.liftweb.util._
import net.liftweb.common._
import ebb.model.Models._
import ebb.util.FaqReader
import org.squeryl._
import PrimitiveTypeMode._
@linqing
linqing / gist:1534581
Created December 29, 2011 15:30
workflow engine ruby version
class WfEntry < ActiveRecord::Base
has_many :history_steps, :foreign_key => :entry_id, :class_name => 'WfHistoryStep', :dependent => :destroy
has_many :current_steps, :foreign_key => :entry_id, :class_name => 'WfCurrentStep', :dependent => :destroy
has_many :comments, :as => :container, :dependent => :destroy
belongs_to :document, :polymorphic => true
named_scope :todo_of_workflow_name_and_owner, lambda { |workflow_name, owner_name|
{:include => :current_steps,
:conditions =>["name = ? and #{WfCurrentStep.table_name}.owner = ?", workflow_name, owner_name ]}
}
@linqing
linqing / gist:1534600
Created December 29, 2011 15:35
workflow angine scala version
package star.oa
package service
import impl.mongo.WorkflowEntry
import impl.mongo.CurrentStep
import impl.mongo.HistoryStep
import impl.mongo.WorkflowComment
import star.oa.workflow._
import net.liftweb.http.S
import java.util.Date
@linqing
linqing / gist:1543950
Created December 31, 2011 13:02
category theory and scala
object Test {
/* 简介 */
type A = Double // 一组对象A
type B = Long // 一组对象B
type C = String // 一组对象C
val f: A => B = // 一组态射f
(a: Double) => a.round
@linqing
linqing / gist:1917183
Created February 26, 2012 14:57
if else for
case class Message(username: String, content: String)
val list = List(Message("aaa", "111"), Message("aaa", "222"),
Message("bbb", "333"), Message("aaa", "444"))
if (list.isEmpty) Nil
else
list.head :: (
for (List(m1, m2) <- list.sliding(2))
yield if (m1.username == m2.username)
m2.copy(username = "") else m2).toList
@linqing
linqing / make.lisp
Created April 21, 2012 06:13
run all make files
#!/usr/bin/env clisp
(setf *bookpaths* '(
("platform/architecture" "book")
("platform/requirements" "book")
("zszj/userGuide/agents" "book")))
(setf *root* (namestring (cd)))
(defun make-books (paths)
(if (null paths)
@linqing
linqing / emacs.el
Created April 22, 2012 05:11
my .emacs
;; Put autosave files (ie #foo#) and backup files (ie foo~) in ~/.emacs.d/.
(custom-set-variables
'(auto-save-file-name-transforms '((".*" "~/.emacs.d/autosaves/\\1" t)))
'(backup-directory-alist '((".*" . "~/.emacs.d/backups/"))))
;; create the autosave dir if necessary, since emacs won't.
(make-directory "~/.emacs.d/autosaves/" t)
;;(setq load-path (cons "~/.emacs.d/emacs-rails" load-path))
;;(require 'rails)
@linqing
linqing / ExprParser
Created June 30, 2012 02:22
what's wrong with the var?
package ch19.sec02
import scala.util.parsing.combinator._
class ExprParser extends RegexParsers {
val number = "[0-9]+".r
def expr: Parser[Any] = term ~ opt("+" | "-") ~ expr
def term: Parser[Any] = factor ~ rep("*" ~ factor)
def factor: Parser[Any] = number | "(" ~ expr ~ ")"
}
@linqing
linqing / Select.scala
Last active December 16, 2015 18:09
select in scala
package star.oa.util.parsing
import scala.util.parsing.combinator._
import scala.util.matching.Regex
case class Table(name: String, alias: Option[String])
case class Join(tableName: String, alias: Option[String], leftTable: String, leftField: String, rightTable: String, rightField: String)
case class Column(table: Option[String] = None,
field: Option[String] = None,
formula: Option[String] = None,
asTitle: Option[String] = None) {
/*
// Setting this in bootstrap.liftweb.Boot.scala
// Use HTML5 for rendering
LiftRules.htmlProperties.default.set((r: Req) =>
new StarXHtmlInHtml5OutProperties(r.userAgent))
*/
package bootstrap.liftweb
import java.io.InputStream