This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.javapractices.com/topic/TopicAction.do?Id=42 | |
// In JDK7 | |
List<String> lines = Files.readAllLines(Paths.get("a.txt"), Charset.forName("utf8")); | |
Files.write(Paths.get("b.txt"), lines, Charset.forName("utf8")); | |
// for big file | |
Path path = Paths.get(aFileName); | |
try (BufferedReader reader = Files.newBufferedReader(path, ENCODING)){ | |
String line = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in scala, map type error could be check in compile time | |
val map = Map(1 -> "a") | |
map.get("a") | |
// in java, it cannot | |
Map<Integer, String> map = new HashMap<>(); | |
map.put(1, "a"); | |
map.get("a"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// embed db - mapdb | |
// libraryDependencies += "org.mapdb" % "mapdb" % "1.0.8" | |
val db : DB = DBMaker.newFileDB(new File("tridb")) | |
.closeOnJvmShutdown() | |
.make() | |
val vertices : JMap[Integer,String] = db.getHashMap("idToName-Vertex") | |
val vertexNames : JMap[String,Integer] = db.getHashMap("nameToid-Vertex") | |
val edges : JMap[Integer,String] = db.getHashMap("idToName-Edge") | |
val edgeNames : JMap[String,Integer] = db.getHashMap("nameToid-Edge") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Size(width: Double, height: Double) | |
case class Point(x: Double, y: Double) | |
case class Row(origin: Point, children: List[Size], hSpacing: Double) { | |
lazy val widthWithSpacing = children.map(_.width + hSpacing).sum | |
lazy val maxHeight = children.map(_.height).max | |
lazy val getRectOrigins: Seq[Point] = { | |
children.foldRight(List[Point](origin)) { (curr, points) => | |
points match { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source in plugin | |
package sbthello | |
import sbt._ | |
import Keys._ | |
object HelloPlugin extends AutoPlugin { | |
object autoImport { | |
val greeting = settingKey[String]("greeting") | |
val obfuscate = taskKey[String]("Obfuscates files.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala "$0" "$@" | |
!# | |
/** | |
* 目标:格式化md table 表格语法 http://www.tablesgenerator.com/markdown_tables | |
* 注意点:文件的编码 涉及到字符串长度的计算 | |
*/ | |
if (args.length < 1 || args.length > 2) { | |
println( | |
"""Usage: scala NormaMdTable.scala inputMdFile [outputMdFile] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package akka.book.essence.chap6.AllForOne | |
import akka.actor.SupervisorStrategy._ | |
import akka.actor._ | |
import akka.pattern.ask | |
import akka.util.Timeout | |
import scala.concurrent.Await | |
import scala.concurrent.duration._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/questions/13489398/delete-files-older-than-10-days-using-shell-script-in-unix | |
Delete files older than 10 days using shell script in Unix | |
``` | |
find ./my_dir -mtime +10 -type f -delete | |
``` | |