damien.h

Grails框架优劣势分析及同类比较

Grails系列的第二篇文章也以在InfoQ中文站发表,可以从这里阅读

在这篇文章里,我试图从客观的角度把Grails和其他两个快速开发框架RoR和Django做一些比较。总的来讲Grails和Rails在各方面都很接近,Grails和Rails各自的开发者如果接触另一个框架都一定容易上手。目前来看,Grails在技术上可圈可点,但是作为开源项目,其最大的软肋来自于社区。没有像RoR和Django这样强大的社区,Grails的发展相比起来缺少活力。而在语言层面上,Groovy也仍旧相当非主流。RoR的成功可以说很大程度上要靠DHH强大的影响力,而Django也许更多是靠着Python社区的影响力,包括Google App Engine对Django的间接推动。Grails在不久之前还是一穷二白:没有强大的社区也没有强大的商业支持。最近SpringSource出手可以说是一大新闻,让我们拭目以待09年Spring会把Grails带到什么样的程度吧。

案例研究:利用Grails搭建Feedlr.com网站

最近为InfoQ中文版供稿了2篇文章,今天第一篇发布了,可以从这里阅读。第一篇文章主要从技术角度介绍使用Grails实现Feedlr的大致过程,以及实现过程中的一些总结。接下来的第二篇将通过Feedlr的经验来引出对当前Grails发展状态的总结和思考,敬请关注。
文章版权属于InfoQ,此处不做转载,请移步InfoQ阅读全文

Feedlr公开上线咯

Feedlr是我用Grails做的一个pet project(宠物项目?)现在已经公开上线咯~

Feedlr是一个类似twitterfeed的miniblog mashup。但它除了twitter同时还支持国内的叽歪饭否,并且能让用户浏览所有在feedlr上创建的bot,就像个bot超市,找自己感兴趣的就能直接follow/关注了。

如果你经常用miniblog,特别是国内的叽歪或者饭否用户的话,不妨去feedlr找找看有趣的bot吧。

或者,如果你有自己的博客,希望更多的人能随时随地收到你博客的更新的话,就可以用feedlr把自己的blog广播到miniblog上。现在不用再羡慕英文blog圈流行的twitterfeed了,用feedlr把你的博客直接广播到国内的叽歪和饭否吧~

另外,你也可以把任何你感兴趣别人也可能感兴趣的feed用feedlr建立bot,让大家都能随时随地收到新鲜消息,比如我建立的cnBeta botGoogle新闻 bot,就有很多叽歪的朋友关注着咯。

你还可以访问Feedlr的叽歪留言板,关注和讨论最新的Feedlr功能和用法,还可以给我提意见~我直接就能通过叽歪收到你的留言呢:))

Blog title updated, meet Elvis!

I feel like updating my blog’s title a bit, to reflect the evolvement of the content of my articles, and to show off a cool concise way to express yourself in Groovy. Can you guess the meaning?

It’s the “?:”, aka. the Elvis Operator, introduced in Groovy 1.5. Pretty awesome, eh?

I’m Zone’d

前两天在折腾wordpress dzone插件的时候惊喜的发觉我上周在新开的feedlr.blog发的Grails IDE文章被顶到DZone上去了,而且貌似大家反映还不错:) Blogosphere果然很好,很强大。

image.png

image1.png

Grails IDE – Eclipse vs. IntelliJ IDEA vs. NetBeans

I’ve written an new article on feedlr.blog. Check it out.

Downloading YouTube Videos with a Groovy one-liner, and convert it to mpeg4

Today I used LiveHTTPHeaders to take a closer look at how the youtube video streams are directed to the browser. And I found that my previous attempt actually has some redundency in it. To get the flv video stream, simply request the URL:

http://cache.googlevideo.com/get_video?video_id=${vid}

where vid is simply the v string in the original URL. e.g. http://www.youtube.com/watch?v=5C0I7Ef4gQI

So the simplified version is one line of code even shorter now.

def vid = (args[0] =~ (/(? new URL("http://cache.googlevideo.com/get_video?video_id=${vid}").openStream().eachByte{it -> os.write(it)}}

And now here’s a bonus. Grab ffmpeg and put the ffmpeg executable to your system path. Then add the following line to the Groovy script above, and the downloaded flv file will be converted to an mpeg4 format mpg file immediately. You can also play with many ffmpeg parameters to fine tune your convertion.

For Windows

Runtime.getRuntime().exec(['cmd', '/c', "ffmpeg -i ${vid}.flv ${vid}.mpg"] as String)

For Linux

Runtime.getRuntime().exec(['sh', '-c', "ffmpeg -i ${vid}.flv ${vid}.mpg"] as String)

Downloading YouTube Videos with a Groovy one-liner, kind of

Inspired by Downloading YouTube videos with a Perl one-liner, I’ve put together a piece of code to do the same thing with Groovy. Not as succinct as Perl. But figure out how much noise there will be in plain Java.

HttpURLConnection.setFollowRedirects(false)
def vid = (args[0] =~ (/(? new URL("http://www.youtube.com/get_video?video_id=$vid&t=${(uri =~ (/(? os.write(it)}}

Let’s take a closer look at the code. To capture the redirect location, we must temporarily disallow HttpURLConnection to follow redirects.

HttpURLConnection.setFollowRedirects(false)

Then we extract the v id from the original YouTube URL and compose the URI for the embedded player. Open a connection to the video URI and extract the redirect location from the HTTP header. The input parameter arg[0] should be something like http://www.youtube.com/watch?v=5C0I7Ef4gQI

def vid = (args[0] =~ (/(?<=v=).*$/)).getAt(0)
def uri = ((HttpURLConnection)new URL("http://www.youtube.com/v/$vid").openConnection()).getHeaderField('Location')

Now we must enable http redirects again, otherwise the last line of code won’t work.

HttpURLConnection.setFollowRedirects(true)

Finally, go ahead to compose the video data download URI, open a connection and download the data stream.

new File("${vid}.flv").withOutputStream{os -> new URL("http://www.youtube.com/get_video?video_id=$vid&t=${(uri =~ (/(? os.write(it)}}

Save the script to a groovy file like “YoutubeSaver.groovy”. Run the script from command line and give the video URL as the parameter. For example,

groovy youtubesaver http://www.youtube.com/watch?v=5C0I7Ef4gQI

Version 1.0.1 of the Groovy Eclipse Plugin is now available!

The goodness of the day isn’t over yet. The newest version of the Groovy Eclipse Plugin is also out now! I can’t wait to try out the code completion magics.

让Grails + MySQL正确处理中文

其实Grails用MySQL数据源处理中文还是很方便的,基本只要注意2点:

  1. 在xxxDataSource.groovy里,mysql url注意要加上参数,例如:jdbc:mysql://server?useUnicode=true&characterEncoding=UTF-8
  2. MySQL数据库要用UTF-8编码

另外,gsp里要注意:
< meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
默认应该就是这样。

Browse Happy logo

My tweets

2016年四月
« 八    
 123
45678910
11121314151617
18192021222324
252627282930  

分类目录

Articles

Fancy Stats