Typo consumer too much memory
I monitor this application typo 5.0.2 consume too much memory about 50 – 80 MB which full feature. So i will try to make lite version for typo because I still like it. By the way, If my try is not successful, I will make my own blog system
มันกิน mem มากเหลือเกินไม่ไหว ถ้ามีโอกาศ จะลองทำแบบ lite ดู แต่ถ้าไม่ได้ลองเขียนใช้เองแล้ว ไม่ไหวเปลือง[…]
Speedthai Go to passenger 1.0.1
Now Speedthai Rails hosting in Thailand switch from Fcgid to Passenger (mod_rails) which consume less memory and better performance
ตอนนี้ Speedthai Rails Hosting ในประเทศไทยได้เปลี่ยนจาการใช้ fcgid ไปเป็น Passenger (mod_rails) ที่มีประสิทธิภาพดีกว่าและยังบริโภคแรมน้อยกว่า
อยู่ในขั้นทดสอบ[…]
Number to word in Thai
อยู่ในภาคทดสอบ แบ่งเป็น 2 แบบคืออ่านธรรมดากับแบบค่าเงิน
ทดสอบได้ที่ num2word
<typo:uvcode lang="ruby"> class Number
def initialize
@unit = %w[ศูนย์ หนึ่ง สอง สาม สี่ ห้า หก เจ็ด แปด เก้า]
@qtys = ["แสน", "หมื่น", "พัน", "ร้อย", "สิบ", "หน่วย"]
@mils = "ล้าน"
@zero = "ศูนย์"
@twenty = "ยี่"
@unitone = "เอ็ด"
end
def self.th_word(number)
Number.new.to_s(number)
end
def self.th_currency(number)
Number.new.to_s_currency(number)
end
def self.commify(number)
(s=number.to_s;x=s.length;s).rjust(x+(3-(x%3))).gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,')
end
def to_s(value)
if (number = value.to_s.split(".");number.length) >2 then return ("'.' more than 1") end
re = []
f = to_s_float(number[1]) if !number[1].nil?
out = to_s_decimal(number[0])
re[0] = f if !f.nil?
re[1] = out
if !f.nil? then re[2] = re[1] + "จุด" + re[0] else re[2] = re[1] end
return re.reverse
end
def to_s_currency(value)
w = to_s(value).reverse
f = value.to_s.gsub(/(\w*)+\./,"0.").to_f if !w[0].nil?
w[0] = to_s_decimal((f * 100.0).round.to_s) if !f.nil?
if !f.nil? then w[2] = w[1] + "จุด" + w[0] else w[2] = w[1] end
return w.reverse
end
def to_s_float(value)
return float_wordify(value).flatten.compact.join(' ').gsub(/ ,/,',')
end
def to_s_decimal(value)
return quantify(value).flatten.compact.join(' ').gsub(/ ,/,',')
end
private
def padded_groups(v)
#make number to be 3 units per slot by fill zero infront (x%3 =0)
out = []
padded = (s=v.to_s.gsub(/\D/i,"");x=s.length;s).rjust(x+(6-(x%6))).gsub(/ /,'0')
padded.scan(/.{6}/)
end
def wordify(v)
out = []
@unitone = "หนึ่ง" if v.to_i == 1
for cur in 0 .. v.length - 1
if cur ==4 and v[cur] == '2'[0]
out << @twenty
elsif cur ==4 and v[cur] == '1'[0]
out << ""
elsif cur ==5 and v[cur] == '1'[0]
out << @unitone
else
out << @unit[v[cur]-'0'[0]]
end
end
return out
end
def float_wordify(v)
out = []
for cur in 0 .. v.length - 1
out << @unit[v[cur]-'0'[0]]
end
out.pop while out.last == @zero
return out
end
def quantify(v)
v = padded_groups(v).reverse
pos = v.length - 1
out = []
while pos >= 0
if v[pos] == ','
out << ','
next
end
word = wordify(v[pos])
for po in 0 .. word.length - 1
if word[po] == @zero then next end
if @qtys[po] != "หน่วย" then out << word[po] + @qtys[po] else out << word[po] end
end
out <<@mils if pos > 0
pos -= 1
end
out.shift while out.first == @mils
out << @zero if out.length.zero?
return out
end
end </typo:uvcode>[...]
Number to word
Source จาก http://sohne.net/articles/2006/04/30/convert-numbers-to-words/ เท่าที่แกะดูก็ไม่ยากแต่ไม่เข้าใจว่า หลายที่เงื่อนไขไม่ลงเลย สงสัยทำเผื่อไว้
Source from http://sohne.net/articles/2006/04/30/convert-numbers-to-words/ I have some confuse with this code, some condition will not may happen but i still be.
มีที่ดีกว่านี้ที่ http://www.deveiate.org/projects/Linguistics/wiki/English
<typo:uvcode lang="ruby"> class Number
def self.to_words(number)
Number.new.to_s(number)
end
def self.commify(number)
(s=number.to_s;x=s.length;s).rjust(x+(3-(x%3))).gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,')
end
def initialize
@unit = %w[zero one two three four five six seven eight nine]
@teen = %w[ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen]
@tens = %w[zero ten twenty thirty fourty fifty sixty seventy eighty ninety]
@qtys = %w[hundred thousand million billion trillion quadrillion quintillion]
@zero = ["zero"]
@hundred = "hundred"
@sepr = "and"
end
def to_s(number)
out = quantify(number).flatten
for x in 0 .. out.length - 1
out[x] = nil if out[x] == @sepr && out[x+1] == @sepr
out[x] = nil if out[x] == "," && out[x+1] == ","
end
out.compact!
out = @zero if out.length == 1 && out[0] == @sepr
out.pop while out.last == @sepr
out.shift while out.first == @sepr
out.join(' ').gsub(/ ,/,',')
end
private
def padded_groups(v)
#make number to be 3 units per slot by fill zero infront (x%3 =0)
out = []
padded = (s=v.to_s;x=s.length;s).rjust(x+(3-(x%3))).gsub(/ /,'0')
padded.scan(/.{3}/)
end
def wordify(v)
#Get 3 unit of slot and compare by ascii code, then word it out
out = []
zero = '0'[0]
h, t, u = v[0] - zero, v[1] - zero, v[2] - zero
if h != 0
out << @unit[h]
out << @hundred
end
#"and" word will add when hundred appear and unit appear
out << @sepr if h != 0 && (t != 0 || u != 0)
out << @sepr if h == 0 && t == 0 && u != 0
if t == 1
out << @teen[u]
else
out << @tens[t] if t != 0
out << @unit[u] if u != 0
end
return out
end
def quantify(v)
#make ach 3 of each slot to be a word by calling wodify
v = padded_groups(v).reverse
cur = pos = v.length - 1
out = []
while pos >= 0
if v[pos] == ','
out << ','
next
end
word = wordify(v[pos])
if word[0] != nil
out << word
out << @qtys[cur] if cur != 0
else
out << @sepr
end
cur -= 1
pos -= 1
end
return out
end
end
puts Number.to_words(1234567890) puts Number.commify(1234567890) </typo:uvcode>
ถ้าอยากรู้ว่า code ทำงานอย่างไรอ่านต่อข้างใน[...]
Ruby.NET เลิกพัฒนา
เขียนลง Blognone
Ruby เป็นภาษาที่ได้รับความสนใจไม่น้อย จนกระทั่งมีคนอยากให้ใช้งานกับ .NET ได้ด้วย ทางด๊อกเตอร์เคลลี่ ผู้พัฒนา Ruby.NET ได้ประกาศผ่านทางกูเกิ้ลกรุ๊ปแล้วว่าเขาจะเลิกพัฒนา Ruby.NET โดยเหตุผลว่า IronRuby นั่นประสพความสำเร็จและไปได้ไกลกว่า
เนื่องจาก Ruby.NET เองแรกเริ่มก็เป็นโครงงานที่แตกตัวออกมาจาก IronRuby ซึ่งถ้าจะทำ Ruby.NET ให้เข้าได้กับ DLR (Dynamic Language Runtime) ต้องทำการเปลี่ยนแปลงหลายอย่าง และด๊อกเตอร์เคลลี่มั่นใจว่ามันจะดีกว่า CLR (Common Language Runtime) ที่ใช้อยู่ในปัจจุบัน
ทางผู้พัฒนา Ruby.NET ก็มีทีท่าจะไปช่วยพัฒนา IronRuby อยู่ด้วย
ที่มา: Google Group[…]
Typo 5.0.2
เปลี่ยนไปเยอะมาก ทั้ง front end และ back end มีการจัดวางเมนูได้ดีขึ้น ใช้ง่ายขึ้น สามารถ edit theme ได้บางส่วน ที่สำคัญยังเพิ่มระบบ multi user ด้วย ป.ล. ถ้าจะให้ดีทำ ระบบ plugin ให้ง่ายกว่านี้ก็ดีนะ อยากได้ revision เหมือน drupal จะได้เป็น Wiki ได้ด้วย[...]Typo is hebinated
Piers Cawley หนึ่งใน main developer ของ typo ออกมาพูดใน blog ตัวเอง
ถึงการหยุดนิ่งของ typo และยังมีการชมเชย Mephisto ที่มีการทำงานที่ดีกว่า typo ทำให้ developer ทำงานได้ง่ายด้วยการเขียน code ที่สะอาด
แต่ไม่นานมานี้ดูท่าจะมีการเปลี่ยนแปลงครั้งใหญ่กัน typo (และคงอีกหลายๆตัว) กับการมาของ rails 2.0 จะรอดีหรือจะ folk ดี หรือจะเขียนเองดีน้า….
อยากได้ plugin เหมือน jazzy ใน Mephisto ไปถาม punneng ดีกว่า[…]
Redgem Project for Rails Hosting
I’m a ruby programming hobbyist and doing rails hosting in Thailand especially ruby (and rails). Because in Thailand, there is nobody doing rails hosting. In fact, I fall in love with ruby as much as i written. One factor that make ruby grow up, there is a product that can release ruby and rails powers. So I decide to do Control panel for Rails hosting in ruby programming.
This project is base on vhcs2 concept with additional features. I draw some concept of control panel with freemind software
uninitialized constant Flickr::XmlSimple
I call this project name “REDGEM” and now I opening project to rubyforge.org and get approve alrady. It can be accessed to redgem project
For rough concept, I separate work into 2 path
- Web Control Panel – It is written by Ruby on Rails. This part is interacted with user.
- Engine – It is also written by Ruby. The engine has responsibility to edit file configuration and deployment
For Future design, UI it may not be a web, it can be other or other language
As you see this is not easy one to do, I need help. Anyone can help me please let me know.
Thank You
File: redgem concept
ภาษาไทยข้างใน[…]
Rails Log
พอดีมีปัญหาเกี่ยวกับ log ใน rails ซึ่งมันก็กินเนื้อที่เยอะพอดูเลยพยามหาวิธีปิดมัน แต่สุดท้ายก็รู้ว่ามันปิดไม่ได้ เพราะ log มันเอาไว้ดูความเคลื่อนไหว ก็เลยได้แต่พยามหาวิธีให้มันเก็บน้อยลง ไปเจอที่ wiki ของ rails สรุปได้ว่า
ActiveRecord จะไปเรียกใช้ class Logger เพื่อจะทำการเก็บ log ลงไฟล์
ใน development จะใช้ :debug
ใน production จะใช้ :info
ซึ่งทั้งหมดก็มี :debug, :info, :warn, :error, :fatal ซึ่ง log class ของ ruby ยังมี :any แต่ไม่ทำงานบน rails ถ้าอยากให้ log น้อยลง เอาเฉพาะที่มี error ก็ใช้ :error
ให้เพิ่ม
config.log_level = :error
ลงในไฟล์
config/environment.rb
หรือถ้าจะปรับแต่งใดๆ ดูได้ที่ wiki ของ rails ครับ[…]
build libgems-ruby เอง
พอดีจะลง notebook ใหม่เลยลอง build source ของ libgems-ruby มาดู โดยไปเอา source มาจาก feisty มา build บน edgy โดยมีลำดับ
//เปิด feisty ใน source
#apt-get source rubygems
//ปิด feisty ใน source
#apt-get build-dep rubygems
//เปิด feisty ใน source
#apt-get source —build rubygems
แต่ว่ามันจะมี ติด dependency นิดหน่อยดูได้จากที่ ubuntu package
พอ build เสร็จก็ได้มา 2 ไฟล์
libgems-ruby1.8_0.9.0-5_all.deb
ไม่รู้ว่าเวลา build ทำไงให้มี version แบบที่เขาทำกันไม่เท่เลย


