下午三點出發,經內灣、尖石,過宇老後左轉玉峰道路,在玉峰道路這一段,滿怕被落 石砸到的,走到底向右迴轉,往巴陵方向前進,之後時速大約30~60公里,一路很小心的衝,走到底,台七甲左轉,這段就放心的一路時速60公里,到泰雅大 橋右轉,接上台七丙後左轉,一直走到羅東,慢慢路過羅東夜市後上北宜高速公路,接下來就一路70~80公里,到南港接上國道三號往芎林,晚上九點到家。這 一趟三百多公里。 開車碰到的狀況:

  1. 在北橫時,大客車不會自動讓路,討厭!
  2. 雪山隧道裡,開70會當領隊,寬容值到80,那就不客氣啦!
  3. 那些時速90、100的車,你們「停」在內側車道做什麼啊!中、外側車道那麼空曠,快滾出去吧!一直害人違背良心從外側超車很討厭耶!

路徑圖:


Forth 發表在 痞客邦 留言(0) 人氣()

設計網頁的時候,配色總是好痛苦,以後可以用Adobe的kuler偷個懶了。


Forth 發表在 痞客邦 留言(0) 人氣()


Forth 發表在 痞客邦 留言(0) 人氣()

require 'uuid'

module ActiveRecord
  module UseUuid #:nodoc:

    def self.append_features(base)
      super
      base.extend(ClassMethods)
    end

    module ClassMethods
      def use_uuid(options = {})
        class_eval do
          set_primary_key options[:column] if options[:column]

          def after_initialize
            self.id ||= UUID.getUUID
          end
        end
      end
    end
  end
end

ActiveRecord::Base.class_eval do
  include ActiveRecord::UseUuid
end

Forth 發表在 痞客邦 留言(0) 人氣()

# Using the algorithm from Hibernate to generate UUID

require 'socket'
require 'thread'

class UUID
  @@instance = nil
  @@mutex = Mutex.new

  def initialize
    @IP = 0
    ipStr = IPSocket.getaddress(Socket.gethostname)
    ipStr.split('.').collect {|a| a.to_i}.pack('C*').each_byte {|a| @IP = (@IP << 8) - 128 + a}
    @counter = -1
    @JVM = (currentTimeMillis >> 8) & 0xffffffff
  end

  def currentTimeMillis
    (Time.new.to_f * 1000).to_i
  end

  def getJVM
    @JVM
  end

  def getCount
    @@mutex.synchronize do
      @counter = (@counter + 1) % 32768
    end
  end

  def getIP
    @IP
  end

  def getHiTime
    currentTimeMillis >> 32
  end

  def getLoTime
    currentTimeMillis & 0xffffffff
  end

  def generate
    sprintf(’%08x-%08x-%04x-%08x-%04x’, getIP, getJVM, getHiTime, getLoTime, getCount)
  end

  def UUID.getInstance
    @@mutex.synchronize do
      @@instance = new unless @@instance
    end
    @@instance
  end

  def UUID.getUUID
    getInstance.generate
  end
end

Forth 發表在 痞客邦 留言(0) 人氣()

#!/usr/local/bin/ruby
require "dbi"

require "parsedate"

db_plog_dsn = "dbi:Mysql:plogdb:localhost"
db_wp_dsn = "dbi:Mysql:wptest:localhost"
db_username = ARGV[0]
db_password = ARGV[1]

Category = Struct.new(:id, :name, :description)
Post = Struct.new(:id, :category, :title, :content, :createDateTime, :modifyDateTime, :status)

wp_cats = Hash.new(nil)
wp_posts = Hash.new(nil)
plog_cats = Hash.new(nil)
plog_posts = Hash.new(nil)

wp_conn = DBI.connect(db_wp_dsn, db_username, db_password)
plog_conn = DBI.connect(db_plog_dsn, db_username, db_password)

# initialize wp_cats
wp_conn.select_all("SELECT * FROM wp_categories") do |row|
  wp_cats[row["cat_name"]] = Category.new(row["cat_ID"], row["cat_name"], row["category_description"])
end

# initialize plog_cats
plog_conn.select_all("SELECT * FROM plog_articles_categories") do |row|
  plog_cats[row["name"]] = Category.new(row["id"], row["name"], row["description"])
end

# initialize wp_posts
wp_conn.select_all("SELECT wp_posts.ID id, wp_categories.cat_name catetory, wp_posts.post_date create_date_time, wp_posts.post_modified modify_date_time, wp_posts.post_title title, wp_posts.post_content content, wp_posts.post_status status FROM wp_post2cat JOIN wp_categories ON wp_post2cat.category_id=wp_categories.cat_ID JOIN wp_posts ON wp_post2cat.post_id=wp_posts.ID") do |row|
  wp_posts[row["title"]] = Post.new(
    row["id"], row["category"], row["title"],
    row["content"], row["create_date_time"],
    row["modify_date_time"], row["status"])
end

# initialize plog_posts
plog_conn.select_all("SELECT plog_articles.id id, plog_articles_categories.name category, plog_articles.`date` create_date_time, plog_articles.modification_date modify_date_time, plog_articles_text.normalized_topic title, plog_articles_text.`text` content, plog_articles.status status FROM plog_article_categories_link JOIN plog_articles_categories ON plog_article_categories_link.category_id=plog_articles_categories.id JOIN plog_articles ON plog_article_categories_link.article_id=plog_articles.id JOIN plog_articles_text ON plog_article_categories_link.article_id=plog_articles_text.article_id") do |row|
  plog_posts[row["title"]] = Post.new(
    row["id"], row["category"], row["title"],
    row["content"].gsub(/\[@more@\]/, ''),
    row["create_date_time"],
    row["modify_date_time"], row["status"])
end

# create category
plog_cats.each_key do |key|
  if false == wp_cats.has_key?(key)
    puts "Create category \"#{key}\""

    plog_cat = plog_cats[key]
    wp_conn.prepare("INSERT INTO wp_categories (cat_name, category_nicename, category_description) VALUES (?, ?, ?)") do |pstmt|
      pstmt.execute(plog_cat.name, plog_cat.name, plog_cat.description)
    end
    # put created category into hash
    id = wp_conn.select_one("SELECT last_insert_id()")
    wp_cat = Category.new(id, plog_cat.name, plog_cat.description)
    wp_cats[wp_cat.name] = wp_cat
  end
end

# create post
(plog_posts.keys - wp_posts.keys).each do |post_title|
  plog_post = plog_posts[post_title]
  puts "Import #{plog_post.title}"
  createGmtDateTime = Time.local(*ParseDate.parsedate(plog_post.createDateTime)).gmtime.strftime("%Y-%m-%d %H:%M:%S")
  modifyDateTime = plog_post.modifyDateTime
  if modifyDateTime == "0000-00-00 00:00:00"
    modifyDateTime = plog_post.createDateTime
  end
  modifyGmtDateTime = plog_post.modifyDateTime
  if modifyGmtDateTime == "0000-00-00 00:00:00"

    modifyGmtDateTime = createGmtDateTime 
  else
    modifyGmtDateTime = Time.local(*ParseDate.parsedate(modifyGmtDateTime)).gmtime.strftime("%Y-%m-%d %H:%M:%S")
  end
  status = plog_post.status
  if status  == 1
    status = "publish"
  else
    status = "draft"
  end
  wp_conn.prepare("INSERT INTO wp_posts (post_author, post_date, post_date_gmt, post_content, post_title, post_status, post_modified, post_modified_gmt) VALUES (?, ?, ?, ?, ?, ?, ?, ?)") do |pstmt|
    pstmt.execute(1, plog_post.createDateTime, createGmtDateTime, plog_post.content, plog_post.title, status, modifyDateTime, modifyGmtDateTime)
  end
  post_id = wp_conn.select_one("SELECT last_insert_id()")
  wp_conn.prepare("INSERT INTO wp_post2cat (post_id, category_id) VALUES (?, ?)") do |pstmt|
    pstmt.execute(post_id, wp_cats[plog_post.category].id)
  end
end

wp_conn.disconnect
plog_conn.disconnect

Forth 發表在 痞客邦 留言(0) 人氣()

BACKUP LOG <資料庫> WITH TRUNCATE_ONLY
DBCC SHRINKDATABASE(<資料庫>)

Forth 發表在 痞客邦 留言(0) 人氣()

--完整備份(append)--
BACKUP DATABASE "db" TO DISK='db.bak' WITH NAME='Full Database Backup', NOFORMAT, NOINIT, SKIP, NOREWIND, NOUNLOAD, STATS=10

--差異備份(append)--
BACKUP DATABASE "db" TO DISK='db.bak' WITH NAME='Differential Database Backup', DIFFERENTIAL, NOFORMAT, NOINIT, SKIP, NOREWIND, NOUNLOAD, STATS=10

--列出backup set--
RESTORE HEADERONLY FROM DISK='db.bak'
使用欄位:Position

--列出第一個backup set的檔名--
RESTORE FILELISTONLY FROM DISK='db.bak'
使用欄位:LogicalName、PhysicalName、Type,Type可能是D或L

--還原至另一個資料庫--
RESTORE DATABASE "db" FROM DISK='db.bak' WITH FILE=1, MOVE 'orig_LogicalName' TO 'db.mdf', MOVE 'orig_LogicalName_log' TO 'db_log.LDF', NORECOVERY, NOUNLOAD, STATS=10
RESTORE DATABASE "db" FROM DISK='db.bak' WITH FILE=2, MOVE 'orig_LogicalName' TO 'db.mdf', MOVE 'orig_LogicalName_log' TO 'db_log.LDF', NOUNLOAD, STATS=10
還原時,除了最後一個backup set,都要NORECOVERY參數

Forth 發表在 痞客邦 留言(0) 人氣()

Mongrel Cluster是一支小程式,用來簡化運行多個Mongrel時的設定、啟動及停止。安裝Mongrel Cluster:

gem install mongrel_cluster -y

因為我有數支rails程式,所以把Mongrel Cluster設定檔集中管理,儲存在/home/forth/etc/mongrel目錄中,另外,寫了一支小程式偷懶,不用每次都敲那麼長的命令,只要定義rails程式的名字、起始連接埠、行程數、目錄:

site :myapp, 8000, 4, '/home/www/myapp'

再執行簡單的命令就能控制rails程式:

railsd config_cluster # 產生設定檔供Mongrel Cluster使用
railsd start_cluster # 透過Mongrel Cluster啟動rails程式
railsd stop_cluster # 停止rails程式

Mongrel Cluster提供了一支開機啟動程式:

/usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.0/resources/mongrel_cluster

把它複製到/usr/local/etc/rc.d目錄,再修改內容,將CONF_DIR設成/home/forth/etc/mongrel,之後就會在開機時啟動所有rails程式。 偷懶小程式railsd:

Forth 發表在 痞客邦 留言(0) 人氣()


Forth 發表在 痞客邦 留言(0) 人氣()

自1996年起,PostgreSQL一直是我偏好使用的資料庫系統,也持續的幫忙訊息中譯。今天,我把所有的資料庫都轉移到MySQL,只因為需要partitioning和replication。這兩項功能在PostgreSQL設定繁瑣,在MySQL則平易近人;另外,以前需要的UTF-8支援和transaction等也已在MySQL出現,所以決定轉移資料庫系統。 以後不能騙人沒碰過MySQL了。

Forth 發表在 痞客邦 留言(0) 人氣()

  • Oct 29 Sun 2006 20:11
  • COSCUP

今天聽了:

 

  • OV+WebKit – gugod
  • 客語輸入法 – Arne
  • win32 libchewing使用者詞庫處理 – seamxr
  • 中文未知詞偵測淺釋 – 葉秉哲
  • ELUTE中文工具組 (斷詞,簡繁轉換,音詞轉換) – b6s
  • suffix抽詞程式 – clsung
  • Web 2.0 和 AJAX 簡介 – othree
  • Mashup with python – tcc
  • CakePHP – darkhero
  • Ruby on Rails – thegiive
  • ZK, Ajax web framework with java – Henri Chen

Forth 發表在 痞客邦 留言(0) 人氣()

10月21日,傳統藝術中心,午餐龍之園餐廳。

10月22日,桃山瀑布,4.3公里,上山1小時10分鐘,下山40分鐘。


Forth 發表在 痞客邦 留言(0) 人氣()

安裝Ruby-GetText-Package

gem install gettext

設定: 建立lib/tasks/gettext.rake:

desc "Update pot/po files." 
task :updatepo do
  require 'gettext/utils'
# Windows需要下一行
#  ENV["MSGMERGE_PATH"] = 'rmsgmerge.cmd'
  GetText.update_pofiles("myapp", Dir.glob("{app,lib,bin}/**/*.{rb,rhtml}"), "myapp 1.0.0")
end

desc "Create mo-files." 
task :makemo do
  require 'gettext/utils'
  GetText.create_mofiles(true, "po", "locale")
end

在config/environment.rb加入:

$KCODE = 'u'
require 'jcode'
require 'gettext/rails'

在app/controller/application.rb加入init_gettext:

class ApplicationController < ActionController::Base
  init_gettext "myapp" 
end

執行

Forth 發表在 痞客邦 留言(0) 人氣()

ActiveRecord的欄位驗證訊息是英文,要改成其它語言,可以覆寫ActiveRecord:: Errors.default_error_messages定義的訊息,如此,就不需要在每個用到validates_*_of的地方加上: message參數。直接在environment.rb加入:

ActiveRecord::Errors.default_error_messages = {
  :inclusion => "不是選項之一",
  :exclusion => "已被保留",
  :invalid => "是無效的",
  :confirmation => "與確認值不符",
  :accepted  => "必需被接受",
  :empty => "不能是空的",
  :blank => "不能是空白",
  :too_long => "太長(最多%d個字)",
  :too_short => "太短(至少%d個字)",
  :wrong_length => "長度不對(必須%d個字)",
  :taken => "已被使用",
  :not_a_number => "不是數字" 
}

Forth 發表在 痞客邦 留言(0) 人氣()