logoruby


undefined method `count’ for Array

Posted in rails, ruby by wanguan2000 on the 03月 24th, 2009

[1,2,3,4].count you should get an undefined method error

Production:
script/console production
Loading production environment (Rails 2.1.0)
>> User.all.class
=> Array
>> User.find(:all).class
=> Array
>> User.find(:all).count
NoMethodError: undefined method `count’ for #
from (irb):3

Development:
script/console
Loading development environment (Rails 2.1.0)
>> User.all.class
=> Array
>> User.find(:all).class
=> Array
>> User.find(:all).count
=> 2

有时就是会报错,so 可以改成User.find(:all).length

评论关闭

rails 里面设置中文响应

Posted in rails by wanguan2000 on the 03月 18th, 2009

直接这样:
不work:

def searchone
@headers["Content-Type"] = "text/html; charset=gb2312"
@response.headers["Content-Type"] = "text/html; charset=gb2312"
=end

评论关闭

回传input框中的鼠标选择文本(firefox ie)

Posted in AJAX, rails by wanguan2000 on the 03月 17th, 2009

var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));

function getSelectionText(){
var myArea = document.getElementById("wg");
var selection;
if (!ie){

if (myArea.selectionStart != undefined) {
selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);

alert(selection);
}
}else{
if (window.getSelection){
selection = window.getSelection();

}else if (document.getSelection){
selection = document.getSelection();

}else if (document.selection){
selection = document.selection.createRange().text;

}
}
return selection;
}

$('document').ready(function() {

$('#wg').mouseup(tuLoad);

});

function tuLoad(){
var str = getSelectionText();
var text2 = "/search/tu/" + str;

if (str.toString().length > 0) {

$('#dictionary').load(text2);
}

}

A

load

评论关闭

ruby的RMagick使用很简单很强大

Posted in rails, ruby by wanguan2000 on the 03月 3rd, 2009

http://www.imagemagick.org/RMagick/doc/
rmagick 给图片添加红线,很简单吧

require 'rubygems'
require 'RMagick'

imgl = Magick::Image.read(”affineok102.gif”).first

max_y = imgl.rows
max_x = imgl.columns

select_gc = Magick::Draw.new
select_gc.stroke(’red’)
select_gc.stroke_width(2)
select_gc.line(10,max_y-60,140,max_y-60)
select_gc.draw(imgl)

imgl.border!(1, 1, “lightcyan2″)
imgl.write(”sss.gif”)

1)定义主要对象
使用RMagick,重要会用到两个对象:Image和Draw。这两个对象可以形象的理解为:Image对象相当于画布,Draw对象相当于画笔。
为方便以下说明,我这样定义这两个对象:
ruby 代码

1. require ‘rmagick’ //千万别忘了在文件开头加上这段代码
2. canvas = Magick::Image.new(width,height,Magick::HatchFill.new(bg_color,bg_color))
3. gc = Magick::Draw.new

参数说明:Image对象定义的前两个参数是定义图片的宽和高,后门一个定义图片的背景(可选),默认为白色。
要读取一个存在的图片,Image对象还有如下定义方式:
ruby 代码

1. img=Magick::Image.read(image_path).first //image_path是字符串形式的图片路径
2. Image对象定义后,根据img.rows和img.columns可以获得它的高度和宽度。

(2)对象使用方法
gc对象的主要功能有:在图片上写字,在图片上画线,把另一张图片组合到当前图片上。下面我主要说两个问题:
在图片上写中文:
主要有两个方法gc.text,gc.annotate 相关参数可以在gotapi上轻松查到。用这两个方法写系统自带的英文字体是非常方便的,gc.font,gc.font_family可以设置字体,还可以通过gc. font_style, gc.font_weight来设置斜体和粗体,它们的参数是类似Magick::ItalicStyle、Magick::NormalStyle、 Magick::BoldWeight、Magick::LighterWeight这样的常量。当然还有gc.pointsize来设置字体大小,这个对于中英文是通用的。
我这里主要对写中文字体做一些介绍。由于RMagick对中文支持不好,当时使用它写中文的时候默认情况下只发现了黑体可以使用(当然是在我的 windows平台下)。因为我们图片处理需要提供多种字体来写字,还考虑到发布环境在linux下,所以我们用了这样的方法:从Windows的字体文件夹c:/windows/fonts下拷贝出中文字体库到自己的工程目录中,然后通过设置gc.font来使用它们。下面是我的例子:
ruby 代码

1. require ‘RMagick’
2.
3. img = Magick::Image.new(200,200,Magick::HatchFill.new(’green’,'green’))
4.
5. gc = Magick::Draw.new
6. gc.stroke(’transparent’)
7. gc.pointsize(24)
8. gc.font(”fonts/STCAIYUN.TTF”)
9. gc.text(20,40, ‘我爱你啊’)
10.
11. gc.font(”fonts/STXINWEI.TTF”)
12. gc.text(20,70, ‘我爱你啊’)
13.
14. gc.fill(’white’)
15. gc.font(”fonts/FZSTK.TTF”)
16. gc.text(20,100, ‘我爱你啊’)
17.
18. gc.font(”fonts/simhei.ttf”)
19. gc.text(20,130, ‘我爱你啊’)
20.
21. gc.font(”fonts/yihejianti.TTF”)
22. gc.text(20,160, ‘我爱你啊’)
23.
24. gc.draw(img)
25. img.write(’love.jpg’)

运行结果:
附件图片love1.jpg
说明:如果你想保存并运行这段代码,请保存为UTF-8的格式,否则会乱码,还要保证你当前文件的fonts目录下有这些ttf字库文件。

这里还要强调的是,在写字的时候一定要设置gc.stroke(’transparent’)。尽管gc.stroke最开始默认的是 transparent,但我还是建议在每次写字之前设置一次,否则如果在之前使用过gc.stroke并且设置了非transparent的值,那么写出来的字会是下面这样的(我把transparent换成了red)
附件图片love2.jpg
当然,如果你想要达到这种效果则另当别论了。如果你想要写出更多的中文字体,那就去下载更多的字体库就可以了,是不是很简单?
我现在还有一个问题没有解决:不知道哪里可以下载中文字体的粗体斜体字库(如黑体,宋体,隶书、楷体等),麻烦知道的朋友告之,我的邮箱zhangxiaoyao067, gmail.com
继续罗嗦一点:对字体的设置有gc.font(ttf_file)和gc.font=ttf_file这两种方式,它们的区别在什么地方呢?还是用上面那个例子来说明。如果其中所有的gc.font(ttf_file)换成gc.font=ttf_file,那么最后的结果会是
附件图片love3.jpg
看明白了吧?也就是用“=”的时候,只有最后一个起作用。

图片裁剪:
还是用代码来说明吧
ruby 代码

1. gc.define_clip_path(’clip_pic’){
2. gc.stroke_width(0)
3. gc.rectangle(lefttop_x,lefttop_y,rightbottom_x,rightbottom_y)}
4. gc.push
5. gc.clip_path(’clip_pic’)
6. gc.composite(x, y, width, height,Magick::Image.read(myImageUrl))
7. gc.pop

说明:首先要定义一个裁剪区域,这里我定义了一个矩形区域,然后是应用。只有在裁剪区域内部的图片才会画到画布上面。这里要注意的是gc.push, gc.pop,因为gc.clip_path的裁剪会应用在gc的整个存活期内部,因此gc.draw的所有内容都会限制在这个裁剪区域内部。这两个操作相当于对裁剪应用的释放。
ok,暂时写这么多吧.
http://www.imagemagick.org/RMagick/doc/

我作的坐标图,很酷
class Disordertu2
def self.distu(disorder,tmhmm,teyi,pfam,hydoca)

seqlength = disorder.length

require 'rubygems'
require 'RMagick'

# Demonstrate the affine primitive. Transform the
# coordinate space to put the origin in the lower
# left corner.

imgl = Magick::ImageList.new
imgl.new_image seqlength+20, 300, Magick::HatchFill.new('white','lightcyan2')

gc = Magick::Draw.new

max_x = imgl.columns
max_y = imgl.rows

# Translate the y origin to the bottom of the window.
# Invert the y points by scaling by -1. Combine the
# two operations using the affine method. That is, the
# affine method is equivalent to:
# gc.translate 0, max_y
# gc.scale 1, -1
gc.affine(1, 0, 0, -1, 0, max_y)
gc.stroke('gray50')
gc.fill('gray50')
gc.stroke_width(1)

# Draw up-pointing arrow.
gc.polyline(10, 20, 10, max_y-20, 5, max_y-25, 15, max_y-25, 10, max_y-20)

# Draw right-pointing arrow
gc.polyline(10, 20, max_x-10, 20, max_x-15, 15, max_x-15, 25, max_x-10, 20)
gc.line(10,max_y/2,max_x-10,max_y/2)
gc.draw(imgl)

# Add labels. Use a different graphics context with a "normal"
# coordinate system so the text isn't inverted.
text_gc = Magick::Draw.new
text_gc.pointsize(10)
text_gc.font_weight(Magick::NormalWeight)
text_gc.stroke('transparent')
text_gc.text(10, max_y-10, "'0'")
#text_gc.text(max_x-20, max_y-16, "'Position'")
text_gc.text(max_x/2-50, 15, "'ABmart antibody analysis'")
text_gc.text(10, max_y/2, "'0.5'")
text_gc.draw(imgl)

text_gc = Magick::Draw.new
text_gc.pointsize(8)
text_gc.font_weight(Magick::NormalWeight)

#position location 10-280
(10..max_x-10).each{|position|
if position % 20 == 0
text_gc.text(10+position, max_y-22, "|")
text_gc.text(10+position-5, max_y-10, "#{position}")
end

}

text_gc.draw(imgl)

#线disorder

points = Array.new

(0..disorder.length-1).each{|dian|
#point_gc.point(10+dian+1, max_y-20 - disorder[dian].to_f*260)
#point_gc.polyline(10+dian+1, max_y-20 - disorder[dian].to_f*260)
points << 10+dian+1
points << max_y-20 - disorder[dian].to_f*260
}
line_gc = Magick::Draw.new
line_gc.stroke('blue').stroke_width(1)
line_gc.fill_opacity(0)
line_gc.polyline(*points)

line_gc.draw(imgl)

#teyi

points2 = Array.new

(0..teyi.length-1).each{|dian|
#point_gc.point(10+dian+1, max_y-20 - disorder[dian].to_f*260)
#point_gc.polyline(10+dian+1, max_y-20 - disorder[dian].to_f*260)
points2 << 10+dian+1
points2 < 1
pfam.each_slice(2) do |slice|
line_gc.stroke('limegreen')

line_gc.stroke_width(20)
line_gc.opacity('70%')
line_gc.line(slice[0],max_y/2,slice[1],max_y/2)

end
line_gc.draw(imgl)
end
=begin
#短肽
nshort = 1
short.each{|mshort|

weizhishort = mshort[0].to_f/2.0
hou = mshort[1]/2.0 + weizhishort

# Draw 10-pixel wide line 短肽
gc.stroke('GreenYellow')
gc.stroke_width(20)
gc.line(weizhishort,max_y/2,hou,max_y/2)

# Annotate 第一行字
gc.fill('black')
gc.stroke('transparent')
gc.text(weizhishort,45,"P#{nshort}:#{mshort[0]}")
nshort += 1
}

=end

#2线tmhmm

points2 = Array.new

(0..tmhmm.length-1).each{|dian|
#point_gc.point(10+dian+1, max_y-20 - disorder[dian].to_f*260)
#point_gc.polyline(10+dian+1, max_y-20 - disorder[dian].to_f*260)
points2 << 10+dian+1
points2 < 0.0
hydoca_gc.stroke('Sea Green')
hydoca_gc.opacity('70%')
hydoca_gc.stroke_width(1)
hydoca_gc.line(10+hynumber,max_y-60,10+hynumber,max_y-60-amino*6.0)

else
hydoca_gc.stroke('Crimson')
hydoca_gc.opacity('70%')
hydoca_gc.stroke_width(1)

hydoca_gc.line(10+hynumber,max_y-60,10+hynumber,max_y-60-amino*6.0)
end
hynumber += 1
}

hydoca_gc.draw(imgl)

#选择片段
=begin
select_gc = Magick::Draw.new
select_gc.stroke('red')
select_gc.stroke_width(2)
select_gc.line(10,max_y-60,140,max_y-60)
select_gc.line(40,max_y-40,140,max_y-40)
select_gc.line(40,max_y-80,140,max_y-80)
select_gc.draw(imgl)
=end

imgl.border!(1, 1, "lightcyan2")
#rand(100).to_s

imgl.write("./public/images/affineok95.gif")

return ""

end
end

评论关闭

Perl API Installation for Ensembl

Posted in bioinformatics, mysql, rails, 网球 by wanguan2000 on the 02月 12th, 2009

http://www.ensembl.org/info/data/ftp/index.html

http://hgdownload.cse.ucsc.edu/downloads.html

EnsEMBL 简介

[编辑] 主办机构

EnsEMBL是由Sanger中心EMBL-EBL共同维护的基因组注释系统。该项目的主要组织者就是BioPerl的元老Ewan Birney

[编辑] 目标

EnsEMBL力图实现以下目标:

  • 准确的基因组自动注释
  • 基于注释信息的全面分析
  • 向全世界公开发布注释与分析结果
  • 以开源合作的方式开发注释与分析所需要的软件(因为是E.B.在管,这里说的软件当然主要是基于Perl/BioPerl。另外这里说的软件仅能用于以EnsEMBL database格式存储的基因组信息)

[编辑] EnsEMBL Perl API 概述

[编辑] EnsEMBL Core

用于组织和分析:

  • 基因组的原始序列
  • 染色体名字等最高级的注释(Top-level annotation)
  • Gene,Transcript(mRNA/ncRNA等),Translation(peptide)的注释
  • microarray(芯片)探针对应的基因组位置的信息
  • 其它外部注释信息的链接(例如GO)

[编辑] EnsEMBL Compara

用于组织和分析:

  • 物种间的局部多序列比对结果
  • 共线性区(Synteny Region)的注释
  • 旁系同源(Paralogue)/直系同源(Orthologue)基因的注释
  • 蛋白家族的定义

[编辑] EnsEMBL Variation

用于组织和分析:

  • SNP(单核甘酸多态)/in-del/CNV等形式的variation注释
  • 群体/基因型/等位基因状态
  • 连锁不平衡信息

[编辑] EnsEMBL EST

软件上是和EnsEMBL Core一样的,只是数据不一样

[编辑] EnsEMBL Perl API 安装

[编辑] 安装BioPerl

需要先安装BioPerl(请参考BioPerl安装)

$ cvs -d :pserver:cvs@code.open-bio.org:/home/repository/bioperl login

Logging in to :pserver:cvs@code.open-bio.org:2401/home/repository/bioperl

CVS password: cvs

$ cvs -d :pserver:cvs@code.open-bio.org:/home/repository/bioperl checkout -r bioperl-release-1-2-3 bioperl-live

另外数据库(一般是MySQL)也是必需的

[编辑] 安装EnsEMBL的模块

文件会被安装到当前目录下

$ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl login

Logging in to :pserver:cvsuser@cvs.sanger.ac.uk:2401/cvsroot/ensembl

CVS password: CVSUSER

$ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl checkout -r branch-ensembl-45 ensembl

上面最后一行安装的是EnsEMBL Core,若需要安装EnsEMBL Variation,则需将最后的ensembl换成ensembl-variation,即:

$ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl checkout -r branch-ensembl-45 ensembl-variation

[编辑] 设置环境变量

目的是让Perl可以找到相关模块:

PERL5LIB=${PERL5LIB}:/path/to/BioPerl/modules

PERL5LIB=${PERL5LIB}:/path/to/ensembl-core/modules

PERL5LIB=${PERL5LIB}:/path/to/ensembl-variation/modules

PERL5LIB=${PERL5LIB}:/path/to/ensembl-compara/modules

export PERL5LIB

请把”/path/to/BioPerl/modules”换成BioPerl模块实际安装的目录。同理,后面的”/path/to/ensembl-core/modules”等,也应该换成EnsEMBL模块实际安装的目录。

[编辑] 下载EnsEMBL数据库

该步不是必须的,本地化与否的优劣,请大家自己考虑。

请到EnsEMBL的FTP下载mysql数据库文件并导入本地mysql数据库,即可在本地使用EnsEMBL的数据。

注意:数据库很大,特别是EnsEMBL Compara。

[编辑] EnsEMBL Perl API 更新

EnsEMBL的数据和API的版本是一一对应的,数据更新过之后必须更新对应的API。用CVS可以很方便地更新,只需在模块安装的目录下运行:

cvs -q update -d -P -r branch-ensembl-45

[编辑] EnsEMBL Perl API 基本用法

要使用EnsEMBL的数据库,首先需要链接上数据库,由于EnsEMBL定义了很多对象及其Adaptor,所以提供了统一的 Bio::EnsEMBL::Registry模块来方便地获取这些Adaptor(曾几何时,要自己建DBAdaptor,然后再建对象的 Adaptor),同时可以避免建立多余的DBAdaptor。

  • 获取预设的数据库连接

use Bio::EnsEMBL::Registry;

my $registry = ‘Bio::EnsEMBL::Registry’;

$registry->load_registry_from_db(-host => ‘ensembldb.ensembl.org’,-user => ‘anonymous’);

  • 获取您所需要的注释信息

上面提到的所有注释信息都可以经由对应的对象的Adaptor获得,例如Gene:

my $gene_adaptor = $registry->get_adaptor( ‘Human’, ‘Core’, ‘Gene’ ); #获得GeneAdaptor对象,可用于读取人的EnsEMBL Core数据库内的信息

my $gene = $gene_adaptor->fetch_by_stable_id(”ENSG00000099889″); #获得一个基因序列及其他注释信息

又例如基因组片段(Slice):

my $slice_adaptor = $registry->get_adaptor(”Human”,”Core”,”Slice”);

my $slice = $slice_adaptor->fetch_by_region(”chromosome”,”14″,”5623425″,”5673425″); # 获得基因组上的一段序列

上面提到的基因组片段(Slice)还可以结合其他Adaptor,查找该片段上的任何注释信息(基因、Exon、多态、芯片探针、等等等等……)。

[编辑] 可以使用EnsEMBL的物种

目前只有部分物种有EnsEMBL化的注释系统:

Human 人 / Mouse 小鼠 / Zebrafish 斑马鱼 / C.elegans 秀丽隐杆线虫 / Cat 猫 / Chicken 鸡 / Chimpanzee 黑猩猩 / Cow 牛 / Dog 狗 / Elephant 象 / Fruitfly 果蝇 / Platypus 鸭嘴兽 / Rabbit 兔 / Rat 大鼠 / S.cerevisiae 酵母 , 等等(主要是动物)

Oryza sativa 栽培稻 / Oryza rufipogon 野生稻 / Zea mays 玉米 / Arabidopsis thaliana 拟南芥

Introduction

All data sets in the Ensembl system are stored in relational databases (MySQL). For each of the Ensembl databases the project provides a specific Perl API. As Ensembl takes also advantage of code provided by the BioPerl project; installation of the BioPerl package is included in these instructions.

Ensembl uses the Concurrent Versions System (CVS) for storing the source code and keeping track of source code revisions. This system will help you keeping up to date with developments and bug fixes. You will need CVS installed if you want to download Ensembl code. Graphical CVS clients are also available for Windows, e.g. WinCVS or TortoiseCVS.

If your computer system is protected by a firewall, this firewall needs to allow outgoing connections to TCP port 2401. There is also a web-based CVS repository, which allows you to download Unix tar archives in case CVS access through a firewall is not possible.

Installation Procedure

  1. Create an installation directory
    $ cd
    $ mkdir src
    $ cd src
  2. Log into the BioPerl CVS server (using a password of cvs):
    $ cvs -d :pserver:cvs@code.open-bio.org:/home/repository/bioperl login
    Logging in to :pserver:cvs@code.open-bio.org:2401/home/repository/bioperl
    CVS password: cvs
  3. Install BioPerl (version 1.2.3)
    $ cvs -d :pserver:cvs@code.open-bio.org:/home/repository/bioperl checkout -r bioperl-release-1-2-3 bioperl-live

    Important note: you must install version 1.2.3, not a more recent version. Starting with 1.2.4, major changes were made to the BioPerl API which have made it incompatible with Ensembl

  4. Log into the Ensembl CVS server at Sanger (using a password of CVSUSER):
    $ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl login
    Logging in to :pserver:cvsuser@cvs.sanger.ac.uk:2401/cvsroot/ensembl
    CVS password: CVSUSER
  5. Install the Ensembl Core Perl API for version 52
    $ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl checkout -r branch-ensembl-52 ensembl
  6. If required, install the Ensembl Variation Perl API for version 52
    $ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl checkout -r branch-ensembl-52 ensembl-variation
  7. If required, install the Ensembl Functional Genomics Perl API for version 52
    $ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl checkout -r branch-ensembl-52 ensembl-functgenomics
  8. If required, install the Ensembl Compara Perl API for verion 52
    $ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl checkout -r branch-ensembl-52 ensembl-compara

    NB: You can install as many Ensembl APIs as you need in this way. To install all the APIs in one go, use the command:

    $ cvs -d :pserver:cvsuser@cvs.sanger.ac.uk:/cvsroot/ensembl checkout -r branch-ensembl-52 ensembl-api
  9. Set up your environmentYou have to tell Perl where to find the modules you just installed. You can do this by using the use lib clause in your script but if you want to make these modules available for all your scripts, the best way is to add them into the PERL5LIB environment variable.
    • Under bash, ksh, or any sh-derived shell:
      PERL5LIB=${PERL5LIB}:${HOME}/src/bioperl-live
      PERL5LIB=${PERL5LIB}:${HOME}/src/ensembl/modules
      PERL5LIB=${PERL5LIB}:${HOME}/src/ensembl-compara/modules
      export PERL5LIB
    • Under csh or tcsh:
      setenv PERL5LIB ${PERL5LIB}:${HOME}/src/bioperl-live
      setenv PERL5LIB ${PERL5LIB}:${HOME}/src/ensembl/modules
      setenv PERL5LIB ${PERL5LIB}:${HOME}/src/ensembl-compara/modules
    • Under Windows (assuming you installed the APIs in C:\src\):
      set PERL5LIB=C:\src\bioperl-live;C:\src\ensembl\modules;C:\src\ensembl-compara\modules

    NB: If you installed extra Ensembl APIs, don’t forget to add their path to the PERL5LIB environment variable.

Additional Tips for Windows users

  • You will of course need Perl installed to use the API! This is available free of charge from ActiveState.
  • You will also need to install the DBD::MySQL package using PPM (Perl Package Manager), a command-line tool which is bundled with ActivePerl.
  • If the existing mysql-driver (”libmysql.dll”) doesn’t work, replace it – e.g. with the one distributed with “php-5-2-3-win32-installer.msi”

Additional Modules

Additional modules for accessing GO data may be found here:

Update Procedure

In case you want to update the Perl APIs to a more recent version, keep in mind that the API and database versions must be identical; you can use a simple CVS command to achieve this.

  1. Change the working directory to the directory into which you originally installed the APIs.
    $ cd
    $ cd src
  2. For each of the APIs, change into its top-directory before issuing the CVS update command. So for the Ensembl Core API, which has been automatically installed into the ensembl directory use the following commands:
    $ cd ensembl
    $ cvs -q update -d -P -r branch-ensembl-52
    $ cd ..

    CVS will automatically add, modify or delete files so that your working directory will resemble the ensembl-branch you selected.

    In case you are asked for a password, repeat the login steps in the installation procedure above. (The password is normally stored in encrypted form in a file in your home directory and remembered between CVS operations.)

评论关闭

github

Posted in rails by wanguan2000 on the 01月 15th, 2009

github

sudo gem install mysql –with-mysql-config

/usr/lib/ruby/gems/1.8/gems

sudo gem install mysql -with-mysql-config=/usr/bin/mysql_config

ubuntu下安装mysql找不到mysql_config
2008-03-13 17:30
安装“libmysqlclient15-dev”包就可以了

1. clone from github: git clone git://github.com/knewter/ansuz.git
2. create database config in config/database.yml (see config/database.yml.example if you need help)
3. run: gem sources -a http://gems.github.com
4. install gems: rake gems:install
5. run: gem install haml –no-ri –no-rdoc
6. run plugin migrations: rake db:migrate:plugins
7. create databases: rake db:create:all
8. run migrations: rake db:migrate
9. run tests: rake spec
10. create a new user (do not use this in production): rake utils:createadmin
11. create the folder at public/uploads (This is for fckeditor’s resource browser / uploader)
12. start server: script/server -p 3000
13. goto: http://localhost:3000/admin
14. login with admin/admin

* Extract sources to a folder
* Create a database.yml file in the config directory. You can copy the database.yml.example
* Create your databases: rake db:create:all
* Migrate your database: rake db:migrate
* Start the server in production mode : ruby script/server -e production

评论关闭

rails 开源项目

Posted in rails by wanguan2000 on the 01月 14th, 2009

http://www.opensourcerails.com/
非常棒的rails开源项目。

评论关闭

ruby 每次迭代了两个怎么写?

Posted in rails, ruby by wanguan2000 on the 01月 14th, 2009

[1,2,3,4,5,6].each_slice(2) do |slice|
print slice[0] , “,” , slice[1] , “\n”
end

在:ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux]报错

undefined method `each_slice’ for :Array
加上这个就可以了:require ‘enumerator’

但是在ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]下没有问题

a = [1,1,1,2,2,2,3,3,3]

a.each(3) do |x,y,z|
print x,y,z,”\n”
end

评论关闭

rails 图片缓存的问题

Posted in rails by wanguan2000 on the 01月 8th, 2009

好像不行,对ie没有用,对firefox可以用。(ubuntu平台下)

这样会在ie下缓存,

singnalp

而这样不会

因为rails默认是no-cache的

@articles = cache(’articles’) do
Articles.latest
end

评论关闭

ubuntu 下rmagick的安装

Posted in rails by wanguan2000 on the 01月 4th, 2009

资源:

http://www.imagemagick.org/RMagick/doc/

http://www.imagemagick.org/RMagick/doc/draw.html


sudo apt-get remove --purge librmagick-ruby-doc librmagick-ruby1.8

sudo apt-get install libmagick9-dev ruby1.8-dev

sudo gem install rmagick

require 'rubygems'
require 'RMagick'

img = Magick::Image.read(’logo.jpg’).first
width,height = 50,50
thumb = img.resize(width,height)
thumb.write(’my1.jpg’)

评论关闭
下一页 »