Archive for the ‘Programing’ Category

プログラムのヘッダー表記

水曜日, 11月 12th, 2008

#!/usr/local/bin/perl
#
# 関連オブジェクトファイル削除コマンド
#   src配下の*.c,*.pcのファイルを検索
#   include文で指定したヘッダを利用しているファイルを抽出
#   obj配下の関連するオブジェクトファイルを削除
#
# ディレクトリ構成
#   $base_dir
#    ├src/ ソース格納用
#    ├inc/ ヘッダ格納用
#    └obj/ オブジェクト格納用
#

/****************************************

 * Outline   : 本関数は………の処理を行なう

 * Description : ――もうすこし詳細な説明を書く

 * Type    : BOOL

 * Args    : nErrCd OUT NUMBER

 *        ――ここに引数NUMBERの説明を書く

 *        vcErrStr OUT VARCHAR2

 *        ――ここに引数VARCHAR2の説明を書く

 * Note    : ――使用上の注意を書く

 * Date    : ――最初のバージョン完成日

 * Update   : ――更新日付1と更新理由1および更新者前1を書く

 *        ――更新日付2と更新理由2および更新者前2を書く

 *        ――更新日付3と更新理由3および更新者前3を書く

 *        ―― …

*****************************************/

Tags:
Posted in Programing | No Comments »

NetBeansでCakePHP参考サイト

火曜日, 11月 4th, 2008

最近NetBeansがよさげ+PHPにも対応したみたいなので試してみた – pirokyunの日記

Tags: ,
Posted in Programing | No Comments »

exerbとmkexy

金曜日, 10月 31st, 2008

Exerb – コマンドリファレンス

Tags: ,
Posted in Programing | No Comments »

WordPressでプログラムコードを記述

金曜日, 10月 31st, 2008

↓これが良さげ

ソースコードサンプル ≫ WordPress-コード表示用プラグイン[SyntaxHighlighter]

その他参考サイト
htmlやPHPなどのソースをBlogに表示する方法 | VIVABlog

Chameleon Cyber ≫ PHP Hilight String

MOVION.net ≫ WordPressでプログラムのソースコードをハイライト表示

Tags:
Posted in Programing | No Comments »

ファイルの行数数えて比較

金曜日, 10月 31st, 2008

count_max = Array.new

#ファイルを開いて行数を配列に追加
File.open(cybozu) { |file|
nil while file.gets
count_max << file.lineno
}

#ファイルを開いて行数を配列に追加
File.open(lv_moto) { |file|
nil while file.gets
count_max << file.lineno
}

#配列の中から大きい方をcount_motoに追加
count_moto = count_max.max

Tags:
Posted in Programing | No Comments »

csvファイルの読み込みと表示

火曜日, 10月 21st, 2008

require ‘csv’
CSV.open(“/temp/test.csv”, ‘r’) do |row|
puts row.join(“<>“)
end

Tags:
Posted in Programing | No Comments »

printとputsとp

火曜日, 10月 21st, 2008

違いを確認しておく

Tags:
Posted in Programing | No Comments »

restful_authenticationその2

火曜日, 8月 26th, 2008

■4. ジェネレータコマンド「authenticated」 が追加されるので、実行
activationもstateful も入れる

$ ./script/generate authenticated user sessions
-?include-activation
-?stateful

こんな感じ。

C:Documents and SettingsMiyaiMy DocumentsNetBeansProjectsrubyweblog>ruby sc
ript/generate authenticated user sessions –include-activation –stateful

———————————————————————-
Don’t forget to:

map.activate ‘/activate/:activation_code’, :controller => ‘users’, :action =
> ‘activate’

- add an observer to config/environment.rb
config.active_record.observers = :user_observer

Also, don’t forget to install the acts_as_state_machine plugin and set your reso
urce:

svn export http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/tr
unk vendor/plugins/acts_as_state_machine

In config/routes.rb:
map.resources :users, :member => { :suspend => :put, :unsuspend => :put, :purg
e => :delete }

Try these for some familiar login URLs if you like:

map.activate ‘/activate/:activation_code’, :controller => ‘users’, :action => ‘a
ctivate’, :activation_code => nil
map.signup ‘/signup’, :controller => ‘users’, :action => ‘new’
map.login ‘/login’, :controller => ‘sessions’, :action => ‘new’
map.logout ‘/logout’, :controller => ‘sessions’, :action => ‘destroy’

———————————————————————-

exists app/models/
exists app/controllers/
exists app/controllers/
exists app/helpers/
create app/views/sessions
create app/views/user_mailer
exists app/controllers/
exists app/helpers/
create app/views/users
exists test/functional/
exists test/functional/
exists test/unit/
create app/models/user.rb
create app/models/user_mailer.rb
create app/models/user_observer.rb
create app/controllers/sessions_controller.rb
create app/controllers/users_controller.rb
create lib/authenticated_system.rb
create lib/authenticated_test_helper.rb
create test/functional/sessions_controller_test.rb
create test/functional/users_controller_test.rb
create test/unit/user_test.rb
create test/unit/user_mailer_test.rb
create test/fixtures/users.yml
create app/helpers/sessions_helper.rb
create app/helpers/users_helper.rb
create app/views/sessions/new.html.erb
create app/views/users/new.html.erb
create app/views/user_mailer/activation.html.erb
create app/views/user_mailer/signup_notification.html.erb
create db/migrate
create db/migrate/20080825221326_create_users.rb
route map.resource :session
route map.resources :users

■5. acts_as_state_machine プラグインもインストール
activationとかstatefulとかに必要らしい。

$ ./script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk/

C:Documents and SettingsMiyaiMy DocumentsNetBeansProjectsrubyweblog>ruby sc
ript/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_mac
hine/trunk/
+ ./CHANGELOG
+ ./MIT-LICENSE
+ ./README
+ ./Rakefile
+ ./TODO
+ ./init.rb
+ ./lib/acts_as_state_machine.rb
+ ./test/acts_as_state_machine_test.rb
+ ./test/database.yml
+ ./test/fixtures/conversation.rb
+ ./test/fixtures/conversations.yml
+ ./test/fixtures/person.rb
+ ./test/schema.rb
+ ./test/test_helper.rb

C:Documents and SettingsMiyaiMy DocumentsNetBeansProjectsrubyweblog>

■6.migrate!(マイグレーション用ファイルは、上記のジェネレート時に設定済み)

netbeans上で、DBを最新化

(in C:/Documents and Settings/Miyai/My Documents/NetBeansProjects/rubyweblog)

== 20080825221326 CreateUsers: migrating ======================================

– create_table(“users”, {:force=>true})

-> 0.0160s

== 20080825221326 CreateUsers: migrated (0.0160s) =============================

ここでhp参照

http://localhost:3000/user/new

でルーティングエラー

よくわからんかったので、認証テスト用の簡易ブログを作成する事にする。

■この認証利用のためのscaffoldを準備

Post title:string content:text

migrateする

(in C:/Documents and Settings/Miyai/My Documents/NetBeansProjects/rubyweblog)
== 20080825222339 CreatePosts: migrating ======================================
– create_table(:posts)
-> 0.0470s
== 20080825222339 CreatePosts: migrated (0.0470s) =============================

app/controllers/sessions_controller.rb
を開いて、四行目の
include AuthenticatedSystem
をカットして保存。

同じフォルダ内にある
application.rb
を開いて
class ApplicationController < ActionController::Base
の内側にカットしたソースをペースト。

これでユーザ認証の機能が実装された。Railsではアクションごとにユーザ認証をかけるために「フィルタ」という仕組みを利用する。ユーザ認証はアクションを実行する前にフィルタを通す必要があるので「Before」フィルタを使う。

ユーザ認証をかけたい部分の***_controller.rb(この場合はapp/controllers/posts_controller.rb)というファイルを開き、二行目にそのフィルタを追記する。

before_filter :login_required, :except => [:index, :show]
※:exceptはオプションで、ここで指定されているindex(一覧ページ)は認証なしで閲覧可能になっている。

ここで、さっきのURLに間違いを発見

http://localhost:3000/users/new

で、いけた!

id,email,passwordを入力

http://localhost:3000/

に戻ってくる。登録できているのか?、ステータスは?
mysqlで確認

C:Documents and SettingsMiyaiMy DocumentsNetBeansProjectsrubyweblog>mysql -
u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql> use database rubyweblog_development;
ERROR 1049 (42000): Unknown database ‘database’
mysql> use rubyweblog_development;
Database changed
mysql> show tables;
+———————————-+
| Tables_in_rubyweblog_development |
+———————————-+
| posts |
| schema_migrations |
| users |
+———————————-+
3 rows in set (0.00 sec)

mysql> select * from users
-> ;
+—-+——–+—————–+——————————————+—-
————————————–+———————+——————-
–+—————-+—————————+——————————–
———-+————–+———+————+
| id | login | email | crypted_password | sal
t | created_at | updated_at
| remember_token | remember_token_expires_at | activation_code
| activated_at | state | deleted_at |
+—-+——–+—————–+——————————————+—-
————————————–+———————+——————-
–+—————-+—————————+——————————–
———-+————–+———+————+
| 1 | tmiyai | takuya@miyai.jp | fc9f16b6bc098badff9347916241545135da9324 | e98
8284bddeb979e4cf87e54a669c0932454fcd2 | 2008-08-25 22:34:10 | 2008-08-25 22:34:1
0 | NULL | NULL | a9c735a91ac344ef39fc849e0e3c359
71854c94f | NULL | pending | NULL |
+—-+——–+—————–+——————————————+—-
————————————–+———————+——————-
–+—————-+—————————+——————————–
———-+————–+———+————+
1 row in set (0.00 sec)

mysql> select login, state from users;
+——–+———+
| login | state |
+——–+———+
| tmiyai | pending |
+——–+———+
1 row in set (0.00 sec)

mysql>

以下を、routes.rbに追加
activateするために必要らしい。

map.connect “activate/:activation_code”, :controller => “users”, :action => “activate”

この辺でよくわからなくなってくる。

てらじろぐ | restful_authentication でメール認証するぞ

restful_authenticationの設定 – べるべる研究日誌

ザリガニが見ていた…。

この辺を見て、再トライだな。。。

Tags:
Posted in Programing | No Comments »

Lenovo note NetBeans開発環境

日曜日, 8月 24th, 2008

Lenovo note NetBeans開発環境

ruby インストール
・One-Click Ruby
ruby186-26.exe

システム環境変数の”path”に追加
;C:\ruby\bin

・MySQL
mysql-essential-5.0.51b-win32.msi

default character を utf8 に変更
Include Bin Directory in Windows PATHにチェックオン

・Rails
gemsでインストール

> gem install rails

c:\ruby>gem install rails
Bulk updating Gem source index for: http://gems.rubyforge.org
Install required dependency rake? [Yn] Y
Install required dependency activesupport? [Yn] Y
Install required dependency activerecord? [Yn] Y
Install required dependency actionpack? [Yn] Y
Install required dependency actionmailer? [Yn] Y
Install required dependency activeresource? [Yn] Y
Successfully installed rails-2.1.0
Successfully installed rake-0.8.1
Successfully installed activesupport-2.1.0
Successfully installed activerecord-2.1.0
Successfully installed actionpack-2.1.0
Successfully installed actionmailer-2.1.0
Successfully installed activeresource-2.1.0
Installing ri documentation for rake-0.8.1…
Installing ri documentation for activesupport-2.1.0…
Installing ri documentation for activerecord-2.1.0…
Installing ri documentation for actionpack-2.1.0…
Installing ri documentation for actionmailer-2.1.0…
Installing ri documentation for activeresource-2.1.0…
Installing RDoc documentation for rake-0.8.1…
Installing RDoc documentation for activesupport-2.1.0…
Installing RDoc documentation for activerecord-2.1.0…
Installing RDoc documentation for actionpack-2.1.0…
Installing RDoc documentation for actionmailer-2.1.0…
Installing RDoc documentation for activeresource-2.1.0…

c:\ruby>gem install rails
Successfully installed rails-2.1.0

インストール許可を省略する際には”-y”オプション
> gem install rails -y

1.2系をインストールする場合は以下参照

> gem install rails –version=”1.2.6″ -y

C:\Documents and Settings\Miyai>mysql –version
mysql Ver 14.12 Distrib 5.0.51b, for Win32 (ia32)

C:\Documents and Settings\Miyai>rails -v
Rails 2.1.0

C:\Documents and Settings\Miyai>ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

・NetBeansインストール
JDKが必要

http://java.sun.com/j2se/1.5.0/ja/download.html

netbeans-6.1-ml-ruby-windows.exe
※mlはマルチランゲージの事。日本語版を含みます。

チュートリアル

http://www.netbeans.org/kb/60/ruby/rapid-ruby-weblog_ja.html

■なぜか、データベースが作成できない。
C:\Documents and Settings\Miyai>mysqladmin -u root -p create rubyweblog_developm
ent
Enter password: ********
mysqladmin: CREATE DATABASE failed; error: ‘Can’t create database ‘rubyweblog_de
velopment’; database exists’

C:\Documents and Settings\Miyai>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> quit;
Bye

C:\Documents and Settings\Miyai>mysqladmin -u root -p create rubyweblog_developm
ent
Enter password: ********
mysqladmin: CREATE DATABASE failed; error: ‘Can’t create database ‘rubyweblog_de
velopment’; database exists’

C:\Documents and Settings\Miyai>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> quit;
Bye

C:\Documents and Settings\Miyai>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> create database rubyweblog_development;
ERROR 1007 (HY000): Can’t create database ‘rubyweblog_development’; database exi
sts

■どうやら同名のデータベースがある模様。(アンインストール失敗していた?)
mysql> show databases;
+————————+
| Database |
+————————+
| information_schema |
| depot_development |
| mysql |
| rubyweblog_development |
| test |
+————————+
5 rows in set (0.23 sec)

■不要なデータベースを削除
mysql> drop database depot_development;
Query OK, 2 rows affected (0.33 sec)

mysql> drop database rubyweblog_development;
Query OK, 0 rows affected (0.00 sec)

mysql> drop database test;
Query OK, 0 rows affected (0.02 sec)

mysql> quit;
Bye

■無事作成できた。
C:\Documents and Settings\Miyai>mysqladmin -u root -p create rubyweblog_development
Enter password: ********

C:\Documents and Settings\Miyai>

■しかし、チュートリアルどおり進まない。
rails1.2系と、rails2.0系の違い

教えて! Watch Ruby on Rails について

http://oshiete1.watch.impress.co.jp/qa4070054.html

始める。 ・テンプレートファイルの名称がXXX.rhtmlからXXX.html.erbに変更 ってとこです。

http://yamamoto.xrea.jp/2008/02/ruby-on-rails-20scaffold.php

——————————————————-
1.railsコマンドでひな形を作成
※rails2.0ではデフォルトのDBがSQLite3なので、mysqlで使う場合は”-d mysql”オプションが必要かもです。
2.database.ymlを修正
3.おもむろにscaffold実行
ruby script/generate scaffold pepole name:string age:integer
4.dbにデータベースを作る
5.mygrateする
rake db:migrate
6.serverをスタートする
——————————————————-

NetBeansのチュートリアル手順を改造するとこんな感じか
——————————————————-
1.db内にデータベース作成する。
2.初期ウィザードで、Mysql指定(これでdatabase.ymlも自動生成)
3.scaffold生成
4.mygrationファイル修正
5.mygrate
6.実行!
——————————————————-

明日やってみる。

Tags: , ,
Posted in Programing | No Comments »

plugin管理ツール

金曜日, 8月 22nd, 2008

RaPT: Railsプラグイン管理ツール – Hello, world! – s21g

Tags:
Posted in Programing | No Comments »

Get Adobe Flash playerPlugin by wpburn.com wordpress themes