2010年11月21日星期日

haskell shell prototype

只是一个非常土的原型……

效果:
*Funs> select (from "/home/march/temp/text/\\.(tex|csv)$") >>= whereLines "end"
["\\end{center}","\\end{document}"]
代码:


module Funs where
import Data.List
import Monad
import System.Directory
import System.FilePath
import System.IO
import Text.Regex.PCRE

data Store t p = Text p 
               | Csv p
               | Bin p
               | File p

selectFrom (Text store) = do
  content <- readFile store
  return$lines content

unionIt :: IO [[String]] -> IO[String]
unionIt = liftM concat

select :: IO [FilePath] -> IO [String]
select paths = paths 
               >>= \ps -> unionIt(filterM doesFileExist ps 
                              >>= mapM (\p -> selectFrom (Text p)))

from :: FilePath -> IO [FilePath]
from path = let (dir, files) = splitFileName path
            in liftM(\lines->[dir++line | line <- lines, line=~files])
                   ((getDirectoryContents.takeDirectory) dir)

whereLines :: String -> [String] -> IO [String]
whereLines reg lines = return $filter (\line -> line =~ reg :: Bool) lines
这段代码已经包含了基本的 select from where 模式,甚至可以说已经是一个实 用的实现,但是对于我来说,期待它有进一步的功能:
  • 有真正的前端脚本
  • 可以在 select 后设定输出字段,如匹配文件字和行号,以及进一步用正则对行 文件分组
  • 将 where 嵌入 select 过程,真正实现流式过滤
  • 支持 limit offset
  • 支持CSV
  • 支持 group by … having
  • 支持 order by

2010年11月18日星期四

《Python速成讲座》使用的新幻灯设置

上次的幻灯中,我对平时使用的 latex 代码做了一些调整,新的引言区如下:

\documentclass[utf8x, notes=hide]{beamer}

%\usepackage[bars]{beamerthemetree} % Beamer Theme v 2.2
\usetheme{boxes} % Beamer theme
\usecolortheme{seahorse} % Beamer color theme

\usepackage[boldfont,slantfont]{xeCJK}
\usepackage{fontspec}
\setmainfont{DejaVu Serif}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}%{Monaco}
\setCJKmainfont{文泉驿正黑}
\setCJKsansfont{文泉驿微米黑}
\setCJKmonofont{WenQuanYi Micro Hei Mono}
\setCJKfamilyfont{tt}{Monaco}

\usepackage{color}
\definecolor{listinggray}{gray}{0.9} 
\usepackage{xcolor}

\usepackage{listings}
\lstset{language=Python,
numbers=left,
backgroundcolor=\color{listinggray},
frame=single,
framexleftmargin=7mm,
frameshape={RYN}{y}{y}{RYN}}
\usepackage{hyperref}
\usepackage{graphicx}
其中最主要的改动是利用xeCJK 对中西文字体做了定制,以及 lstlisting 代码区的定制(圆角、显示行号)

2010年11月9日星期二