Liu 的个人资料唯有仰望是真实的照片日志列表更多 ![]() | 帮助 |
|
2007/9/30 javascript beautifier in ruby更新一下,elfz已经通过无所不能的google看到这篇了,并在他的页面上放上了此帖的链接:P 做web的小朋友们总会看到各种网站他们的很酷的js效果,但是打开我们亲爱的firebug或者webdeveloper show javascritps, 看到是jsmin之后的一行很长的无法阅读的东东。 在网上找到这个家伙的网站http://elfz.laacz.lv/beautify/,提供在线的把jsmin之后一行的js反向格式化成可以阅读的样子。作者提供了php的源代码http://elfz.laacz.lv/beautify/beautify.phps。 于是我想将程序员的懒惰本性发挥的更多一些,是否能够把这个东东集成到我们亲爱的webdeveloper show javascripts或者最近小靓身影的YSlow里面去呢, 于是我找来webdeveloper的代码,挺好,只要把beautifier翻译成js的就可以嵌入进去,哈哈,到时看我看到每个开心的网站就能省很大力气去看他们的js代码了。 当然这个只是重新格式化代码,如果网站不只是压缩了js代码,而且进行了混淆,那么这个工具就无能为力了,你就格式话之后看着一个个没意义的变量猜吧,或者人家不让我们看,我们就不看好了。 在翻译成js版本之前,为了活跃一下气氛,最近写代码也不多,大多是琐碎的事情,于是乎觉得每天不写他几百行代码就tmd不爽,先翻译一个ruby的版本,熟练一下ruby的一些用法,不如之前不知道的begin-end-while来伪装do-while, 和unicode的正则匹配,刚跑了一下测试的代码,和原作者网站上的在线服务测试那个autocomplete.jsa good example结果一样了,小开心一下,排解一下空荡荡房子无所事事的无聊情绪。js版本的js_beautifier.js和嵌入webdeveloper随后奉上。 原作者elfz老大的原话,我quote说: “This script was intended to be useful to explore the scripts compacted in one line (CAPXOUS autocomplete, recently renamed to CreateWebApp for some stupid reason, is a good example). That's what I wrote it for—all the other beautifiers really sucked. As the time went, I improved to suit your pretty-formatting javascript needs better.” =======================我是code monkey的分界线====================== #!/usr/bin/env ruby $TK_UNKNOWN = 3 $TK_BLOCK_COMMENT = 13 $TK_PUNCT = 15 # internal flags def js_beautify(js_source_text) # words which should always start on new line. # states showing if we are currently in expression (i.e. "if" case) - IN_EXPR, or in usual block (like, procedure), IN_BLOCK. $pos = 0 $lasttok = $TK_EOF while true case token_type if line_starters.include? $token_text or prefix == $PRINT_NL when $TK_END_COMMAND space if start_delim $lasttok = token_type def prepare_utf(str) def nl(ignore_repeated = true) def space def token def indent def unindent def in_context(where) def in_pop def make_array(str) def get_next_token if num_newlines return [c, $TK_START_EXPR] if c == '(' or c == '[' if c == '/' # peek for comment // ... if (c == "'" or #string if $pos < $input_length $pos += 1 if $punct.include? c return [c, $TK_PUNCT] if c == '/' if $0 == __FILE__ 2007/9/29 Ruby's Hidden do {} while () Loop (zz)from http://www.jvoorhis.com/articles/2007/06/13/ruby-hidden-do-while-loop 今天翻译一段php代码到ruby, 才发现ruby没有do-while:P, 偷懒网上搜到这个方法,呵呵,挺有趣 Posted by Jeremy Voorhis Tue, 12 Jun 2007 22:13:00 GMT I found the following snippet while reading the source for At first glance, I assumed the while modifier would be evaluated before the contents of begin...end, but that is not the case. Observe: As you would expect, the loop will continue to execute while the modifier is true. While I would be happy to never see this idiom again, begin...end is quite powerful. The following is a common idiom to memoize a one-liner method with no params: Here is an ugly, but quick way to memoize something more complex: 2007/9/27 心情好最近心情特别的好,参加了小熊主持的中心的晚会,两三年可能更多没参加学校的活动了,特别的开心,我想我更适合学校的环境,让人很放松,不去考虑很多很烦很恶心的东东,更不要说能看到美女:) 延续了好几年的惯例,和从前qqq版上的朋友们吃了中秋饭,很久没有见这些小朋友们了,大家变化都挺大,ahka同学变的好肥:P, 哈哈,对比一下,我还是控制的满不错的。大家吃饭聊天分月饼,很是开心。和never gg讨论些工作和职业的问题,感觉挺忽悠人家的,因为自己的前途未卜,且鼠目寸光看不清前面的路,希望他能够做的比我好:) DVD卡住弹不出来了,刚上线的改动服务器挂了又回滚了,mapbar提供的地图服务真是不好用的说,但是这一切的一切,都休想扰乱我的好心情。 2007/9/23 CMU Professor Randy Pausch's 'Last Lecture'
在课程展示的时候,那个"oh, not Ctrl-Alt-Delete" and the world crashed. 太赞了,呵呵,好感动,achieving your dreams and enables the dreams of others.Brick walls are there for a reason: they let us prove how badly we want things还有那段对mm们的忠告,"ignore all the things man said, pay real attentions to what they do", 汗,真切。强烈推荐去youtube上看看,it will change your world:)
|
|
|