Monday, November 30, 2009

Ruby1.9 encoding

SinatraがRuby1.9に対応したので早々UPGrade
しかし1.9のエンコードがうまくいかない
原因はRackのParamsからのリターンがASCII-8BITになってしまうため

Patent.rbではファイルストリングがUTF-8か判断して
そうでないときはSJISと解釈してforce_encodingし
さらにUTF-8にencodeし
一方でUTF-8の時はUTF-8にforce_encodingする

    def conv_to_utf8_string(filename)
        str = IO.read(filename) rescue filename
        if str.utf8?
            # should force encoding: Rack bug which params badly return ASCII-8BIT
            str.force_encoding('UTF-8')
        else
            str.force_encoding('SJIS').encode('UTF-8').gsub("\r", "")
        end
    end

File encoding sjis to utf8

入力ファイルがUTF-8でない場合
SJISと判断してUTF-8に変換
 
#!/usr/bin/env ruby
# encoding: utf-8

class String
    def utf8?
        unpack('U*') rescue return false
        true
    end
end

f1 = '/Users/keyes/Desktop/utf8.txt'
f2 = '/Users/keyes/Desktop/sjis.txt'

pfs = [f1, f2]
pfs.map! do |f|
    if File.open(f).gets.utf8?
        File.open(f, 'r')
    else
        File.open(f, "r:sjis:utf-8")
    end
end

pfs.each do |pf|
    puts pf.read
end


Sunday, November 29, 2009

Ajax Upload

in html
    #upload_button Upload

in javascript
    new AjaxUpload('#upload_button', {
        action: '/',
        name: 'file',
        autoSubmit: true
    });

in controller

params[:file][:tempfile]

Wednesday, November 25, 2009

RMagic memory leak

image_shrink.rbでRMagickを使ってる
それで大量の画像を渡すとメモリーが解放されず
処理が著しく低下するというバグがあるみたいだ
で対応としてGCを強制的に作動させる
def run_gc
  fDisabled  = GC.enable
  GC.start
  GC.disable if fDisabled
end
を各RMagickの処理のあとに呼ぶ

Thursday, November 19, 2009

明細書作成支援Webアプリ

なかなかの調子で進行中
が、リナンバリングでつまづく
やはりデータベースでの管理が必要か
結局サーバー側とクライアント側のデータ受け渡しが厄介だ
例えば、クライアント側でデータを書き換えて
その結果に基づいて処理を行う場合
クライアント側からデータをサーバーに渡し
サーバー側で処理してまたクライアントに渡さなければならない

サーバーとクライアント側でRubyを走らせて
DRubyでオブジェクトをそのまま渡せたらどんなにか便利だろうに

その場で

その場で編集が実装できるjQueryのプラグインjeditable.js
      $(".editable_textarea").editable("http://localhost:4567/save", {
          indicator : "<img src='../img/indicator.gif'>",
          type   : 'textarea',
          submitdata: { _method: "put" },
          select : false,
          submit : 'OK',
          cancel : 'cancel',
          cssclass : "editable"
      });

dataの受け取りは、params[:name], params[:value]で

Wednesday, November 18, 2009

Firefox3.6beta + nightly build tools add-on

vimp doesn't work on firefox3.6b.
but with nightly build tool addon, it works fine.
after the tool work, then disable the tool. it start working.
but i can't use ime for this.??

install Scala

  1. www.scala-lang.orgからDLして解凍
  2. mv scala/ /usr/local/
  3. add followings to .zshrc

export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/opt/local/bin:/opt/local/sbin:/opt/local/lib/:.:$HOME/Dropbox/lib:$SCALA_HOME/bin:$PATH"
export SCALA_HOME="/usr/local/scala"


http://www.paradox1x.org/archives/2009/06/very-quick-star.shtml

Sunday, November 15, 2009

grep in vim

:vimgrep /【......*】/j *.pat
:copen

Saturday, November 14, 2009

jQuery checkbox + getJSON

jquery
  $('#go_btn').click(function(event){
    var params = [];
    $("input:checkbox[name='selector']:checked").each(function(){
      params.push($(this).val());
    });
    $.getJSON('/results/'+params.join(':'), function(json){
      $('#results').html("<p>"+json.evalclaims+"</p>"+"<p>"+json.claims+"</p>");
    });
  });    

controller
get '/results/:params' do |params|
  redirect '/' unless request.xhr?
  requests = params.split(':')
  q = {}
  unless requests.empty?
    pf = PatentFile.new('./public/tmpfile')
    requests.each do |res|
      case res
      when 'evalclaims'
        q[:evalclaims] = pf.eval_claims_with_statics.last[:claims]
      when 'claims'
        q[:claims] = pf.claims 1
      end
    end
  end
  content_type :json
  {:evalclaims => q[:evalclaims], :claims => q[:claims]}.to_json
end

Sinatra File Upload

controller
    if params[:file]
    path = './public/tmpfile'
    File.open(path,'w'){ |f| f.write(params[:file][:tempfile].read) }
    @original = File.open(path).read
    end

view
    %form{:action=>'/', :method=>'post', :enctype=>'multipart/form-data'}
      %input{:type=>'file', :name=>'file'}
      %input{:type=>'submit', :value=>'POST'}

Tuesday, November 10, 2009

data backupの手順

  1. backup_coosamac.sh
  2. backup_eggmac.sh
  3. backup_keyesmac.sh
  4. backup_bigmac.sh

backup_keyesmac.sh
rsync -avz -e ssh --delete --exclude 'Library/Caches/' --exclude '.Trash' /Users/keyes/ /Volumes/BIGMAC/backups/keyesmac/

backup_bigmac.sh
rsync -avz -e ssh --delete --exclude '.*' --exclude 'Desktop*' --exclude 'backups/' /Volumes/BIGMAC/ coosa@192.168.1.5:/Volumes/EGGMAC/backups/keyesmac/

backup_coosamac.sh
rsync -avz -e ssh --delete --exclude 'Library/Caches/' --exclude '.Trash' /Users/coosa/ /Volumes/EGGMAC/backups/coosamac/

backup_eggmac.sh
rsync -avz -e ssh --delete --exclude '.*' --exclude 'Desktop*' --exclude 'backups/' /Volumes/EGGMAC/ keyes@192.168.1.3:/Volumes/BIGMAC/backups/coosamac/

外付けHDD購入 -> DELL PC処分

巨大なDELL PCを遂に処分する方向でプロジェクト進行中
  1. まずはAmazonで外付けHDD(IO Data HDCN-500A)を8,600円で購入
  2. データのバックアップ。さち、バックアップ中にHDD蹴り倒す!信じがたい事故発生。しかしHDD奇跡的に無事
  3. DELLを撤去
  4. ついでにシュレッダーも一時倉庫に退去
  5. コードの一部とUPSをキャビネットの裏に隠して足下すっきり
DELLは当初裏の中古屋にタダで引き取ってもらうつもりだったけど
ヤフオクみたら売れるかもということでそちらに挑戦予定
WinXPインストール済


Blogger.vim

vim からBloggerに投稿できるBlogger.vimという素晴らしいツールがある
これを使うためにGHCとかいろんなものをインストールしたんだけど
どうもうまく動かない
ruby create ....
はうまくいくんだけど

とりあえず断念する

Sunday, November 08, 2009

Software Idea

Software Idea Note

1.explore: display only selected directories and file types.

2.editor for patent application creator:
    -devide a file to a specification and an abstract
    -auto numbaring
    -criteria checker for submission to JPO
    -parts number extractor from specificaton to parts list
    -template provider
    -word counter
    -DOC formated file as default save file
    -view by [0000]
    -parts number viewer

3.Auto Dialer: stay an icon in notification area of Win95
        -by click the icon, name list appear
        -by select a name, the number will be call up

4.Mouse Pointer Mover: with shift+arrow keys, move mouse pointer freely.
5.Trump Game:A set of 52cards, only do shaffle, hand out cards.
             network battle type game. user can play any card games as
             they do on real cards.
6.atomosphere utility: whether in a PC changes, rain, snow, shine...
            background of work

7.Patesuke Next Version
 -Color astarisk for type of schedule
 -Move date on shedule input dialog
 -Display & print a list of schedules
 -Jump date
 -Input birthday for alarming
 -

8.Inshi Adminislator

9.method for eliminating data or program on a medium.

10.correction for data read by OCR
 - replace very rare words or characters, ie.ぱ
 - replace to very frequent words

11.WZ macro :converter for JPO format from txt
 -auto conv 1mm2,mm3,O2,O3,H2O etc. to upper or lower case

旅の記録

旅の記録
93.06 2wks  Australia  sydney:ANA hotel-adelade:Hilton-perth-bloom:honeymoon
94.04 3wks  USA        oregon-san francisco-paloalto-yosemite-monterey-carmel
95.01 5days USA        L.A.:hollywood-bevery hills:beverywillshier-santa monica
96.10.09-14 Bali       Nusadua:grand hyatt-jimbaran-ubudo
97.07.16-22 Hawaii     Hawaii Island:four seasons
98.07.15-22 Hawaii     Maui Island:a condo
99.03.25-28 Hong Kong  C.W.Mariott
99.07.10-18 USA        LasVegas:Belargio-Oafu Island:Kahara Mandarin
00.02.10-15 Philipin   Pamalican Island:Amanpulo

Accomodations at Jourey in 2002

Our Journey in 2002

Priod
July 04 – Dec 24, 2002, 175days
Destinations
Singapore : 10 days
Indonesia : 1 day
Thailand : 7 days
Malaysia : 13 days
Australia : 72 days
New Zealand : 70 days
Number of Accommodations
53 accommodations
D. Itinerary
04 July    NRT-Singapore            Singapore Airline
07 July    Singapore-Bintan Is.        Ferry
08 July    Bintan Is.-Singapore        Ferry
08 July    Singapore-Bangkok        Singapore Airline
15 July    Bangkok-Singapore        Singapore Airline
16 July    Singapore-Malacca        Express Bus
20 July    Malacca-Kuala Lumpur        Express Bus
29 July    Kuala Lumpur-Singapore        Express Train
04 Aug    Singapore-Brisbane        Singapore Airline
06 Sep    Brisbane-Perth            Qantas
12 Sep    Perth-Coral Bay            Car
18 Sep    Coral Bay-Perth            Car
25 Sep    Perth-Sydney            Virgin Blue Airline
15 Oct    Sydney-Auckland        Air New Zealand
14 Nov    Wellington-Picton        Linx Ferry
12 Dec    Picton-Wellington        Linx Ferry
23 Dec    Auckland-Brisbane        Air New Zealand
24 Dec    Brisbane-Singapore        Singapore Airline
25 Dec    Singapore-NRT            Singapore Airline

Things to do
Golf 8 times
Fry Fishing 3 times
Beaches 10 times(Snorkeling 4 times, Surfing & Bogie Board 2 times)
Pools 10 times
Luge 1 time
Hot Springs 2 times
Casino 17 times
Car Hire 4 times

Cost
 \2,500,000
Accommodations
Orchard Parade Hotel    04-06 July    Singapore
Bintan Lagoon Resort    07 July        Bintan Is. , Indonesia
Le Meridian Hotel        08-14 July    Bangkok, Thailand
The Comfort Hotel    15 July        Singapore
Mimosa Hotel        16-19 July    Malacca, Malaysia
Plaza Hotel        20 July        Kuala Lumpur, Malaysia
Concord Hotel        21-28 July    Kuala Lumpur, Malaysia
Sweeny's House        29 July-03 Aug    Singapore
Hotel Mercure        05-08 Aug    Brisbane, QLD, Australia
Montepellier        09-24 Aug    Noosa, QLD, Australia
Curts Falls Lodge        25 Aug        Tamborine, QLD, Australia
Regends Hotel        26-29 Aug    Gold Coast, QLD, Australia
Hotel Grand Chancellor    30 Aug        Brisbane, QLD, Australia
Hotel George Williams    31 Aug        Brisbane, QLD, Australia
James St. Motor Inn    01-02 Sep    Toowoomba, QLD, Australia
Manly Hotel        03 Sep        Manly, QLD, Australia
Hotel George Williams    04-05 Sep    Brisbane, QLD, Australia
Holiday Inn        06-08 Sep    Perth, WA, Australia
Kings Hotel        09-11 Sep    Perth, WA, Australia
Best Western Carnarvon    12 Sep        Carnarvon, WA, Australia
Ningaloo Reef Resort    13-16 Sep    Coral Bay, WA, Australia
Best Western Geraldton    17 Sep        Geraldton, WA, Australia
Kings Hotel        18-23 Sep    Perth, WA, Australia
Oakford Darling Harbor    25 Sep-08 Oct    Sydney, NSW, Australia
O'baoill's House        09-12 Oct    Schofeilds, NSW, Australia
Pacific International Inn    13-14 Oct    Sydney, NSW, Australia
Madion on the Square    15-21 Oct    Auckland, Nth, New Zealand
Baylys Motor Park        22-24 Oct    Dargaville, Nth, New Zealand
Omapere Motel        25 Oct        Omapere, Nth, New Zealand
Kauri Park Motel        26-29 Oct    Kerikeri, Nth, New Zealand
Top 10 Orere Point     30 Oct        Orere Point, Nth, New Zealand
Top 10 Papamoa Beach    31 Oct-02 Nov    Papamoa Beach, Nth, New Zealand
Ann's Volcanic Rotorua    03-04 Nov    Rotorua, Nth, New Zealand
Top 10 Lake Taupo    05-11 Nov    Taupo, Nth, New Zealand
747 Motel        12-13 Nov    Wellington, Nth, New Zealand
Blue Seas Motel        14 Nov        Kaikoura, Sth, New Zealand
City Worcester Motel    15 Nov        Christchurch, Sth, New Zealand
Milano Motor Lodge    16-19 Nov    Christchurch, Sth, New Zealand
Tekapo House        20 Nov        Lake Tekapo, Sth, New Zealand
The Heritage Queenstown    21-22 Nov    Queenstown, Sth, New Zealand
Milano Motor Lodge    23-27 Nov    Christchurch, Sth, New Zealand
The Heritage Queenstown    28-29 Nov    Queenstown, Sth, New Zealand
Garden Court Apartments    30 Nov        Queenstown, Sth, New Zealand
Milano Motor Lodge    01-02 Dec    Christchurch, Sth, New Zealand
Settlers Inn Motel        03-04 Dec    Hammer Springs, Sth, New Zealand
Mapua Leisure Park    05 Dec        Mapua, Sth, New Zealand
Equestrian Lodge        06 Dec        Motueka, Sth, New Zealand
Lugano Motor Lodge    07-11 Dec    Blenheim, Sth, New Zealand
Camelot Motor Lodge    12 Dec        Palmerstone North, Nth, New Zealand
Top 10 Kennedy Park    13-14 Dec    Napier, Nth, New Zealand
Top 10 Lake Taupo    15-18 Dec    Taupo, Nth, New Zealand
Top 10 Papamoa Beach    19-22 Dec    Papamoa Beach, Nth, New Zealand
Airport Travel Air Motor Inn 23 Dec        Auckland, Nth, New Zealand

古いレコードのリスト

LP
井上陽水 氷の世界 1000
中島みゆき 中島みゆき 1000以下
荒井由実 ひこうき雲 1000以下
松任谷由実 Diamond Dust
松任谷由実 No Side
松任谷由実 DADIDA
松任谷由実 ALARM a la mode
原ゆうこ はらゆうこが語るひととき
グレープ 三年坂
石川優子 Love Feeling

Beatles HELP
Beatles sgt peppers lonely hearts club band
John Lennon Double Fantasy
John Lennon ジョンの魂
Wings Venus and Mars
Wings At the Speed of Sound
Paul McCartney Tug of War
Derek and The Dominos LAYLA
Mountain Flowers of Evil
Lee Ritenour RIT
Michael Jackson Thrieler
Michael Jackson BAD

Berlin Phil Karajan Dvorak Symphony No.9(5) From the New World
Furtwangler Beethoven Symphony No.5&9
冨田勲 惑星

小池一也とワゴンマスターズ テキサスの黄色いバラ/荒野の呼声
三橋美智也 ああ新撰組/照菊:幾松小唄
島倉千代子 りんどう峠/布良の娘
日本民謡全集

SP
小泉今日子 ひとり街角
安全地帯 ワインレッドの心
井上陽水 Bright Eyes
桜田淳子 ウィスパーカード
村下孝蔵 春雨

一節太郎 一発節
三沢あけみ 街角
坂本九 GIブルース/砂漠の恋の物語
吉永小百合 明日の花嫁/いつでも夢を
山田太郎 帰ろう心のふるさとへ/幸福はこだまする

Beatles Long tall sally / I call your name


Friday, November 06, 2009

Railsが動いた

Rubyのバージョンがいけなかった
_ruby script/server
とすればよかった

ひさびさのRailsに困惑

ちょっと前に作った特許関係のアプリを見てみようと
Railsファイルを開いたんだけど
久しぶりすぎて起動方法すら忘れていてビックリ

でRails2.3.4ということでやはりうまく動かない
Rubyも1.9だし

  1. config/environment.rbのヴァージョンを2.3.4に
  2. rake rails:update
  3. development.rbのcache関連の一行を削除
とやったけどだめだ

Sunday, November 01, 2009

youtube -> mp3

safari stand cmd+click -> flv
extractmp3 flv -> mp3