Skip to content

Instantly share code, notes, and snippets.

@songpp
songpp / InsertionSort.cpp
Created April 2, 2011 07:34
插入排序
//============================================================================
// Name : Algorithm.cpp
// Author : Songpp
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <vector>
using namespace std;
@songpp
songpp / SQLParser.scala
Created April 2, 2011 07:37
sql statement combinator parser
package par
import scala.util.parsing.combinator._
class SqlTokenParser extends JavaTokenParsers{
def ws : Parser[String] = """\s+""".r
def query : Parser[Any] = selectClouse ~ fromClouse
@songpp
songpp / Review.hs
Created April 2, 2011 07:45
haskell基础复习巩固
-- fold left
foldLeft :: (b -> a -> b) -> b -> [a] -> b
foldLeft _ acc [] = acc
foldLeft f acc (x : xs) = foldLeft f (f acc x) xs
-- fold right
foldRight :: (a -> b -> b) -> b -> [a] -> b
foldRight f acc [] = acc
foldRight f acc (x : xs) = f x (foldRight f acc xs)
@songpp
songpp / Tree.hs
Created April 2, 2011 07:46
haskell very simple tree
module Tree where
data Tree v = EmptyTree
| Node v (Tree v) (Tree v)
deriving Show
singleton value = Node value EmptyTree EmptyTree
--map f EmptyTree = EmptyTree
--map f Node v left right = Node (f v) (map f left) (map f right)
@songpp
songpp / OnError.js
Created April 2, 2011 07:50
javascript window onerror function
window.onerror = function() {
/**
* onerror 事件
* arguments 共三个
*
* 第一个 错误原因
* 第二个 所在js文件
* 第三个 第几行
*/
arglen = arguments.length;
@songpp
songpp / blockgiven.rb
Created April 2, 2011 07:56
ruby block given ?
def t1(ar1,ar2,&block)
if(block_given?)
yield(ar1,ar2)
else
puts ar1 , ar2
end
block.call(ar1,ar2)
end
@songpp
songpp / QuickSort.scala
Created April 2, 2011 08:00
scala 快速排序
package flower.april.sort
import flower.april.util.ArrayUtils
/**
* Date: 2010-7-26
* Time: 12:34:40
* Description:
*/
@songpp
songpp / ScalaContinuations.scala
Created April 2, 2011 08:01
scala delimited continuations
package flower.april.continuation
import scala.util.continuations._
import java.util.{Timer, TimerTask}
/**
* User: i-flower
* Date: 2010-8-10
* Time: 20:28:05
* this blow up my mind
@songpp
songpp / AVLTree.scala
Created April 3, 2011 13:40
scala版 AVLTree
package org.songpp.structure
object AVLTree {
/**
* 2011-04-03
* 未完成。
* 关键的旋转算法还没实现。
* toy-writing for fun and studying scala
* base on scala collections framework
@songpp
songpp / Fp.scala
Created March 16, 2012 09:24
from Scalaz Video
package org.songpp.fp
/*
* scala
*/
trait FoldLeft[F[_]] {
def foldLeft[A, B](xs: F[A], init: B, func: (B, A) => B): B
}
object FoldLeft {
implicit object FoldLeftList extends FoldLeft[List] {