Showing posts with label Ruby. Show all posts
Showing posts with label Ruby. Show all posts

Tuesday, December 18, 2007

Update Rails แล้วเจอ OpenURI::HTTPError


วันนี้ลองทำการ update Rails ให้เป็น 2.0.2 (เพิ่งออกเมื่อวานนี้ครับ .. เป็น Bugfix จาก 2.0.1) เนื่องจากว่ายังไม่ได้ลองเขียนอะไรจริงๆ จังๆ ก็เลยทำการอัพเดทให้เป็นรุ่นล่าสุดไว้ก่อน เผื่อว่ามันมีอะไรใหม่ๆ เราจะได้ใช้ feature ใหม่ๆ มันซะเลย


แต่แล้วเจ้ากรรม หลังจากรัน gem update -y แล้วมันดันเกิดปัญหาขึ้นนี่ ..

Updating installed gems...
Bulk updating Gem source index for: http://gems.rubyforge.org
Attempting remote update of actionmailer
ERROR:  While executing gem ... (OpenURI::HTTPError)
    404 Not Found

ลองทำใหม่อยู่สามสี่รอบ ก็เริ่มมึนๆ ว่ามันเกิดอะไรขึ้น ก็เลยลองค้นหาใน Google ดู พบว่ามีคนมีปัญหาคล้ายๆ กัน โดยเขาเสนอวิธีแก้โดยการทำการ update RubyGems ก่อน ให้เป็นรุ่น 0.9.5 (ที่ติดมากับ Leopard จะเป็น 0.9.4 ครับ) โดยการใช้คำสั่ง

gem update --system

หลังจากนั้นพอใช้คำสั่ง gem update -y ก็ไม่มีปัญหาแล้วครับ อัพเดทเรียบร้อย :)

ปล. เห็นแว๊บๆ ตอนอัพเดทว่ามันใส่ flag -y (include dependencies) ให้เรียบร้อยแล้ว .. แปลว่าต่อไปรันแค่ gem update ก็พอแล้ว :)

Friday, June 15, 2007

โค้ดแก้ไข C Bundle ใน Textmate

ตอนนี้ต้องใช้ Textmate ในการเรียน C++ Programming
แต่มีปัญหาว่า Textmate เจ้ากรรมนั้น ไม่สามารถที่จะ Compile และ Run ไฟล์เดียวโดดๆ ได้
เพราะว่าเวลามันจะ Build มันจะต้องสร้างโปรเจค X Code ก่อน

สองวันมานี้ ก็เลยลองแก้ Bundle ดูเรื่อยๆ
ใช้ร่วมกันระหว่าง Ruby กับ AppleScript
แล้วก็ เปิด Google จนตาลายเลย ..

จนได้ออกมา อย่างนี้ !

Compile Single File to Tool

#!/usr/bin/env ruby
#
# Compile the active file to an executable.
# Executable name is prefixed with "Test".

require 'English'

FilePath = ENV['TM_FILEPATH']
FileDir = ENV['TM_DIRECTORY']
FileBaseName = File.basename(FilePath)
FileExtension = File.extname(FilePath)
FileNoExtension = FileBaseName.sub(/#{FileExtension}$/, "")

Dir.chdir(ENV['TM_DIRECTORY'])

# have to use g++ to bring in C++ runtime libraries
cc = case FileExtension
when /\.c(pp?|xx|\+\+)/,'.C','.ii'
'g++'
else
'gcc'
end

puts "<pre>"
%x{ "#{cc}" -g -Wmost -Os -o "#{FileNoExtension}" "$TM_FILEPATH"}
puts "</pre>"


puts "<font color='#499914'>Successfully created #{FileNoExtension}</font>" unless $CHILD_STATUS != 0

(อาจจะแก้ไขอีกนิด เพราะอยากให้มันแสดงหน้าจอ Build สวยๆ หน่อย)

Run Single File in Terminal Window
#!/usr/bin/env ruby
#
# Compile the active file to an executable.
# Executable name is prefixed with "Test".

require 'English'

FilePath = ENV['TM_FILEPATH']
FileDir = ENV['TM_DIRECTORY']
FileBaseName = File.basename(FilePath)
FileExtension = File.extname(FilePath)
FileNoExtension = FileBaseName.sub(/#{FileExtension}$/, "")

puts %x{ osascript <<EOF
tell application "Terminal"
activate
do script "cd '#{FileDir}'; clear; echo 'Running #{FileNoExtension} ...'; echo ; ./#{FileNoExtension} ; echo ; read -p 'Please return to exit ..'; exit"
end tell
EOF }


ดูๆ แล่้วก็เวิร์คดีเหมือนกันแฮะ