Showing posts with label Groovy. Show all posts
Showing posts with label Groovy. Show all posts

Saturday, September 12, 2009

การ encode ข้อมูล ด้วย groovy

ตัวอย่าง การ encode ข้อมูล

def outFile = new File('out2.txt')
outFile.delete()
datafile = new File('out.txt')
datafile.eachLine{ line ->
for (c in line) {
outFile.append( (char) ((int)c+1) )
}
outFile.append ('\n')
}
input (out.txt)
--------
This is a boy.
This is a girl.

output (out2.txt)
---------
Uijt!jt!b!cpz/
Uijt!jt!b!hjsm/

การ decode ข้อมูล ก็สามารถทำได้ไม่ยาก เหมือนกันลองไปทำดูครับ

เกี่ยวกับ file ใน groovy

ตัวอย่างการสร้างไฟล์ และ อ่านไฟล์ใน groovy

การสร้าง file

def outFile = new File('out.txt')
outFile.delete() // if file exist, delete it
def i = 1
4.times{ // 4 time loop
outFile.append i++ + '\n'
}


การอ่าน file

datafile = new File('out.txt')
datafile.eachLine{ line -> print line + '\n' } // closure

คำแนะนำในการศึกษา Grails

ถ้าคุณเคยใช้จาวา การใช้ Groovy คุณต้องเข้าใจเรื่องต่อไปนี้ closures maps และ properties อ่านตรงนี้
และ เรื่อง MVC, GORM, Filters and Services, GSP และ conf

กรณีการ insert ข้อมูลใน Grails แล้ว OutOfMemoryError

แสดงตัวอย่างการ insert ข้อมูลจำนวนมากใน Grails แล้วจะช้ามาก และจะเกิด OutOfMemoryError สามารถแก้ไขโดยการsessionFactory.getCurrentSession().clear(); ตามลิงค์นี้
Grails, Inserting lots of data using withTransaction results in OutOfMemoryError

การใช้ Batch ใน Grails

การใช้ Block-Level และ Method Level Transaction ใน Grails
Transaction & Batch-processing in Grails

เริ่มต้นการใช้งาน blog แรก และ groovy

บางครั้งเคยเจอ ลิงค์่ที่น่าสนใจ แต่ไม่รู้จะเก็บไว้ไหน ก็เลยมาเก็บไว้ตรงนี้ เดี๋ยวปล่อยไว้นานจะหาไม่เจออีก น่าเสียดาย

วิธีติดตั้งการใช้งาน groovy
http://groovy.codehaus.org/Installing+Groovy

การใช้งาน groovy เบี้องต้น
http://www.javalobby.org/articles/groovy-intro1/