Skip to content

Instantly share code, notes, and snippets.

View notyy's full-sized avatar

大魔头 notyy

View GitHub Profile
package diamondProblem
trait A{
def hello() = println("hello from A")
}
trait B extends A{
override def hello() = println("hello from B")
}
import java.io._
def delDirNoRecur(dirName: String): Unit = {
val dir = new File(dirName)
if(dir.exists && dir.isDirectory){
val files = dir.listFiles
files.foreach(_.delete())
println(s"delete complete ${files.size} files deleted")
}else{
println(s"$dirName not a directory")
@notyy
notyy / future.scala
Created November 25, 2013 12:32
first code block use future promise second only use future
import scala.concurrent.{ future, promise }
import scala.concurrent.ExecutionContext.Implicits.global
val p = promise[String]
val f = p.future
val producer = future {
println("producing")
Thread.sleep(1000)
val r = "produced"
p success r
Thread.sleep(1000)
@notyy
notyy / dci.scala
Last active December 27, 2015 07:29
//database model
case class Account(id: Identifier, owner: User, var balance: Money)
object AccountRepository {
def lookUp(id: Int):Account = Account("id1", "notyy", 100.0) //just an example
}
//DCI model
class AccountHolder(val account: Account) //adaptor
@notyy
notyy / code.java
Last active December 22, 2015 05:19
Option in java
package notyy;
public class Option<A> {
private final A thing;
public Option(A thing) {
this.thing = thing;
}
public <E extends Exception> A getOrThrow(E excetion) throws E{
@notyy
notyy / AbstractBase
Created July 27, 2013 13:19
implicit abstract class problem
package base;
import java.util.List;
public abstract class AbstractBase {
abstract protected List getChildren();
}
@notyy
notyy / gist:6093587
Created July 27, 2013 03:29
this implicit works for scala
package com.github.notyy.retroboard.util
import org.scalatest.FunSpec
import org.scalatest.matchers.ShouldMatchers
trait Base {
protected def getChildren: List[String]
}
object Base {
@notyy
notyy / gist:5790999
Created June 16, 2013 06:22
scaladay 2013 slide links
https://speakerdeck.com/ryanlecompte/confessions-of-a-ruby-developer-whose-heart-was-stolen-by-scala
Practical type mining in Scala ( Rose Toomey )
http://www.slideshare.net/prasinous/scaladays-2013-final
Real world akka recepies (Jamie Allen, Björn Antonsson and Patrik Nordwall)
http://www.slideshare.net/shinolajla/real-world-akka-recepies-v3
Scala IDE 3.0 - Present & Future ( Mirco Dotta )
@notyy
notyy / gist:3958354
Created October 26, 2012 11:52
implicit list as functor
trait Functor[A, T[_]] {
def fmap[B](f: A => B): T[B]
}
class ListFunctor[A](val list: List[A]) extends Functor[A, List] {
override def fmap[B](f: A => B): List[B] = list match {
case List() => List()
case (x :: xs) => f(x) :: xs.fmap(f)
}
}
@notyy
notyy / gist:3712639
Created September 13, 2012 07:39
how to remove
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
window.onload = doIt;
function doIt() {
var oDiv = document.getElementById("div1");
alert (oDiv);
//oDiv.removeAttribute("onclick");
}