2008年4月13日日曜日

現在編集しているファイル名をクリップボードに

人に説明する際に、ファイル名や抜粋がクリップボードにコピーしたくなることがある。
以下を vimrc にでも追記すれば :FN や :FL で簡単にコピーできる。
# visual 選択中の :FL は抜粋になる


" 'ファイル名' をヤンク/クリップボードのバッファにコピー
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
command! FN let @"=expand("%:p") | if has("gui_running") | let @*=@" | endif

" 'ファイル名 :L行番号' をヤンク/クリップボードのバッファにコピー
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:get_filename_with_line_number(s, e)
let result = expand("%:p")." :L".line(".")
if a:s == a:e
let @" = result
else
let result .= "\n===\n"
let result .= join(getline(a:s, a:e), "\n")
let @" = result."\n==="
endif

if has("gui_running")
let @* = @"
endif
endfunction
command! -range FL call s:get_filename_with_line_number(<line1>, <line2>)

2008年4月12日土曜日

SICP てきとー要約:1.1 The Elements of Programming

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html

強力なプログラム言語は、単なるコンピュータへの命令手段ではなく自分のアイデアをまとめるフレームワークでもある。そのため、プログラミングでは言語に用意されている単純なアイデアを複雑なアイデアに組み上げる仕組みについて意識すべきだ。強力といわれるあらゆる言語には 3 つの機構がある。
  • 最も単純な式
  • それを組み合わせる手段
  • また、それを抽象化する手段
プログラミングでは手続きとデータという 2 つの要素を扱い、強力なプログラム言語ではそれらを抽象化したり組み合わせたりできる。

この章では単純な数値データのルールについて説明する。

2008年4月7日月曜日

Redmineの工数詳細を100件に制限

工数登録が多くなると表示がかなり遅くなるので、
100 件で制限しておく。
全部表示したい場合は csv を指定すれば OK。

=====================================
app/controllers/timelog_controller.rb
=====================================

def details
sort_init 'spent_on', 'desc'
sort_update

####### 変更開始
#@entries = (@issue ? @issue : @project).time_entries.find(:all, :include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :order => sort_clause)
find_param = [:all, {:include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :order => sort_clause}]
if 'csv' != params[:export]
find_param[1][:limit] = 100
end
@entries = (@issue ? @issue : @project).time_entries.find(*find_param)
####### ここまで

@total_hours = @entries.inject(0) { |sum,entry| sum + entry.hours }
@owner_id = User.current.id

send_csv and return if 'csv' == params[:export]
render :action => 'details', :layout => false if request.xhr?
end

Redmineに工数確認機能を追加2

工数入力は同じ課題がしばらく続くことが多いので、
入力補助として履歴に最近入力した課題への工数入力のリンクを増やしてみた。

----------------------------------------
app/views/my/blocks/_hourhistories.rhtml
----------------------------------------
<h3>入力工数履歴</h3>

<ul>
<% sql =
"select user_id, spent_on, sum(hours) as day_hour" +
" from time_entries" +
" where user_id = #{user.id}" +
" group by spent_on" +
" order by spent_on desc" +
" limit 5"-%>
<% for entry in TimeEntry.find_by_sql(sql) %>
<li><%= "#{entry.spent_on}: #{entry.day_hour} h" %>
<% end %>
</ul>

<%= link_to "詳細", :controller => "man_hour" %>
<p>
<% sql =
"select distinct issue_id " +
" from time_entries" +
" where user_id = #{user.id}" +
" order by spent_on desc" +
" limit 10"-%>
<h3>最近工数入力した課題</h3>
<ul>
<% i = 0 %>
<% for entry in TimeEntry.find_by_sql(sql) %>
<% if entry.issue %>
<li>[<%= link_to '工数入力', :controller => 'timelog', :action => 'edit', :issue_id => entry.issue_id %>]
<%= link_to_issue entry.issue %> <%= entry.issue.subject %>
<% end %>
<% end %>
</ul>

2008年3月23日日曜日

SICP てきとー要約:Chapter 1 Building Abstractions with Procedures

英語読解能力がほぼ 0 な私が、はしょりながら SICP を読み解く第1弾。英語と Scheme とコンピュータを全て同時に学ぼうという無謀な挑戦。
(続くのか??)

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-9.html

computational process は data と呼ばれる”もの”を program と呼ばれる規則に沿って処理する。魔法と同じように見えないし触れないけど、実際に銀行や工場で computational process は動作している。

program を勉強するのは魔法と違って安全だけど、bug と呼ばれる小さなミスが原因で飛行機やダムの破滅的な崩壊を招いたり、工場のロボットが自爆してしまう可能性だってある。

software 技術の master は意図的に動作するようにプログラムする能力があり、うまく構造化することで思いがけない問題が発生しても破滅的な事態にならず、その問題を修正することができるのだ。

Programming in Lisp

本書では、Lisp という programming language を使用する。Lisp は 2 番目に古い言語ながらその柔軟性によって最も近代的な program design を備えている。Lisp には方言が多くあるのだが、その中でも Scheme と呼ばれる方言を使用する。

Lisp は主要言語とは言えないかもしれない。しかし、Lisp は procedure と呼ばれる処理の記述を data としても扱える。これはとても重要な特徴で、受け身な data と活動的な process の境界を曖昧にする強力な技法である。この特徴によって Lisp は我々が design 技法を探し求めるのに最も使える言語の一つとなっている。しかも Lisp の programming はとても楽しいのだ!


2008年1月15日火曜日

Redmineに機能追加(終了済み Issue をカレンダーで取り消し線)


--------------------------------
app/views/common/_calendar.rhtml
--------------------------------
<%= h("#{i.project.name} -") unless @project && @project == i.project %>
<%= link_to_issue i %>: <!-- 元の処理 %= h(truncate(i.subject, 30)) % -->
<!-- 追加開始 -->
<%= '<del>' if i.closed? %><%= h(truncate(i.subject, 30)) %><%= '</del>' if i.closed? %>
<!-- ここまで -->
<span class="tip"><%= render_issue_tooltip i %></span>

2008年1月14日月曜日

Redmineに工数確認機能を追加

Redmine で工数を入力できるけど、
日々の合計値や一覧がないので少し使いにくい。

なので簡単に機能追加。
#かなり adhoc だけどローカル用だしね。

試したのは redmine-0.6.3。


(1) まずはコントローラを追加
ruby script/generate cotroller man_hour


(2) 各ファイルを追記したり作成したり修正したり。

--------------------------------------
app/controllers/man_hour_controller.rb
--------------------------------------
class ManHourController < ApplicationController
layout 'base'

def index
@time_entries = TimeEntry.find(:all,
:conditions => ['spent_on > ?',
Time.now - 14.day],
:order => 'user_id, issue_id, spent_on')

@time_entries = [] if !@time_entries

respond_to do |format|
format.html
end
end

end

-----------------------------
app/views/man_hour/index.html
-----------------------------
<h1>入力工数一覧</h1>

<% start_day = Time.now - 13.day -%>
<table class="list">
<tr>
<th>メンバ</th><th>課題</th>
<% 14.times do |n| -%>
<th>
<!-- %= (start_day + n.day).strftime("%m/%d") % -->
<% d = (start_day + n.day) -%>
<%= "#{d.month}/" if d.day == 1 %>
<%= d.day %>
</th>
<% end -%>
</tr>
<% max = @time_entries.length -%>
<% i = 0 -%>
<% while i < max -%>
<% entry = @time_entries[i] -%>
<tr class="<%=cycle('odd', 'even') %>">
<td><%= entry.user.name %></td>
<td>[<%= entry.project.name %>] <%= entry.issue.subject if entry.issue %></td>
<% issue_id = entry.issue_id -%>
<% 14.times do |n| -%>
<% if entry && (issue_id == entry.issue_id) && (entry.spent_on.day == (start_day + n.day).day) -%>
<td>
<!-- %= entry.hours % -->
<% if entry.user_id == User.current.id -%>
<%= link_to entry.hours, :controller => "timelog", :action => "edit", :id => entry.id %>
<% else -%>
<%= entry.hours %>
<% end -%>
</td>
<% i = i.next -%>
<% entry = @time_entries[i] -%>
<% else -%>
<td></td>
<% end -%>
<% end -%>
</tr>
<% end -%>
</table>

----------------
config/routes.rb
----------------
map.connect 'man_hour/', :controller => 'man_hour', :action => 'index' # 追記

--------------------------------
app/controllers/my_controller.rb
--------------------------------
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
'issuesreportedbyme' => :label_reported_issues,
'issueswatched' => :label_watched_issues,
'news' => :label_news_latest,
'calendar' => :label_calendar,
'documents' => :label_document_plural,
'hourhistories' => '入力工数履歴' # UTF8 で追記
}.freeze

----------------------------------------
app/views/my/blocks/_hourhistories.rhtml
----------------------------------------
<h3>入力工数履歴</h3>

<ul>
<% sql =
"select user_id, spent_on, sum(hours) as day_hour" +
" from time_entries" +
" where user_id = #{user.id}" +
" group by spent_on" +
" order by spent_on desc" +
" limit 5"-%>
<% for entry in TimeEntry.find_by_sql(sql) %>
<li><%= "#{entry.spent_on}: #{entry.day_hour} h" %>
<% end %>
</ul>

<%= link_to "詳細", :controller => "man_hour" %>