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 / gist:ed0b55907d2261b572cd
Last active August 29, 2015 14:17
nested `andThen` transformed to normal function application

先从简单的情况入手,假设 f1 的类型是 A => B, 看看

    f2 andThen {
	    _ andThen f1
    }

到底是什么意思 先去掉语法糖,完整形式为:

@Centaur
Centaur / dry.scala
Last active August 29, 2015 14:09
Refactor protocolMap
import util._
abstract class SrcProtocol(val id: String)
case class CompileSrc(override val id:String) extends SrcProtocol(id)
case class TestSrc(override val id:String) extends SrcProtocol(id)
case class SystemSrc(override val id:String) extends SrcProtocol(id)
abstract class DstProtocol(val id: String)
@Centaur
Centaur / egret.scala
Last active August 29, 2015 14:09
forEgret
def name2id1(name: String): Option[String] = name match {
case "name1" => Some("id1")
case "name2" => Some("id2")
case "name3" => Some("id3")
case _ => None
}
def name2id2(name: String): Option[String] = name match {
case "name1" => None
case "name2" => Some("id2")
case "name3" => Some("id3")
realm=Sonatype Nexus Repository Manager
host=nexus.company.com
user=admin
password=admin123

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@Centaur
Centaur / CommaSeperatedData.scala
Created October 31, 2014 04:08
dynamically run scala code
import tools.nsc.interpreter.IMain
import tools.nsc.Settings
object CommaSeperatedData extends App {
val data = """ "Doe, John", 35, 225, "5'10\"", "555-0123" """
val settings = new Settings
settings.usejavacp.value = true
val n = new IMain(settings)
n.interpret("List(" + data + ")")
@Centaur
Centaur / Dispatcher.scala
Created October 20, 2014 12:33
dispatcher
package flux
/**
* Created by IntelliJ IDEA.
* User: xf
* Date: 14/10/20
* Time: 下午5:49
*/
trait Payload[T] {

I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.

From Require.js - Why AMD:

The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"

I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.


@Centaur
Centaur / gist:cb0d95116b6b691993c0
Created August 14, 2014 03:17
refactor challenge
object PathList {
def unapplySeq(path: String): Option[Seq[String]] =
if(path.isEmpty) None
else Some(path.split("/"))
}
def testMatch(str: String): Boolean = str match {
case PathList("org", "scalaconsole", "fxui", "main", "ace-builds", sub) => true
case PathList("org", "scalaconsole", "fxui", "main", "ace-builds", sub, xs@_*) if sub != "src-min-noconflict" => true
val keywords = Set("class", "public", "private", "protected")
def wordCount(is: java.io.InputStream): Map[String, Int] = {
var result = Map[String, Int]()
val scanner = new java.util.Scanner(is)
while(scanner.hasNext) {
val word = scanner.next
if(keywords.contains(word)) {
if(result.contains(word)) {