gedit และ vim เพื่อการทดแทน textmate
ไม่เคยใช้ mac หรือนะ เลยไม่เคยมี textmate แต่คิดว่า gedit นี่ก็โอเคแล้ว Gmate: http://github.com/lexrupy/gmate/ วิธีลงก็
$ git clone git://github.com/lexrupy/gmate.git $ cd gmate $ sh install.sh
$ git clone git://github.com/akitaonrails/vimfiles.git .vim $cd .vim $ git submodule init $ git submodule update $ cp vimrc ~/.vimrc
git submodule update
Luko Sharpening
ตอนนี้ลองเขียน Luko Sharpening โดยได้ศึกษาระบบการทำงานมาจาก kittyresize + unsharp-mask little by little
พี่แสนเคยบอกไว้มานานแล้วว่า เวลาย่อรูปเนี่ยเราไม่ควรย่อลงไปให้ได้ขนาดในทันที เช่น จาก 100% ไปเป็น 50% เราคววรจะแบ่งการย่อทีละนิดๆจาก 100% ไปเป็น 75% แล้วค่อยย่อจาก 75% ให้ได้ 50% หลังการย่อแต่ละครั้งให้ทำ unsharp-mask ด้วยจะทำให้ภาพคมขึ้นและดูสวยงามMy brother SAN told me long time, when I have to resize, I should not resize to aspect ratio immediately such as 100% to 50%. I have to resize little by little from 100% to 75% then resize from 75% to 50 . Then after each resize process, it should be applied unsharp-mask filter. I will make more sharpen.
ผมก็เลยเขียนเพิ่มให้มันเป็นการแบ่งครั้งที่จะทำการ resize ได้ดังนี้
ดูได้จากภาพตัวอย่าง ได้ที่ multiply
[...]
Ruby Fork
จากครั้งที่แล้วผมอยากจะเขียน ruby สักอันไว้ทำการ stamp ลายเซ็นพร้อมค่า exif ลงในรูป จากการลองเขียนเป็น thread แล้วปรากฏว่าไม่ค่อยมีประโยชน์เท่าไหร่กลับกลายเป็นว่ามี overhead ขึ้นมาเพียบและก็ทำงานไม่ครบได้ทุก core ที่มี งานส่วนใหญ่ในการทำงานเกี่ยวกับภาพนี่จะเป็นในด้านคำนวนซะเยอะ เลยเขียนเป็นลักษณะ fork ออกมาจะดีกว่าพอลองได้เขียนก็ได้แนวคิดมา 2 แบบ คือ
- ทำงานแบบเป็น lot คือทำพร้อมกันที่ละเท่าๆกัน แล้วรอให้เสร็จหมด ค่อยเริ่ม lot ต่อไป แบบนี้ถ้ามี process ใน lot เสร็จก่อนเพื่อนก็ต้องรอ
- แบบที่สองคือเริ่มทำงานให้เต็มตามที่เรากำหนด ถ้า process ไหนเสร็จก่อนก็เอา process ใหม่มา run ได้เลย แบบนี้จะทำให้การทำงานต่อเนื่อง
My Failure with Ruby Multi-Thread
คือว่าผมใช้ debian + ruby + rmagick เขียน script เพื่อที่จะทำการ stamp รูป แต่มาได้ความคิดว่า อย่าง convert เนี่ย ถ้าเราเรียก- Kernel space จะเป็น thread แบบ native คือ kernel จะเป็นผู้จัดสรรและสับเปลี่ยน ก็จะได้ประสิทธิภาพตามคุณภาพของ kermel + cpu
- User space หรือเรียกอีกอย่างว่า Green thread คือ thread ที่ทำงานแบบ time slice โดยผู้รับผิดชอบคือ VM (Virtual Machine) ในกรณีของผมคือ ruby นั่งเอง VM จะทำหน้าที่จัดสรรและสับเปลี่ยน เสหมือนเป็นการจำลอง thread อีกที ผลที่ได้คือ kernel เห็นเป็นเพีบง singel thread จึงทำงานได้เต็มที่แค่ 1 core
Make a stamped for a Photo; ทำกรอบรอบรูป
หลังจากที่ได้ D80 มาสมใจอยาก เห็นหลายๆคนเวลาแสดงรูปจะมีการแสดงความเป็นเจ้าของโดยใส่ลายน้ำหรือใส่ข้อมูล exif หรือลายเซ็นไว้ ก็เลยอยากจะทำมั่ง ใน Photoshop ก็สามารถเขียน script(java script) ให้ทำทีละหลายๆรูปได้ หรือจะใช้ ACDSee ก็ทำได้ ส่วนสำหรับบน Linux ไม่ค่อยมีข้อมูลเท่าไหร่ แต่ Tools และ Libs เพียบ เลยตกงว่าจะออกกำลังเขียน ไหนๆก็ไหนๆ แล้วเขียนด้วย ruby ซะเลย นี่เป็น version ใช้เอง แต่ก็สามารถเขียนให้ดีกว่านี้เพื่อเอาไปใช้กับงานอื่นๆได้ code License GPL2
After I got D80, I saw many people show up their photos with a water mark, signature, exif data. I think that I have to do same way. Photoshop can do with a script, ACDSee can do also but Linux have no idea about that ( I may not know). By the way ,Linux come wiht many tools and Libs so I make a decision to write a ruby script for do that. This code is under GPL2 License. This version is for my own purpose, it may not be well design.
Requirement: Ruby 1.8.6, RMagick
Usage: run script at same Photo Directory, script will generate a directory "stamped" and file name is "stamped-Passenger with some fcgi
I have a problem that I install passenger 1.0.3 that work fine with low transeaction web but for some web need high transaction , it need fcgi. The question that how can I use fcgi for some web and other run by passengerTypo 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>[...]

