Skip to content

Instantly share code, notes, and snippets.

package demo.app
// 从雪山大虫scalaz example改写为使用cats
import cats.Functor
import cats.data.{Coproduct, Reader, Xor}
import cats.free.{Free, Inject}
import cats._
import cats.std.all._
import cats.syntax.all._
import scala.io.StdIn
@linqing
linqing / build.sbt
Created July 5, 2013 04:41
build.sbt with spray library
name := "star-one-fire"
version := "0.0.1"
organization := "com.starworking"
scalaVersion := "2.10.2"
@linqing
linqing / FunctionUtil.scala
Created June 4, 2013 03:43
Call scala function in java
package chapter1
object FunctionUtil {
def testFunction(f: Int => Int): Int = f(5)
val list = (1 to 100).toList
def filter(func: Int => Boolean): List[Int] =
list.filter(func)
}
class Bill < ActiveRecord::Base
set_table_name "ads"
has_many :bill_edit_histories
has_many :bill_display_dates, :dependent => :destroy, :foreign_key => 'bill_id'
has_many :bill_display_times, :dependent => :destroy
has_many :mem_integrals
belongs_to :bill_type
belongs_to :bill_brand
has_one :bill_last_display_date, :class_name=>'BillDisplayDate', :order => 'edates desc' # todo 这个地方好像有错
has_many :attachments, :as => :container, :dependent => :destroy
package math
object Statistics1 {
// 中位数(又称中值,英语:Median),统计学中的专有名词,代表一个样本、种群或概率分布中的一个数值,
// 其可将数值集合划分为相等的上下两部分。对于有限的数集,可以通过把所有观察值高低排序后找出正中间的一个作为中位数。
// 如果观察值有偶数个,则中位数不唯一,通常取最中间的两个数值的平均数作为中位数。
def median(xs: Vector[Double]): Double = xs(xs.size / 2)
/*
// 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
@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) {
@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 / 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 / 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)