2017年2月20日星期一

Enabling the macro-paradise Scala compiler plugin in Maven projects


11down voteaccepted
Looks like I got it to work with the following additions to the pom.xml
 <repositories>
   ...
   <repository>
     <id>oss.sonatype.org</id>
      <name>sonatype sapshots</name>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
   ...
  </repositories>
and
  <plugins>
    ...
    <plugin>
      ... scala-maven-plugin identification...
      <configuration>
        ...
        <compilerPlugins>
          <compilerPlugin>
            <groupId>org.scala-lang.plugins</groupId>
            <artifactId>macro-paradise_2.10.2</artifactId>
            <version>2.0.0-SNAPSHOT</version>
          </compilerPlugin>
        </compilerPlugins>
        ...
      </configuration>
      ...
    </plugin>
    ...
  </plugins>

2017年2月17日星期五

scala object apply default type parameter with more constructor

/**  * Created by eagooqi on 2017/2/17.  */class UTest[T] () {
  var _id:String = _
  def this(id:String){
    this()
    this._id = id
  }
}
object UTest{

  def apply[T](id:String) = new UTest[T](id)
  def apply[Nothing](id:String) = new UTest[String](id)

}

object Test2 extends App{
  var ut: UTest[String] = UTest[String]("")
  var ut2  = UTest("")
  println(ut2.getClass.getTypeName)
}

2017年2月12日星期日

datelist.sh

#!/bin/bash

if [ $# -eq 2 ];then
  date1=$1
  date2=$2
fi
if [ $# -eq 1 ];then
  date1=$1
  date2=$1
 
fi

date1=`date +%Y-%m-%d -d "$date1 0 days ago"`
date2=`date +%Y-%m-%d -d "$date2 0 days ago"`
#echo $date1" "$date2
if [ ${#date1} -ne 10 -o ${#date2} -ne 10 ];then
  echo "invalid input usg:datelist.sh yyyy-mm-dd yyyy-mm-dd"
  exit
fi


if [[ "$date1" > "$date2" ]];then
        echo "datelist.sh yyyy-mm-dd yyyy-mm-dd"
        exit
fi
while [ "$date1" \< "$date2" ] || [ "$date1" = "$date2" ]
do
        echo $date1
        date1=`date +%Y-%m-%d -d "$date1 -1 days ago"`
done