#!/usr/bin/env ruby # -*- coding: euc-jp -*- require 'pstore' require 'cgi' class ErrorMsg < RuntimeError end def redirect print "Status: 302 Moved Temporary\n" print "Location: http://shinh.skr.jp/yomikata/\n\n" end def can_vote(e) e.each do |i| return false if i[4].index(@ip) end true end def do_vote(e, yi) e = e[1] if !can_vote(e) raise ErrorMsg.new('あなたは既に投票してます') end e[yi][1] += 1 e[yi][4].push(@ip) sum = e.inject(0) {|r, i| r + i[1]} e.each do |i| i[2] = 100 * i[1] / sum i[3] = "#" * (i[2] / 5) + " " * (20 - i[2] / 5) end end def print_vote(e, ei) (word, res) = e print %Q(
) res.each_with_index do |r, i| print %Q() end print %Q(
#{CGI.escapeHTML(r[0])}  #{r[1]}票#{r[2]}%#{r[3]}
) end q = CGI.new db = PStore.new('enq.db') @ip = ENV['REMOTE_ADDR'] head = "Content-Type: text/html; charset=EUC-JP\n\n" headered = false begin if ENV['REQUEST_METHOD'] == 'POST' if q.key?('ajax') wi = q['wi'].to_i yi = q['yi'].to_i db.transaction do a = db['root'] e = a[a.size-wi] do_vote(e, yi) print head print_vote(e, a.size - wi) end exit(0) end word = q['word'].to_s if word == '' raise ErrorMsg.new('なんか入力がカラですよ') end if q.key?('addword') db.transaction do a = db['root'] if word =~ /http:\/\// raise ErrorMsg.new('URLはスパム扱いするっす') end if a.assoc(word) raise ErrorMsg.new("#{word}は既に登録されてる単語ですよ") end a.unshift([word, []]) end redirect elsif q.key?('addyomi') yomi = q['yomi'].to_s db.transaction do a = db['root'] e = a.assoc(word) if yomi == '' raise ErrorMsg.new('なんか入力がカラですよ') end if yomi =~ /http:\/\// raise ErrorMsg.new('URLはスパム扱いするっす') end if !e raise ErrorMsg.new("なにやらヘンなエラー") end e = e[1] if e.assoc(yomi) raise ErrorMsg.new("#{yomi}は既に登録されている読み方ですよ") end e.push([yomi, 0, 0, " "*20, [], []]) end redirect elsif q.key?('vote') if !q.keys.find {|i| i =~ /vote_(\d+)/} raise ErrorMsg.new('存在しない投票先っす') end vote = $1.to_i db.transaction do a = db['root'] e = a.assoc(word) if !e raise ErrorMsg.new("なにやらヘンなエラー") end do_vote(e, vote) end redirect end else print head headered = true print %Q( よみかたあんけーと

よみかたあんけーと

気が向いたら以下の単語の読み方のアンケートに協力して下さい。 自分がその読み方をしてなくても読み方を 追加してもらっていいです。 読み方はなるべくひらがなで記述して下さい。 一つの IP で 1回だけ投票できます。 単語増やすのも歓迎です。 このシステムのソースコードは GPL2 で。 アンケートに答えてくれた人には ごほうびにマイノリティ度チェックを。 ) db.transaction(true) do db['root'].each_with_index do |e, ei| (word, res) = e print %Q(

#{CGI.escapeHTML(word)}

) if res.empty? print %Q(

まだ投票項目が無いです

) else print %Q(
) print_vote(e, db['root'].size - ei) print %Q(
) end print %Q(
) end end print %Q(

単語を増やす

以下からアンケート単語を増やせます。


home / index

全てリンクフリーです。 コード片は自由に使用していただいて構いません。 その他のものはGPL扱いであればあらゆる使用に関して文句は言いません。 なにかあれば下記メールアドレスへ。

hamaji _at_ nii.ac.jp / shinichiro.h
) end rescue ErrorMsg if (!headered) print head + "\r\n" end print "ERROR: #{$!}" rescue if (!headered) print head + "\r\n" end print "
\n"
  print CGI.escapeHTML("#{$!.to_s}\n")
  print CGI.escapeHTML("#{$!.backtrace.join("\n")}\n")
  print "
\n" end