Skip to content

Instantly share code, notes, and snippets.

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
```
@jasonqu
jasonqu / AllForOne Strategy
Last active March 16, 2017 03:38
supervisor strategy from [Akka Essentials](https://github.com/write2munish/Akka-Essentials)
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._
@jasonqu
jasonqu / NormaMdTable.scala
Last active August 19, 2016 10:46
格式化markdown表格
#!/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]
@jasonqu
jasonqu / HelloPlugin.scala
Last active January 14, 2016 09:01
how to use setting defined in sbt plugin
// 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.")
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 {
@jasonqu
jasonqu / gist:8964c1f52f462db30666
Created July 21, 2015 10:29
tri analyze - mapdb try
// 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")
// 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");
// 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;