Skip to content

Instantly share code, notes, and snippets.

View notyy's full-sized avatar

大魔头 notyy

View GitHub Profile
@notyy
notyy / gist:3422084
Created August 22, 2012 03:33
extract user story
#!/bin/sh
exec scala -nc "$0" "$@"
!#
import scala.io._
val source = if(args.length>0) Source.fromFile(args(0)).getLines else Source.stdin.getLines
val pattern = """([a-zA-Z]+)-(\d+)""".r
source.flatMap(pattern.findFirstIn).toList.distinct.foreach(println)
@notyy
notyy / gist:3123499
Created July 16, 2012 15:59
scala_lecture,ruby comparation6
cond = "false"
if cond then true else false end
=> true
@notyy
notyy / gist:3122675
Created July 16, 2012 13:20
scala_lecture,ruby comparation5
def match_type param
if param.kind_of? Integer
puts "it's a Integer"
end
if param.kind_of? String
puts "its a String"
end
if param.kind_of? Array
puts "its an Array"
end
@notyy
notyy / gist:3120022
Created July 16, 2012 02:29
scala_lecture,ruby comparation4
def postProcess int_list
int_list.map{ |i| i * 2}.each{|l| puts l}
end
list = [1,2,3,4,5]
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10}.map{ |i|i.to_s}
postProcess(rs)
@notyy
notyy / gist:3119946
Created July 16, 2012 02:13
scala_lecture,ruby comparation3
def postProcess int_list
int_list.map{ |i| i - 2}.each{|l| puts l}
end
list = [1,2,3,4,5]
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10}.map{ |i|i.to_s}
postProcess(rs)
@notyy
notyy / gist:3119293
Created July 16, 2012 00:04
scala_lecture,ruby comparation2
def postProcess int_list
int_list.each{|l| puts l}
end
list = [1,2,3,4,5]
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10}.map{ |i|i.to_s}
postProcess(rs)
@notyy
notyy / gist:3119266
Created July 15, 2012 23:51
scala_lecture,ruby comparation
def postProcess int_list
int_list.each{|l| puts l}
end
list = [1,2,3,4,5]
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10}
postProcess(rs)
@notyy
notyy / gist:3116070
Created July 15, 2012 09:34
lecture
list = [1,2,3,4,5]
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10}
rs.each{|l| puts l}
@notyy
notyy / gist:2999941
Created June 26, 2012 23:02
这有多大改进?
def qsort[T <% Ordered[T]](list:List[T]):List[T] = {
list.match({
case Nil => Nil;
case x::xs =>
val (before,after) = xs.partition({ i => i.<(x) });
qsort(before).++(qsort(after).::(x)));
});
}
def qsort[T <% Ordered[T]](list:List[T]):List[T] = list match {
def requestAccToken(code:String): Option[String] = if(code=="bad") None else Some("token")
def requestOpenId(token:String): Option[String] = Some("openId")
def requestUserInfo(openId:String): Option[String] = Some("notyy's account")
def getUser(code:String):Option[String] = requestAccToken(code) flatMap(requestOpenId) flatMap(requestUserInfo)