ITeye博客

sitoto的博客

sitoto · 共 93 篇文章

使用rails和mongoid删除MongoDB重复的项

手上有一个表,本来是不重复的,但是因为 field 没有明确指定为 String 还是Int,结果导致,存储的 c_num 有 123 和 "123" 这两条结果; 无奈之极,只好 将所有的 数字 变成了 字符串。 Car.where(:c_num.with_type => 16).each {|car| car.update_attribute(:c_num, car.c_num.to_s)} 再通过下面的语句删除掉重复的: db.cars.ensureIndex({c_num : 1, from_site : 1},{unique : true, dropDups : true})

2013-08-23 15:24 · 评论(0)

unescape编码错误

javascript 的 escape 中文 编码成 utf-8格式的 ruby 的 unescape 中文 解析为 gbk编码的,所以ruby无法解析javascript的escape 什么情况下ruby可以解析: 还是中文的问题,在?传递中文参数时请使用encodeURIComponent. document.write(encodeURIComponent(”中文”)); => %E4%B8%AD%E6%96%87 document.write(escape(”中文”)); => %u4E2D%u6587 Rails 能自动 decode 使用encodeURIComponent的编码…

2013-08-21 12:55 · ruby · 评论(0)

mysql2安装错误

administrator@ubuntu:~/store$ gem install mysql2 Fetching: mysql2-0.3.13.gem (100%) Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. /home/administrator/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb checking for rb…

2013-08-08 13:22 · mysql · ubuntu · 评论(0)

nokogiri安装错误处理

administrator@ubuntu:~/store$ gem source *** CURRENT SOURCES *** http://ruby.taobao.org administrator@ubuntu:~/store$ gem install nokogiri Building native extensions. This could take a while... Successfully installed nokogiri-1.6.0 1 gem installed Installing ri documentation for nokogiri-1.6.0... I…

2013-08-08 13:14 · nokogiri · 评论(0)

ruby-nokogiri -xpath 用法说明

//div/table/tr/td/a/@href 上面那段代码的意思说清楚,基本上可以用xpath 解析html了。 xpath() at_xpath() 做个记录先 参考资料:http://stackoverflow.com/questions/2683298/xpath-matching-attribute-and-content-of-an-element 193737895群,可交流。

2012-08-01 14:14 · ruby · 评论(0)

看哪个目录占的空间比较大

看哪个目录占的空间比较大 能排序不? 闪的快呀 这 看毛啊。。。 或者只显示 统计结果吧 du -sh * | sort -hk1 如果没有h的话就两边都去掉h du -s * | sort -k1

2012-07-27 17:09 · 评论(0)

ssh 显示中文

设置FB的字集字集 utf-8 setenv LANG zh_CN.UTF-8 PUTTY设置里 Window->Appearance : 字体选择宋体 Window->Translation : 字符集选择 UTF-8.

2012-07-26 16:07 · 评论(0)

apt-key是Debian软件包的安全管理工具

apt-key是Debian软件包的安全管理工具。每个发布的deb包,都是通过密钥认证的,apt-key用来管理密钥。 1> apt-key list 列出已保存在系统中key。 Example: chao@gardenia:/etc/apt$ sudo apt-key list password for chao: /etc/apt/trusted.gpg pub 1024D/437D05B5 2004-09-12 uid Ubuntu Archive Automatic Signing Key ftpmaster@ubuntu.com sub 2048g/79164387 2004-09…

2012-07-18 16:34 · 评论(0)

ruby-(%Q-%q-%W-%w-%r-%s-%x)说明

%Q This is an alternative for double-quoted strings, when you have more quote characters in a string.Instead of putting backslashes in front of them, you can easily write: >> %Q(Joe said: "Frank said: "#{what_frank_said}"") => "Joe said: "Frank said: "Hello!""" The parenthesis “(…)” can be replaced…

2012-07-17 09:27 · ruby · 评论(0)

windows7的telnet

笔者有一次需要telnet到客户的刀片光纤交换机模块上进行配置,但是当我打开windows7自带的CMD输入telnet命令之后,系统却提示我“不是内部或外部命令也不是可运行的程序或批处理”。 我的第一感觉是CMD功能失效了,于是又尝试了ping的命令,奇怪的是ping功能可以正常使用。这时候我想到了可能是在windows7上telnet这个功能没有被开启。 于是打开“控制面板”,找到程序和功能,然后点击左上方的“打开或关闭windows功能”,会弹出windows功能的对话框,这个对话框里面有许多windows的小功能,再找到Telent Client,打上勾,确认即可!

2012-07-14 10:24 · 评论(0)

gem install mysql sqlite3-ruby nokogiri 错误

$ gem install mysql2 Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. =============8<==ubuntu 错误解决办法========== sudo apt-get install libmysql-ruby libmysqlclient-dev =< *** #gem install nokigiri ERROR: While executing…

2012-07-13 21:22 · 评论(0)

Capistrano deploy ** Host key verification failed

Known Hosts bug If you are not using agent forwarding, the first time you deploy may fail due to Capistrano not prompting with this message: The authenticity of host 'github.com (207.97.227.239)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you s…

2012-07-13 20:44 · ubuntu · 评论(0)

It seems the user clicked on the 'Stop' button in his browser.

Reported by pierre.b...@gmail.com, Sep 8, 2009 What steps will reproduce the problem? Nginx 6.71 Passenger 2.2.4 Random page show a 502 Gateway errors with this message : Couldn't forward the HTTP response back to the HTTP client: It seems the user clicked on the 'Stop' button in his browser. : Cou…

2012-07-12 08:37 · nginx · 评论(0)

git - remote add origin 的使用

Global setup: Set up git git config --global user.name "Your Name" git config --global user.email huang.gadela@gmail.com Next steps: mkdir test cd test git init touch README git add README git commit -m 'first commit' git remote add origin https://github.com/sitoto/test.git git push -u origin maste…

2012-07-02 12:57 · 评论(0)

ruby 中puts和print和p,pp

共同点:都是用来屏幕输出的。 不同点: puts 输出内容后,会自动换行(如果内容参数为空,则仅输出一个换行符号);另外如果内容参数中有转义符,输出时将先处理转义再输出,puts传递的参数不知一个,可以有多个参数() puts 将puts("this is ge num=",a,"this is b=",b) 用逗号隔开的当做几个字符串来处理 而print 把print("this is ge num=",a,"this is b=",b)当作一个字符串来处理; print基本与puts相同,但不会处理参数中的转义符号 print 基本与puts相同,但输出内容后,不会自动在结尾加上换行符 …

2012-06-16 18:23 · ruby · 评论(0)