ITeye博客

蜡笔的涂鸦

t0uch · 共 47 篇文章

percona安装小问题

不知道为什么,死活装不上innodb-plugin,发现mysql到安装有bug,特此记录 ./configure --prefix=/usr/local --with-extra-charsets=complex --with-plugins=innodb_plugin,myisam --without-debug --with-ssl --enable-assembler --enable-thread-safe-client --enable-shared --enable-local-infile --without-plugin-innobase --without-plugin-…

2010-11-01 16:23 · 评论(0)

rails3中使用delayed_job异步发送邮件的方法

railscasts有个视频,使用delayed_job去发送邮件(http://railscasts.com/episodes/171-delayed-job) 但是呢,rails3的发送邮件的api发生了些许变化。(详情请看:http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3) 发送的方法上也要做些许的修改。这里以我的代码作为示例,做个示范。 这里的UserMailer大概代码: class UserMailer < ActionMailer::Base default :from => "admin@example…

2010-05-23 17:34 · RoR · 评论(0)

最新版ruby编译的痛苦(readline)

由于configure不支持--with-readline-dir的选项了,查了很久,发现用REE的installer可以支持。手动下载安装readline后,可以通过如下方式指定radline的路径: sudo ./installer -a /usr/local --no-tcmalloc -c --with-readline-dir=/usr/local 这个问题折腾了好几天,特此记录。

2010-03-31 21:20 · RoR · 评论(0)

SICP 2.33~2.39习题答案

(define (filter predicate sequence) (cond ((null? sequence) nill) ((predicate (car sequence)) (cons (car sequence) (filter predicate (cdr sequence)))) (else (filter predicate (cdr sequence))))) (define (accumulate op initial sequence) (if (null? sequence) initial (op (car sequence) (accumulate op i…

2010-02-06 17:06 · SICP · 评论(0)

Rails 3.0 release note

官方的文档已经出来了 http://guides.rails.info/3_0_release_notes.html 我最感兴趣的是2.3.5如何升级到3.0。官方做了个rails_upgrade插件来帮助用户升级。 方法很简单: 先安装 script/plugin install git://github.com/rails/rails_upgrade.git 然后按照如下命令来做您需要的事情即可 # Check your app for required upgrades rake rails:upgrade:check # Backup your likely modified fil…

2010-02-03 09:57 · RoR · 评论(13)

SICP 2.30~2.32 习题答案

;; 2.30 ;(define (square-tree tree) ; (cond ((null? tree) nil) ; ((not (pair? tree)) (* tree tree)) ; (else (cons (square-tree (car tree)) ; (square-tree (cdr tree)))))) ;(define (square-tree tree) ; (map (lambda (sub-tree) ; (if (pair? sub-tree) ; (square-tree sub-tree) ; (* sub-tree sub-tree))) ;…

2010-01-26 18:01 · SICP · 评论(0)

SICP 2.25~2.29习题答案

这一节难度开始加大,有一些答案是借鉴了别人才做出来的。 ;; 2.25 (define list1 (list 1 3 (list 5 7) 9)) ;(car (cdr (car (cdr (cdr list1))))) (define list2 (list (list 7))) ;(car (car list2)) (define list3 (list 1 (list 2 (list 3 (list 4 (list 5 (list 6 7))))))) ;(car (cdr (car (cdr (car (cdr (car (cdr (car (cdr (car (cdr list3…

2010-01-25 17:00 · SICP · 评论(0)

SICP 2.17~2.23 习题答案

这一节比较容易 (define (square n) (* n n)) (define (list-ref items n) (if (= n 0) (car items) (list-ref (cdr items) (- n 1)))) (define (length items) (if (null? items) 0 (+ 1 (length (cdr items))))) (define (append list1 list2) (if (null? list1) list2 (cons (car list1) (append (cdr list1) list2)))) ;; 2.1…

2010-01-20 11:12 · SICP · 评论(0)

SICP 2.7~2.16习题答案

这一段的题目有点多,都是要有前面的代码的,写到一起得了 2.13用代数式看一下就知道了,比较容易。 2.14用代码试试看就知道了,感觉操作会引起误差,但不知道为什么,2.15,2.16同样 但是通过2.14的结果就知道,2.15的结论应该是对的,除法运算并没有引入新的误差。 2.2节开始进入令人愉快的数据结构了,^_^。令人期待。 (define (make-interval a b) (cons a b)) ;; 2.7 (define (lower-bound n) (car n)) (define (upper-bound n) (cdr n)) (define (width-inte…

2010-01-18 15:28 · SICP · 评论(0)

SICP 2.6 习题答案-lambda算子

2.6这道题目需要一些lambda算子的知识,g9的blog有很不错的文章翻译了。 具体是这样的,首先是one,one即为zero add-1,所以把zero代入add-1的表达式中,得: lambda (f) (lambda (x) (f (((lambda (f) (lambda (x) x)) f) x))) 将f代入zero的lambda表达式中,得 lambda (f) (lambda (x) (f ((lambda (x) x) x))) 然后正好可以将x代入后面lambda (x)的表达式中,得到one lambda (f) (lambda (x) (f (x))) two也是…

2010-01-12 18:03 · SICP · 评论(0)

SICP 2.5 习题答案

通过数学的方法可以解决,假设乘积n不是偶数,那a肯定是0。 (define (power x n r) (if (< n 1) r (power x (- n 1) (* r x)))) (define (cons a b) (* (power 2 a 1) (power 3 b 1))) (define (car n) (define (car-iter x counter) (if (not(even? x)) counter (car-iter (/ x 2) (+ counter 1)))) (car-iter n 0)) (define (cdr n) (define (cdr-i…

2010-01-11 15:34 · SICP · 评论(0)

SICP 2.4 习题答案

小小试了一下,结果应该没有错 (define (cdr z) (z (lambda (p q) q)))

2010-01-11 13:57 · SICP · 评论(0)

SICP 2.3 习题答案

可能书上想让我用2.2的答案,实在不想那么搞。。。 (define (make-point x y) (cons x y)) (define (x-point p) (car p)) (define (y-point p) (cdr p)) (define (make-rect left-top right-bottom) (cons left-top right-bottom)) (define (bottom-left rect) (make-point (x-point (car rect)) (y-point (cdr rect)))) (define (bottom-right r…

2010-01-11 12:06 · SICP · 评论(0)

passenger也可以debug

最近在做一个东西,要用到subdomain,发现webrick不能支持,所以寻找passenger进行debug的方法。 方法比较土,但还是管用的。 首先,往development.rb里加入 if File.exists?(File.join(RAILS_ROOT,'tmp', 'debug.txt')) require 'ruby-debug' Debugger.wait_connection = true Debugger.start_remote File.delete(File.join(RAILS_ROOT,'tmp', 'debug.txt')) end 接着在lib/task…

2009-12-17 15:23 · RoR · 评论(4)

SICP 2.2 习题答案

cons对于数据结构来说是一个很强大的东西 (define (print-point p) (newline) (display "(") (display (x-point p)) (display ",") (display (y-point p)) (display ")")) (define (make-point x y) (cons x y)) (define (x-point p) (car p)) (define (y-point p) (cdr p)) (define (make-segment start end) (cons start end)) (define (s…

2009-12-11 17:32 · SICP · 评论(0)