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
เปลี่ยน theme
ไหนๆก็ update เป็น typo 5.0.2 แล้วก็เลยลองเปลี่ยน theme เพราะ theme เห่ามีปัญหาไม่ยอมเว้น space กับภาษาไทย ก็เลยลองหาดูจาก typo theme
เลยได้ theme eggdrop สีส้มเขียวอ่อนๆ ดูสบายตาดี ลูเล่นน่ารัก
แต่ใจอยากได้ origami แต่ค่อนข้างมี Bug หลาย feature ใม่ได้ ขี้เกียจแก้ด้วย เลยตกลงปลงใจที่ Theme eggdrop
ถ้าจะแก้ก็ไปแก้ที่ css ไม่รู้ว่าใช้รูปเยอะแค่ไหน
Typo 5.0.2
เปลี่ยนไปเยอะมาก ทั้ง front end และ back end มีการจัดวางเมนูได้ดีขึ้น ใช้ง่ายขึ้น สามารถ edit theme ได้บางส่วน ที่สำคัญยังเพิ่มระบบ multi user ด้วย ป.ล. ถ้าจะให้ดีทำ ระบบ plugin ให้ง่ายกว่านี้ก็ดีนะ อยากได้ revision เหมือน drupal จะได้เป็น Wiki ได้ด้วยUltraviolet Hack แบบใช้ไปก่อน
วิธีการก็เอา syntax ที่มีอยู่ใน typo มา hack ซะ ซึ่งมันเป็น macro อยู่แล้ว จาก plugin ชื่อ typo_textfilter_code ก็ copy ทั้ง folder มาเป็นชื่อ typo_textfilter_uvcode จากนั้นก็แก้ทุกอย่างที่เดิมเป็น code ให้เป็น uvcode แล้วก็แก้ไฟล์ typo_textfilter_uvcode/lib/typo_textfilter_uvcode.rb ดังนี้
<typo:uvcode lang="ruby"> def self.macrofilter(blog,content,attrib,params,text="")
lang = attrib['lang'] || "plain_text"
title = attrib['title']
cssclass = attrib['class'] || 'iplastic'
linenumber = attrib['linenumber'] || false
text = text.to_s.gsub(/\r/,'').gsub(/\A\n/,'').chomp
convertor = Uv
text = convertor.parse(text, "xhtml", lang, linenumber, cssclass)
"<div class=\"typocode\">#{text}</div>"
end </typo:uvcode>
จากนั้นก็เอา css จะใช้ไปใส่ที่ public/stylesheets/user-style.css ในนี้เพิ่ม <typo:uvcode lang="css"> overflow: auto; </typo:uvcode> เข้าไปใน class pre
ทดสอบ ultraviolet highlight plugin
<typo:uvcode lang="php"> <?php require 'DB.php';
$dsn = 'mysql://root:bank24@localhost/vhcs2';
$dbh = DB::connect($dsn);
if(DB::isError($dbh)){
die ($dbh->getMessage());
} $result = $dbh->query("select * from admin"); if(DB::isError($result)) { die($result->getMessage());}
while($row = $result->fetchRow()){
print $row[0]."\n";
}
$result = $dbh->query("select * from admin");
if(DB::isError($result)) { die($result->getMessage());}
while($result->fetchInto($row)){
print $row[0]."\n";
}
$row = $dbh->getAll("select * from admin"); print_r($row); ?> </typo:uvcode>
ใช้กับ textile ไม่ได้แหะ ลองอีก code
<typo:uvcode lang="ruby_on_rails"> def self.macrofilter(blog,content,attrib,params,text="")
lang = attrib['lang'] || "plain_text"
title = attrib['title']
cssclass = attrib['class'] || 'iplastic'
linenumber = attrib['linenumber'] || false
text = text.to_s.gsub(/\r/,'').gsub(/\A\n/,'').chomp
convertor = Uv
text = convertor.parse(text, "xhtml", lang, linenumber, cssclass)
"<div class=\"typocode\">#{text}</div>"
end
</typo:uvcode>













