by agate - Published: 2008-06-19 [8:20 上午] - Category: 程序编码

ruby 对非西欧字符采用 utf8 编码,但是一个中文字符使用 String#length or String#size 就会得到 3 个字符的结果。是因为中文变成了 \xxx\xxx\xxx 的形式,就比如 "睡觉" -> "\347\235\241\350\247\211"。要是出现中英文混合的字符串统计字数就麻烦咯~这里给出一个简单的解决方安:使用 "jcode" 库

irb(main):001:0> str = "睡觉ing"
=> "\347\235\241\350\247\211ing"
irb(main):002:0> str.length
=> 9
irb(main):003:0> $KCODE='utf8'
=> "utf8"
irb(main):004:0> require 'jcode'
=> true
irb(main):005:0> str.jlength
=> 5
Tags: [ ] - Comments: Comments
by agate - Published: 2008-06-18 [5:31 下午] - Category: 程序编码

if you are using rails 2.0+. congratulations! your rails default db engine is sqlite3 and you don't need to do any other work. just type the command:
$rails {your app name}
if you are using rails 1.2.6 or older version. the sqlite3 is not the default db engine for the project. but you can use one command to create the sqlite3 base app.
$rails {your app name} -d sqlite3

ps. if you get the error when you runing the server. it maybe cause by the db engine. make sure you have install the sqlite3-ruby gem.
$sudo gem install sqlite3-ruby

Tags: [ , ] - Comments: Comments
by agate - Published: 2008-06-15 [11:00 下午] - Category: 系统操作

======== 启动流程 ========
Linux系统主要通过以下步骤启动:
1、读取MBR的信息,启动Boot Manager Windows使用NTLDR作为Boot Manager,如果您的系统中安装多个版本的Windows,您就需要在NTLDR中选择您要进入的系统。 Linux通常使用功能强大,配置灵活的GRUB作为Boot Manager,我们将在启动管理章节中向您介绍它的使用方式。
2、加载系统内核,启动init进程 init进程是Linux的根进程,所有的系统进程都是它的子进程。
3、init进程读取"/etc/inittab"文件中的信息,并进入预设的运行级别,按顺序运行该运行级别对应文件夹下的脚本。脚本通常以"start"参数启动,并指向一个系统中的程序。 通常情况下,"/etc/rcS.d/"目录下的启动脚本首先被执行,然后是"/etc/rcN.d/"目录。例如您设定的运行级别为3,那么它对应的启动目录为"/etc/rc3.d/"。
4、根据"/etc/rcS.d/"文件夹中对应的脚本启动Xwindow服务器"xorg" Xwindow为Linux下的图形用户界面系统。
5、启动登录管理器,等待用户登录 Ubuntu系统默认使用GDM作为登录管理器,您在登录管理器界面中输入用户名和密码后,便可以登录系统。(您可以在"/etc/rc3.d/"文件夹中找到一个名为"S13gdm"的链接)

======== 更改运行级别 ========
在"/etc/inittab"文件中找到如下内容: # The default runlevel. id:2:initdefault: 这一行中的数字2,为系统的运行级别,默认的运行级别涵义如下: 0 关机 1 单用户维护模式 2~5 多用户模式 6 重启
Read more...

Tags: [ , , ] - Comments: Comments
by agate - Published: 2008-06-15 [9:06 下午] - Category: 程序编码

power by ruby language:

require "net/http"

module SmallBlogSender
  def SmallBlogSender.send(username, password, web_server, message, param_name="status")
    url = URI.parse(web_server)
    req = Net::HTTP::Post.new(url.path)
    req.basic_auth username, password
    req.set_form_data({param_name => message}, ';')
    res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
    case res
    when Net::HTTPSuccess, Net::HTTPRedirection
      # OK
    else
      res.error!
    end
    return res
  end
  UPDATESERVERS = {
    "fanfou" => "http://api.fanfou.com/statuses/update.xml",
    "twitter" => "http://twitter.com/statuses/update.xml"
  }
end

puts "message:(less than 140 characters)"
message=gets
print "username: "
username=gets.delete("\n")
print "password: "
password=gets.delete("\n")
print "==== Now sending to Fanfou ===>"
response = SmallBlogSender.send(username, password, SmallBlogSender::UPDATESERVERS["fanfou"], message)
puts " OK." if response==Net::HTTPSuccess or Net::HTTPRedirection
print "==== Now sending to Twitter ===>"
response = SmallBlogSender.send(username, password, SmallBlogSender::UPDATESERVERS["twitter"], message)
puts " OK." if response==Net::HTTPSuccess or Net::HTTPRedirection

suggest to run on linux(unix or mac) bash!

Tags: [ , ] - Comments: Comments
by agate - Published: 2008-06-05 [8:46 上午] - Category: 软件使用

也许不是中国人吧~~~卡巴斯基在出现问题的时候总是问你一个似乎很智能的问题~允许?拒绝?

我纳闷了:
“允许”是允许卡巴斯基阻止下载,还是允许恶意文件执行?
“拒绝”是拒绝卡巴斯基阻止,还是拒绝恶意文件?

这个文字游戏烦了我好久啊~后面在查阅360网站的时候才知道,原来是要选择那个拒绝才会拒绝这个“恶意软件”或病毒什么的~(这里提醒一下,你安装软件的时候如果你确认这个软件的安全性那么他提示你就别管他,按那个允许就好了!)。

这里引用360上面的一句话:“ 是你在操作电脑,不是你被电脑操作。所谓允许的命令是指允许这个病毒程序进入电脑。同理拒绝的命令。”呵呵,是大家在操作电脑!

Tags: [ ] - Comments: Comments