2007年6月20日星期三

如何阻止Google Analytics生成的Cookies?

Google Analytics会自动生成一些Cookies,类似:

__utma=22912040.2101146157.1178589316.1181115988.1181178175.14; __utmz=22912040.1178589316.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmb=22912040; __utmc=22912040

这些信息是由下面的这个JS文件生成的:
https://ssl.google-analytics.com/urchin.js

只要将域google-analytics.com屏蔽掉即可阻止这些Cookies的生成。
方法是:使用FireFox的NoScript插件。

2007年5月30日星期三

在BlogSpot中使用dp.SyntaxHighlighter

1、将dp.SyntaxHighlighter加入到blogspot.com
  • 将展开后的dp.SyntaxHighlighter代码上传到googlepages.com或其他可访问的地方
  • 修改网页模板,将dp.SyntaxHighlighter的风格单及JavaScript加入
  • 将“转换断行”设为“否”(“修改设置”-〉“格式设定”-〉“转换断行”) 。但是这将影响已发布blog的格式,请慎重使用。
2、使用方法参考dp.SyntaxHighlighter的说明
3、替代方案: 使用Google code prettify
下面是对dp.SyntaxHighlighter的一个测试:
# {tagname} {tagfile} {tagaddress}[;" {tagfield}..]
# "A tagfield has a name, a colon, and a value: "name:value".
# The name of the "kind:" field can be omitted.  A program reading the
# tags file can recognize the "kind:" field by the missing ':'.
  
class Parser
  @@parsers = []

  def get_type()
    return ""
  end
  
  def parse( xml )
   @var = nil
    return nil
  end

  def Parser.add_parser( :symlink )
    @@parsers.push( p )
  end
  def Parser.parsers()
    return @@parsers
  end
end

class RSSParser < Parser
  def get_type()
    return "RSS"
  end
  
  def parse( xml )
    # Parse the XML up and return some known format
    return nil
  end
end

Parser.add_parser( RSSParser )

class RDFParser < Parser
  def get_type()
    return "RDF"
  end
  
  def parse( xml )
    # Parse the XML up and return some known format
    return nil
  end
end

Parser.add_parser( RDFParser )

2007年5月15日星期二

svn--版本化scaffold_resource生成文件的批处理脚本

scaffold_resource生成的文件有许多,在执行./script/generate scaffold_resource命令时添加选项“-c”可同时将这些文件添加到svn中。然则“-c”选项总是忘记输入,这时,你可以执行. /script/destroy scaffold_resource然后重新generate,但假如你已经对生成的文件作了一些修改或者许多修改,你就不愿或不能重新generate 了。下面的这段脚本可以帮助你走出这个困境:
ruby 代码

#!/usr/bin/env ruby

require 'rubygems'
require 'active_support/inflector'

@cmd = 'add'      # add, del, etc. run "svn help" for more.

# show usage
def usage
puts "Usage: #{$0} "
puts "    -- svn #{@cmd} scaffold_resource files."
end

model = $*.shift
if model
model_singular_name = Inflector.singularize(model)
model_plural_name = Inflector.pluralize(model)

puts "model is [" + model_singular_name + "]"

filebase = File.dirname(__FILE__)
puts "filebase: " + filebase

files = ["app/views/#{model_plural_name}",
         "app/views/layouts/#{model_plural_name}.rhtml",
         "app/models/#{model_singular_name}.rb",
         "app/controllers/#{model_plural_name}_controller.rb",
         "test/functional/#{model_plural_name}_controller_test.rb",
         "app/helpers/#{model_plural_name}_helper.rb",
         "test/unit/#{model_singular_name}_test.rb",
         "test/fixtures/#{model_plural_name}.yml"
         ]

Dir["db/migrate/*create_#{model_plural_name}.{rb}"].each do |x|
#    puts x
  files <<>  
将上述代码保存到当前项目的根目录,文件名可取为svn-add.rb。然后执行 chmod +x svn-add.rb

一个ExtJs的Rails Plugin

本文介绍一个专门集成ExtJs到Rails的Plugin。ExtJs库是一个实用的一流Javascript库,相信许多人在看到它之后会爱不释手。对于Rails爱好者,则希望了解如何在Rails下使用它。下面介绍其使用: 该plugin功能概要:
  • Easy to include ext files
  • Pagination
  • Scaffold
  • Tree (Not implemented yet)
  • and so on (Not implemented yet)
1、安装 1)安装ext plugin:
cd vendor/plugins
svn co http://wota.jp/svn/rails/plugins/trunk/ext/
2)安装依赖的plugins:
ruby script/plugin install http://wota.jp/svn/rails/plugins/branches/stable/dsl_accessor/
ruby script/plugin install http://wota.jp/svn/rails/plugins/branches/stable/named_options/
3)安装extjs库 此处下载最新版的ExtJs,有三个adapter: jquery, prototype, yui wget http://extjs.com/deploy/ext-1.0.1a.zip unzip ext-1.0.1a.zip cd public ln -s ../ext-1.0.1a ext 基于Windows的用户可将ext-1.0.1a.zip直接展开到public目录,然后将目录ext-1.0.1a更名为ext。 2、修改ExtJs Plugin 该plugin是基于ext-1.0-alpha3而作的,稍加修改即可支持最新版ext-1.0.1a。 打开文件vendor/plugins/ext/lib/ext/helper.rb,将ext_include方法修改为:
ruby 代码
  1. def ext_include
  2. array = []
  3. array << class="string">"#{ext_top}resources/css/ext-all")
  4. array << class="string">"#{ext_top}adapter/yui/yui-utilities")
  5. array << class="string">"#{ext_top}adapter/yui/ext-yui-adapter")
  6. if RAILS_ENV == 'development'
  7. array << class="string">"#{ext_top}ext-all-debug")
  8. else
  9. array << class="string">"#{ext_top}ext-all")
  10. end
  11. array <<>
  12. array <<>
  13. array.join("\n")
  14. end
你也可以将adapter修改为jquery或prototype。查看public/ext/adapter/jquery或prototype目录下有哪些文件,参考上面的方法替换即可。 3、试用: 1) Migration:
ruby 代码
  1. create_table :tomcats do |t|
  2. t.column :kname, :string
  3. t.column :memo, :text
  4. end
2) 在Controller中添加 ext_paginate,不要含有其他方法。
ruby 代码
  1. class TomcatsController <>
  2. ext_paginate Tomcat, 20,
  3. :cm => Ext::Grid::ColumnModel.new([
  4. {:dataIndex => "id" , :width => 100, :header => "Thread ID"},
  5. {:dataIndex => "kname" , :width => 200, :header => "Title"},
  6. {:dataIndex => "memo" , :width => 400, :header => "Description"},
  7. ])
  8. end
3) 如果routes.rb文件中有map.resources :tomcats,则注释掉。 4) 重新启动script/server,浏览http://localhost:3000/tomcats 参考:

质疑JavaEye的野蛮删贴行为

来自javaeye.com的声音: 1个小时前,本人发的一个题为“Railscasts--免费的Rails视频教学”的帖子不见了踪影,这是为什么?本人发这个帖子的初衷是为了分享自己 的发现,促进国内Rails爱好者学习与使用Rails,没想到会被删贴,而且在自己的blog中也不见了踪影,这究竟是怎么回事???希望能得到一些解 释,也希望这个帖子不被野蛮删除!!! 建议: 删贴时不要彻底删除,去掉论坛里的链接即可,保留blog中的内容,保留blogger的劳动果实。 另外:给javaeye.com添加一个删贴通知功能应该不难吧,告知发贴人删贴原因。

2007年5月11日星期五

Fix theme_support in rails1.2.x

theme_support当前版本1.3.0不支持Rails1.2.x,需要修理一下方
可使用。

1、错误现象的产生:
执行下述命令:
./script/generate theme default
将安装theme_support到vender/plugins,且创建themes目录后生成
default theme。
再次生成另一个theme,比如:another
./script/generate theme another
将产生下述错误:
./script/../config/../vendor/plugins/theme_support/lib/
patches/routeset_ex.rb:26:in `create_theme_routes':
undefined method `named_route' for # (NoMethodError)

2、解决方法:
1)修改
vendor/plugins/theme_support/lib/patches/routeset_ex.rb
文件,将draw方法替换为下述内容:
  def draw
  clear!
  create_theme_routes
  yield Mapper.new(self)
  named_routes.install
end
在create_theme_routes方法中,
————替换named_route为add_named_route;
————替换connect为add_route。

也可以在这里下载修改好的theme_support包。

2)修改
vendor/plugins/theme_support/lib/patches/actioncontroller_ex.rb
文件,添加下述内容:
alias_method :__assert_existence_of_template_file, :assert_existence_of_template_file
def assert_existence_of_template_file(template_name)
  unless template_exists?(File.join( "../../themes/#{current_theme}", template_name))
    __assert_existence_of_template_file(template_name)
  end
end
上述方法在Rails1.2.3下测试通过。 参考: http://www.ruby-forum.com/topic/100163 http://www.mattmccray.com/pivot/archive.php?c=Theme_Support http://imaspy.com/news/read/5

2007年5月1日星期二

Ubuntu 7.04 (Feisty Fawn) on VMware

4月19日,ubuntu7.0.4正式发行了。如果你不打算自己从头安装,准备在虚拟机VMware下运行ubuntu server 7.0.4,可以选择下载现成的VMware applicance(见下文描述)。如果你喜欢GUI,也可以在此基础上安装GUI。 0、前提条件: 安装了vmware的播放工具,可选下述任一款: 本人使用的是VMware Server版。 1、下载 Ubuntu Server 7.04 (Feisty Fawn) ubuntu-server-7.04-i386.zip, 189M (点击此处) 如果尚未有下载torrent格式文件的工具,则可下载uTorrent (free!) 2、配置与使用: 用户名: notroot 口令: thoughtpolice 注: 尚未安装 VMware Tools 2.1 改变控制台语言: 编辑 /home/notroot/.bash_profile 加入 export LANG=de (example given for German) 注: 不必执行这一步,写下这一步只为完整性。
2.2 变更控制台键盘布局:
sudo dpkg-reconfigure console-setup
2.3 更新软件
sudo aptitude update # refresh apt's cache sudo aptitude upgrade # run the upgrade
2.4 安装新软件
sudo aptitude update # refresh apt's cache aptitude search pkgnames # lists all available software containing aptitude search pkgnames | grep -i WORD # lists all software containing WORD sudo aptitude install PACKAGE # installs PACKAGE (found from list above)
2.5 GUI在那里?
这个版本是server版,没有安装GUI。如果需要,可执行: sudo aptitude install xorg gnome
2.6 文档与指导:
Feisty Fawn wiki page
3、使用putty客户端连接到ubuntu server 7.0.4 安装sshd: sudo apt-get install openssh-server 使用ifconfig查看IP地址,假定IP地址为: 192.168.0.100 下载putty: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html 运行putty.exe,输入上面的IP地址,回车后将出现登陆界面。输入用户名口令即可。 新版ubuntu的一个特棒功能: 当系统发现运行的命令不存在时,将提示安装命令。这样解决了以往版本下包名记不准的苦恼。比如: notroot@ubuntu:~$ emacs The program 'emacs' can be found in the following packages: * emacs21 * emacs-snapshot * e3 * emacs-snapshot-nox * emacs21-nox * jove * emacs-snapshot-gtk Try: sudo apt-get install Make sure you have the 'universe' component enabled -bash: emacs: command not found notroot@ubuntu:~$ 然后你可以选择安装emacs-snapshot-gtk,即: sudo apt-get install emacs-snapshot-gtk 参考: http://www.thoughtpolice.co.uk/vmware/#ubuntu7.04