
Udon @ Tsurutontan Roppongi
Originally uploaded by vik_122
世の中はお盆休みのようで。
仕事中に急に奥様から「ホテルオークラに泊まろう」と連絡があったので」六本木で合流した。
いつも混んでいて入るのを躊躇していたおうどんのお店、「つるとんたん六本木店」に30分待ちでいってみた。
海老真蒸と胡麻団子のおうどんに温泉卵をつけてみた。なかなか美味しかったよ。
あらゆる開発言語で開発をしている人のブログ

Udon @ Tsurutontan Roppongi
Originally uploaded by vik_122
世の中はお盆休みのようで。
仕事中に急に奥様から「ホテルオークラに泊まろう」と連絡があったので」六本木で合流した。
いつも混んでいて入るのを躊躇していたおうどんのお店、「つるとんたん六本木店」に30分待ちでいってみた。
海老真蒸と胡麻団子のおうどんに温泉卵をつけてみた。なかなか美味しかったよ。
japanvik.netのリニューアルをしたくなったので、この際wsgiの勉強も兼ねてmvcな俺フレームワークでもつかって見ようかと思う。
サイトのコンセプトは「俺ポータル」 - 自分のブログのアグレゲート済みRSSやTwitterやコードなど、自分のまとめサイトにしたいと思っている。
しばらくwsgi関連のサイトを巡回しながらコードをちょこちょこ書いている。現段階では次のような仕組みで作っている:
テンプレートエンジン: mako + ドキュメント用にmarkdown2
URLディスパッチャー: selector + pasteのstatic
その他自分で書いたものちょこちょこ
本当はelixirでdb接続を行いたいのだけど、dbへのコネクションの維持のあたりがよく解っていないので、今のところdb接続はは無し。Pylonsのコードでも釣ってみようかな。
DBの接続まで出来たら今時のmvcフレームワークとして成立するので、機会があれば公開しようと思う。比較的小規模なサイトならサクサクと出来てしまいそう。ただ、このままいくと、ほぼPylonsになってしまう気配がw
I came across an Agile RSS Aggregator in Ruby which had very elegant code, so I decided to port it to Python. It uses wsgi, the Universal Feed Parser, and the Mako Template.
Here is the code:
#!/usr/bin/python
from wsgiref.simple_server import make_server
from mako.template import Template
import feedparser
class Feed:
""" A Python port of the "Agile RSS Aggregator in Ruby"
See README for details
"""
def __init__(self, environ, start_response):
self.environ = environ
self.start = start_response
def __iter__(self):
status = "200 OK"
response_headers = [('Content-type','text/html')]
self.start(status, response_headers)
stories = []
for f in open('feeds.txt', 'r'):
feed = feedparser.parse(f.strip())
stories.extend(feed.entries)
page = Template(filename='news.mako', output_encoding='utf8')
yield page.render(stories=stories)
httpd= make_server("", 8000, Feed)
httpd.serve_forever()
% for item in stories:
<div class="section details">
<h3><a href="${item.link}">${item.title}</a></h3>
<p style="color:#444;font-size:90%;">${item.summary}</p>
</div>
% endfor
<% item.link %>
Ubuntu recently upgraded its Python distribution from 2.4 to 2.5.
Along the way, setup tools (read easy_install) seems to break itself.
If your python related installs are failing and getting errors like:E: Sub-process /usr/bin/dpkg returned an error code (1)
A package failed to install. Trying to recover:
Setting up python-setuptools (0.6c3-1ubuntu4) ...
pycentral: pycentral pkginstall: already exists: /usr/lib/python2.4/site-packages/setuptools.pth
pycentral pkginstall: already exists: /usr/lib/python2.4/site-packages/setuptools.pth
Then python-setuptools need to be reinstalled.sudo apt-get remove python-setuptools
sudo apt-get install python-setuptools
This fixes the dependency issue and you should be able towithout getting errors.
easy_install Pylons TurboGears
While making a wrapper helper to extend the functionality of the stock date_select, I needed to access the actual date object attributes within the helper method.
The api of the date_select helper is like this:
date_select(object_name, method, options = {})
Where object_name is is the object in the template, and method is the method of that object which returns a date for the select boxes to show.
I wanted to make an enhanced version of the date_select with some javascript goodness, while maintaining the same parameters, and needed the actual date object so I can use it on the javascript output.
Basically I needed to do this:
date = object_name.method
Here is how I did it:
def ajax_date_select(object_name, method, options = {})
# Get the object_name.method value
date = instance_variable_get("@#{object_name.to_s.dup}").send(method.to_s.dup)
The instance_variable_get method allows you to reference the variables in the rendered view.
So for example in the controller, if you said something like:
@hoge = Hoge.find(1)
and in the view:
<%= ajax_date_select :hoge :created_at %>
by using instance_variable_get, you can do the equivalent of
date = hoge.created_at
from within the custom helper code.