Skip to content

Instantly share code, notes, and snippets.

@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 / 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: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: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 / 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._