2011/06/28
Coffescript iteration caveat
2011/01/11
how to get OAuth Consumer Key / Secret for Google OAuth
Here is the easiest way to do it.
2010/11/11
Resources for learning node.js
2010/11/05
serving a mp4 via node.js
I'm practicing node.js. It's like early days of Rails. One thing that stops me to jump in this bandwagon is that my lack of knowledge of javascript. Anyway, after mastering node.js world technique, I want to go use event techniques in ruby in the future. I'm sure that ruby's virtual machine will evolve.
2010/09/27
2010/09/21
Installing jspec, rspec textmate bundles
Install RVM textmate bundle http://rvm.beginrescueend.com/integration/textmate/cd /Library/Application\ Support/TextMate/Bundles/git clone git://github.com/rspec/rspec-tmbundle.git RSpec.tmbundleit clone git://github.com/visionmedia/jspec.tmbundle.gitosascript -e 'tell app "TextMate" to reload bundles'
2010/02/28
My first visit to IDC
2009/10/17
Cappuccino - animated segment controller
LPKit enabled Cappuccino toolbar from jaigouk on Vimeo.
2009/01/30
Rest with Merb: CouchDB resources

I've been studying couchdb. There are several ways to use couchDB with merb. CouchRest, dm-couchdb-adapter, relaxdb. At the beginning, I've focussed on dm-couchdb-adapter. Because there is a good example, the muddle. It works on my local machine too. I looked into the source codes, and it was not easy to understand them. My head was full of relational database concepts, and it prevented me to go further. I decided to spend more time on couchDB. I asked @merbist via twitter that which would be the proper way to use couchDB. And he answered that "Couchrest for sure, the 2 other ones don't use couch properly"
These are the resources to start.
- CouchDB and Me(Jan 31, 2009): Damien Katz explains what drove him to create CouchDB
- codebits2008 presentation by jan lehnardt(Nov 27, 2008) : good introduction
- Peepcode screencast(Sep 23, 2008) : goes deeper and shows how to use couchrest. It is little bit outdated.(couchview -> couchapp) But example app works!
- CouchRest::Model - ORM, the CouchDB way(Sep, 2008)
- Atlanta Ruby Group, merbday presentation(Dec 12, 2008)
There is a ruby interface written by jchris, Couchrest. He has a plan to launch Couchrest::Model seperately [link].
And Couchview has been replaced by couchapp [link](I've followed Peepcode screencast, and spent some time to figure out why "couchview" command is not working.)
$ couchapp
Usage: /opt/local/bin/couchapp [options] (push|generate)
-q, —quiet Omit extra debug info
-h, —help Display detailed help and exit
-v, —version Display version number
Here is what jchris said about couchapp at couchrest google group[link]
====================
Couchapp is equivalent to couchview, except for a few details about
how it expects to see documents stored on the filesystem.If I recall correctly, couchview takes something like this
views/test-map.js
views/test-reduce.jsand pushes it to the views member of a design doc, which you'd specify
on the command line, with a default of falling back to a directory name. Couchview does that job just fine, but it is no generalized to handle the other functions that can be stored in a design doc.the CouchApp script takes a filesystem and pushes it transparently to a design doc, so the on-disk layout it expects is a little different:
views/test/map.js
views/test/reduce.js
validate_doc_update.js
shows/post.js
lists/index.js
_attachments/images/example.png
_attachments/foo/bar.htmlyou are free to leave any of that out (so if you only care about views then you should be able to use it just fine.)
currently the python version of couchapp also has the ability to "clone" from a url. I'm working on getting the ruby version back up to speed, but for now you might be happiest installing the python version.
Things move so fast around couchDB and couchrest that one article is not proper to summarize them. I will post time to time about it.
2009/01/27
merb pagination
Q. "@current_page = (params[:page] || 1).to_i " what does that refers to?
A. billturner> when you use the pagination, and the <%= paginate(..) %> stuff, it gives you links like /posts/index?page=2
A. billturner> so, if there's no "page=X" then it will pull the first page of results
2009/01/23
502 Bad Gateway

Recently, I've changed my server from mod-passenger to nginx because of the comment at merb google groups[link]. Passenger was fit for me. It makes deployment more easier than before. However, merb's way of handling processes seems complicated and advanced as Ezra said[link]. And it is not fully compatible with passenger now.
So I came back to nginx. I thought it would be easy. But it took some time to run my small app. I 've seen a lot of "502 Bad Gateway" page. I guessed that compiling was wrong at first time. It wasn't nginx but my logic in the codes. So the best way to check what's wrong, just type "merb" on the server. I haven't installed necessary gems and libraries. Yes, it is very basic stuff but easy to miss.
2009/01/16
Twitter on Merb : Merb flat app Walkthrough


Description
- site : merb.kicks-ass.org
- codes : jaigouk.github.com/twitter-on-merb
- server: slicehost Ubuntu 8.1, nginx, merb version 1.0.8.1, dm version 0.9.10
- purpose: aggreate github commits feeds and post them to twitter @edgemerb
- todo: eager cache
Motivation
I’m a newbie in merb community. Since “the merger”, I needed correct and reliable reference and so was other newbies in the community. I started to translate merb-book in Korean. But it was not enough for us .I thought that learning merb would be easier if I build an app what I really need such as tracking recent changes. It was easy since there are good tutorials and tools. And scraping nightly version of README file could be helpful too. Because merb core team members are too busy to write guides and tutorials.
I laid aside scraping the README files for now. I just aggregated merb commits rss and send them to twitter. I use TwitterFox as twitter client on my desktop. Whenever a new message comes, It shows the message in a brief moment. It's really handy.

Generating a flat app
This is what I did at first time. As you see, It is really small and shows basic structure how merb works. If you want to learn more about internals of merb, visit here(http://github.com/michaelklishin/merb-internals-handbook)
Using Model in a flat app
I edited config/framework.rb file. Because I could not use twitter_search gem to verify the message is unique or not. This is same as twitter timeline api. It seems that they use cache. Therefore I had to add a model to check the message I'm sending is unique or not.
First, I added one line :model => Merb.root / "models" in config/frameworks.rb file. And then, wrote dependencies in init.rb file.
$merb-gen model tweet
$rake db:automigrate
Scraping with nokogiri
Since merb flat app has a single controller file, It was easy to start. But the twitter api and nokogiri took some time to use. I was not familiar with nokogiri, I googled and found this tutorial. (http://www.robertsosinski.com/2008/12/08/scraping-pages-made-easy-with-ruby-and-nokogiri/).
And I better use a well designed web site template. I picked one of the recommended templates from samshmagazine.(http://www.smashingmagazine.com/2008/12/01/100-free-high-quality-xhtmlcss-templates/)
There were 3 or 4 ruby libraries for twitter. And twitter4r has more documents than the others. It took much time to discover that timeline api and search api use cache. I just forgot about the cache. Anyway I installed necessary gems.
$sudo gem install twitter4r twitter nokogiri shorturl
And then I eddited index.html.erb file. In the controller, it only needs render method. I just wanted to use feedtools and feedupdater gem. But there were not enough document to reference and as merb-book says, I better not use codes that I don't understand. Scraping pages with nokogiri is easy but my app would be fragile.
I know the codes above is not that beautiful. But I hope this code help another rubist who want a scraping example through nokogiri. As you see above, k.content which was return by nokogiri's search method was Hash. This is why i used to_s method.
Scheduling background works

And posting a message to twitter was tricky for me. Because of increasing popularity of twitter, posting throuth api was too fast for twitter sometimes. Posting messages takes much time and that code block needs to sleep. In the initial codes, I wrapped the block with run_later. But I found that I need to schedule the tasks. There would be several way to acheive scheduling the daemons. In version 0.0.1.4(Twitter-on-Merb), I used crontab and rake. But the codes were dirty and it did not work as I expected. I talked about this with lakteck via tiwtter, and I remembered that I've seen rufus-scheduler at igvita.com[link]. It was really easy to implement scheduler with rufus-scheduler gem. The scheduler scrapes web sites on every 10 minutes. And I made a starling consumer daemon. I referenced "Advanced Rails Recipes #42"
confing/init.rb
lib/daemons/starling_consumer.rb file
lib/daemons/starling_consumer_ctl.rb file
config/consumer.god file. Daemons are started after "cap:deploy".
Cache
My flat app was too slow, and it was time to implement cache. I referenced,
- Keep a hot cache with merb-cache by Ben Burkert at MerbCamp
- Merbunity Tutorial#15 written by Ben Burkert on Sep 07, 2008
- Merb-cache's methods written by Guillaume Maury(a.k.a giom) on Dec 19, 2008
== Quick intro
With fragment caching, you can mix dynamic and static content.
With action caching, the whole template is cached
but the before filters are still processed.
With page caching, the whole template is put in html files in a special
directory in order to be handled directly without triggering Merb.
by Dan Kubb on July 22, 2008
But my init file was wrong at that time and throws erros whenever I run "rake db:automigrate" since I set up the cache(http://gist.github.com/44702). I really didn't know how to fix this. At first, I guessed that datamapper version could be the reason why causes it. After updating the gems, error were still there. Fortunately I have known Guillaume Maury(giom) recently via twitter. He helped to get out of this. This code was not familiar with me. I thought I knew the way to setup the cache.
The codes were already in his article (http://gom-jabbar.org/articles/2008/12/14/example-nginx-configuration-for-merb-with-page-caching-using-the-file-store). I run my apps on passenger so I simply skipped it. :) I highly recommend his blog if you are in Merb2 or Rails3. Here is the snippet written by him. (The initial flat app with plain dependency line did not work.)
And I referenced here.
http://blog.evanweaver.com/files/doc/fauna/memcached/files/README.html
$ wget http://download.tangent.org/libmemcached-0.25.tar.gz
$ tar -xzvf libmemcached-0.25.tar.gz
$ cd libmemcached-0.25.tar.gz
$ ./configure
$ make && sudo make install
$ sudo gem install memcached
$ irb
> require 'rubygems'
> require 'memcached'
Deploy
$cap deploy:setup
$scp -r database.yml to server
$scp -r twitter.yml to server
$rake db:create
$rake db:automigrate
$cap deploy
this is my deploy.rb file.
tip
And if you have problems after your deployment, check if config.ru(must be 'config.ru', not 'Config.ru') file exists and the permissions are correct(chmod 755 -R).
2009/01/02
Free merb screen casts

#1 MerbCamp - Yes, all merbists have seen it.
#2 Merbunity - It's maintained by hassox!
#3 Atlanta ruby user - I found this site recently. I think it's worth to see.
#4 Merb Dependencies and Bundler - by Carl Lerche
#5 peepcode (well, not free. but it's 9$) - The screencast was recorded on merb 0.9 but it still is a good one.
And there are good tutorials.
2008/12/24
Merb + Rails merger

Update(2009.2.8)
"Merb in Action" => "Rails3 in Action"
http://www.manning.com/katz/
Table of Contents
1. Building Your First Rails 3.0 Application
2. Overview of the Rails stack(s) + architecture
3. Creating Rails Applications
4. Using DataMapper for Models
5. Using ActiveRecord for Models
6. Other Choices for Models
7. Processing Requests
8. Routing in Rails 3
9. Customizing Views
10. Working on the Client Side
11. Supporting Characters
12. Using the Plugin API
13. Testing Your Applications
14. Deploying a Rails Application
15. Scaling Rails
Appendix A Just enough advanced Ruby
Appendix B The migration story
Appendix C Rails 2 to Rails 3
Appendix D Merb 1 to Rails 3
Update(2009.2.5)
Rails 3 will have mountable applications, not engines or slices.
Update(2009.1.16)
I just got an email from manning about "Merb in Action".Update(2008/12/26)
- Rails becomes more modular, by building on rails-core with the ability to opt in or out of specific components and making it possible to replace parts of Rails without disturbing other parts.
- Merb performance improvements flow into Rails, including benchmarking applications so developers can see which optimizations have real-world impact.
- A defined public API with a test suite, so users and plugin developers have a stable API to build against.
- A "core" version of Rails, like Merb's current core generator, that makes it easy to select just the parts that are important for your app.
- DataMapper and Sequel support as first-class ORMs, along with ActiveRecord as the default.
- Rack support in Rails 3, to improve the state of modular, sharable logic between applications.
So far, it seems that merb google group is the best source. And Matt Aimonetti answers all the concerns.
Yehuda Katz says
"If you want to learn Merb for modularity and power that is not currently present in Rails, stick with Merb. We'll provide a good upgrade path to Rails3 (and feel free to contact me personally to keep me honest on that promise), and you'll have a leg-up when the same power makes its way into Rails. While Rails3 will still be very similar to Rails2 for current Rails users, it will look a lot like Merb for those users who are currently drawn to Merb."
"We always said that there would be breaking changes in Merb 2.0. Now, some of those breaking changes will be in tandem with the Rails3 merger. However, we will treat them like any other breaking changes, and make sure the deprecation notices flow freely and the transition path is clean. Make sense?"
Matt Aimonetti says,
"The great advantage of using merb now, is that it has a public API so we will be able to easily migrate it to the new 3.0 API. Concretely, we are planning on being able to replace merb-core by rails-core in your merb app and to use merb-helpers and other plugins with rails-core."
I think "Merb in Action" would take longer than expected. And it's required to rewrite the whole chapters that are published. Of course, book's title will not be changed but I'm just worried about Merb. It would be called Rails3.0 by many other people, especially inside Rails community.
As Ezra said,
Merb is dead, long live Merb(Rails-3.0)!Matt Aimonetti said,
I don't think Ezra is right. Merb isn't dead. First off, merb will still be around until the next release (rails 3.0) and we will keep on supporting it even after that (maintenance).So many merbists are disappointed by this news but there is nothing can be done. Engin Yard's decision looks solid. I've accepted it, after all. I've read many articles enough to say that I will stick with Merb. There were some people who even want to switch to Django. I decided to practice Merb more than before. Because Merb would be the core changes in Rails3. And it could happen that Merb core team is too busy. But evangelist like Matt Aimonetti will help us. I hope taking this path would be natural to Merb2.
2008/12/20
오픈소스 merb-book 한국어 번역

Now, merb has many resources to learn.
튜토리얼 및 기타 소개 동영상들 : MerbCamp videos,스크린캐스트 : http://merbunity.com/screencasts
and there is open source merb-book which is started by Matt Aimonetti.
Well, I saw Chinese and Japanese but no Korean one. I think that there are probably not enough rubists in Korea. Anyway I sent a message to him that I want to start if there is no one. And here it is.

Update(12/22/2008)
I've completed "Merb-More" Chapter. But there are still unfinished chapters in English.
Merb-More 챕터까지 모두 한국어로 번역을 완료했지만, 영어로 된 원본이 아직 빈 곳이 많습니다. 번역하는데에는 네이버 단어장, 구글번역기, 바벨피쉬, 그리고 제 경험을 최대한 살려서 번역했습니다. 많이 부족하므로 오타나 잘못된 번역을 알려주시면 고치도록 하겠습니다. 한글로 된 merb 책이 나오려면 아직 오래 걸릴 것 같습니다. (영어 책도 아직 출판되지 않았습니다.) 참여를 원하시는 분은 메일 보내주시기 바랍니닷.
Update(12/23/2008)
I finished the translation.
현재까지 작성된 영어 원본에 대한 번역은 마쳤습니다. 제 생각에는 본격적으로 책들이 쏟아지는 2009년 전반에는 이 오픈소스 책도 많은 개선이 있을 것 같습니다.
Update(12/24/2008)
Rails와 Merb가 합쳐지는 이 시점에서, Pragmatic Bookshelf, Apress 등에서 나온 책들은 의미가 희석되었다고 생각합니다. 워낙 빠르게 변하다보니 책들이 따라가지 못하고 있습니다. 오픈소스 책의 발안자인 Matt Aimonetti가 Rails 코어팀에 합류했기 때문에 이 책이 그나마 현재 나온 책중에서는 가장 참고할만한 책이 되지 않을까 싶습니다. Rails3.0에선 Merb의 기능들을 흡수할 예정이기 때문입니다.
update(2009.1.4)
제가 실수로 master 브렌치에 작업내용을 합치질 않았었습니다. -_-;;;
이제 github에서 다운받으셔서 정상적으로 보실 수 있습니다. 업데이트 내용은 4번째 장인 "데이터베이스와 상호작용" 부분입니다. 현재까지 작업된 영어원본까지 모두 작업완료되었습니다. 책을 받아서 보시는 분들이 계시다면, 오타나 의역에 무리가 있는 부분을 지적해주세요. :)
오픈소스 merb 책이 나왔지만 한국어 번역이 없어 매트에게 해보겠다고 메세지를 보냈습니다. 흔쾌히 해보라해서 현재 작업중이고 getting started/mvc까지 작업완료했습니다. 이제와서 보니 일본어나 프랑스, 중국 번역판에 비해 늦은 것은 아니었습니다.
------------------------------
책을 보는 방법
------------------------------
필요조건 :
a. ruby, gem
b. git
스텝 :
1. 먼저 제 github 저장소에서 merb-book을 로컬 pc로 복사합니다.
$git clone git@github.com:jaigouk/merb-book.git
2. 다운받은 merb-book 루트 디렉토리에서 다음을 실행해 주시면 됩니다.
$./bin/merb
3. 브라우저에서 http://localhost:4000 주소로 가면 책을 보실 수 있습니다. 목차 맨위에 보시면 각 언어들 링크가 있는데 한국어를 선택하시면 됩니다.
----------------------------------
Chapter별 완성도(2009/1/4): 좋음(○), 미흡(△), 없음(X)
----------------------------------
2008/12/17
3D desktop and ruby

As the rumor says, it is obvious that Apple is developing next OSX. 3D environment is the critical difference. Bumptop desktop could be similar with it. Trends are really clear. Wiimote, Jeff Han's Ted demo, and Ubuntu Compiz fusion. The new era of HCI has come. But there're little apps which are appropriate with these environments. Adobe launched AIR, and it is still early for general users. But it is certain that adoptions are growing.

Now, we see java 3d OS. Where is shining, rich ruby desktop environment! Do we need to learn Air to mimic 3d actions?





