Skip to content

Instantly share code, notes, and snippets.

View Centaur's full-sized avatar

oldpig Centaur

  • singerdream.com
  • Shanghai
View GitHub Profile
@Centaur
Centaur / setjdk.fish
Created June 24, 2019 14:59 — forked from tobias/setjdk.fish
Manage multiple java versions on the mac from the fish shell
function setjdk
if test -n "$JAVA_HOME"
removeFromPath "$JAVA_HOME/bin"
end
set -gx JAVA_HOME (/usr/libexec/java_home -v $argv[1])
set -gx PATH $JAVA_HOME/bin $PATH
end
function removeFromPath
set -l idx 0
import scala.collection.AbstractIterator
case class Player(name: String, rank: Int)
case class Position(group: Char, index: Int, player: Player)
val 老猪 = Player("老猪", 1719)
val 邢罡 = Player("邢罡(外卡)", 1500)
val a剑 = Player("a剑", 1528)
val 阮鸣强 = Player("阮鸣强", 1478)
val 大通 = Player("大通", 1392)
val 简 = Player("简", 1429)
import scala.collection.AbstractIterator
def forward_from(n: Int, e: Int) = Iterator.continually(1 to n).flatten.slice(e - 1, e - 1 + n).toVector
def backward_from(n: Int, e: Int) = Iterator.continually(n.to(1, -1)).flatten.slice(n - e, n - e + n).toVector
def beiger_even(player_count: Int): Iterator[(Vector[Int], Vector[Int])] = new AbstractIterator[(Vector[Int], Vector[Int])] {
var next_round = 1
var flat = (1 to player_count).toVector
@Centaur
Centaur / tailrec2fold.scala
Last active December 19, 2016 04:34
Tailrec to Fold
package org.snippets
import scala.collection.immutable.Stream.#::
import scala.util.{Failure, Success, Try}
class InsufficientParametersException(message: String) extends RuntimeException(message)
object Tailrec2Fold {
type RpnModel = String
type CalculationState = (String, String)
@Centaur
Centaur / testcase.scala
Created November 9, 2016 06:41
TestCase
val programmingScala = TreeNode("Scala 程序设计", Seq(
TreeNode("序"),
TreeNode("前言"),
TreeNode("第一章 零到六十: Scala简介", Seq(
TreeNode("1.1 为什么选择 Scala", Seq(
TreeNode("1.1.1 富有魅力的 Scala"),
TreeNode("1.1.2 关于 Java8")
)),
TreeNode("1.2 安装 Scala", Seq(
TreeNode("1.2.1 使用 SBT"),
package org.snippets
import scala.collection.mutable.ListBuffer
import scala.reflect.ClassTag
trait Event[T] {
}
trait EventListener[T] {
@Centaur
Centaur / fromScalaConsole.scala
Created August 24, 2016 04:20
redis-cleanup
import com.redis._
val redis = new RedisClient("localhost", 6379)
for{set <- redis.smembers("Odersky-Keys")}
for{opt <- set}
for{key <- opt}
redis.del(key)
redis.del("Odersky-Keys")
@Centaur
Centaur / idiomatic.scala
Created August 9, 2016 12:27
代码优化
import util._
trait Idiomatic {
def step1(s: String): Try[List[String]]
def step2(s: String): Option[String]
def logic(src: String) = {
for(data1 <- step1(src)) {
package org.snippets
object NormalizePage {
def solute(m: Int, n: Int): Option[Int] = {
var i = n
while(i <= m.min(2*n)) {
if(m % i + n <= i) return Some(i)
i += 1
}
None
package org.snippets
import scala.concurrent.{Future, Promise}
class Test {
def test(): Function3[String, String, String, String] = {
new Function3[String, String, String, String] {
@throws(classOf[Exception])
override def apply(arg1: String, arg2: String, arg3: String): Future[String] = {
Promise[String]().future