2012年12月11日火曜日

VC2010で.NetFrameworkのバージョンを2.0に変更する

VisualStudio2010で
C++/CLIで.NetFrameworkのバージョンを2.0に変更したかったのですが、
C#はUIで設定できるのにC++はUIで変更は出来ないようです。
(頑張ってUIを探してみたけど見つかりませんでした。。)

検索したら、MSDNに載ってました。
http://msdn.microsoft.com/ja-jp/library/ff770576(v=vs.100).aspx
.vcxprojを直接編集するしかないみたい。

以下のタグの値を変更すればOKとのこと。
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

早速エディタで.vcxprojを開いてみましたが。。。
TargetFrameworkVersionのタグがない!!

それっぽいタグの中に追加。
<PropertyGroup Label="Globals">
  <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>

無事C++/CLIのプロジェクトのプロパティで対象フレームワークにv2.0と表示されました!

早速ビルドしてみると。。。
エラー。
----

error MSB8009: .NET Framework 2.0/3.0/3.5 は、v90 のプラットフォーム ツールセットを対象としています。コンピューターに Visual Studio 2008 がインストールされていることを確認してください。
----
なんという!

VisualStudio2008をインストールするとちゃんとビルドできました。

非常に面倒ですね。GUIで変更できないだけでなく、
古いバージョンのVisualStudioが必要とか。
何とかならないもんですかねぇ~。


2012年12月7日金曜日

文字列に特定の文字が含まれているのをチェックする


バッチファイルで文字列に特定の文字が含まれているのをチェックする方法です。

例:

echo aaa bbb|findstr /C:" ">NUL
if not ERRORLEVEL 1 echo ok




例:バッチファイルを実行したパス(フォルダ)に半角スペースがあるかを調べる

echo %~dp0|findstr /C:" ">NUL
if not ERRORLEVEL 1 echo ok



2012年11月14日水曜日

C# .NET2.0で使えるParserクラスを作ってみた。

HaskellのParsecに触発されて、
C# .NET2.0で使えるParserクラスを作ってみた。


https://github.com/mezashi184/Parq


サンプル
----

   Parser parser = CharParser.Range('0', '9');
   using (StringSource source = new StringSource("012"))
   {
      Assert.That(parser.Run(source), Is.EqualTo('0'));
   }
----



2012年9月1日土曜日

C++/CLIでIEnumerableを実装してみる。


サクッと実装する予定が"明示的なオーバーライド"ではまってしまったので、
残しておきます。


以下のように実装クラスを書いてコンパイル!
public ref class SampleList:public System::Collections::Generic::IEnumerable
{
public :
    virtual System::Collections::Generic::IEnumerator^ GetEnumerator() { return nullptr; }
    virtual System::Collections::IEnumerator^ System::Collections::IEnumerable::GetEnumerator() { return GetEnumerator(); }
};


すると。

エラー、エラー、エラー。。。。

error C3253: 'IEnumerable.GetEnumerator' : 明示的なオーバーライドでエラーが発生しました
error C2838: 'IEnumerable.GetEnumerator' : メンバ宣言内の限定名が間違っています。
error C3648: この明示的なオーバーライド構文には /clr:oldSyntax が必要です


明示的なオーバーライドは /clr オプションでは出来ないみたい。


調べるとMSDNさんにありました。
関数のオーバーライドを別の関数名にして実装が出来るとのこと。
http://msdn.microsoft.com/ja-jp/library/fw0bbh51(v=vs.80).aspx

これで書きなおしたのがこれ!
public ref class SampleList:public System::Collections::Generic::IEnumerable
{
public :
virtual System::Collections::Generic::IEnumerator^ GetEnumerator() { return gcnew Iterator(); }
virtual System::Collections::IEnumerator^ GetEnumeratorImpl() =System::Collections::IEnumerable::GetEnumerator { return GetEnumerator(); }
};


■参考サイト。
http://msdn.microsoft.com/en-us/library/fw0bbh51(v=vs.80).aspx


■おまけIEnumeratorの実装。
ref class Iterator : System::Collections::Generic::IEnumerator
{
    int i;
public:
Iterator()
{
i = -1;
}
virtual ~Iterator()
{
}


property virtual int Current
{
int get()
{
return i;
}
}
virtual System::Object^ CurrentImpl() = System::Collections::IEnumerator::Current::get
{
return Current;
}
virtual void Reset() = System::Collections::IEnumerator::Reset
{
throw gcnew NotImplementedException();
}


virtual bool MoveNext()
{
i++;
return i;
}


};



2012年8月10日金曜日

CentOSでcronの設定

定期的に処理をしたかったので、cronの設定を調べました。


cronの設定を編集する。
# crontab -e
* * * * * 実行するコマンド
例:毎時0分に実行する。
0 * * * * echo test
参考:


Windows で VMWareServer をコマンドラインで操作する。



検索してもLinuxでの情報しか出てこないんですよね。。。
Linuxでは /usr/bin/ に入っているみたいで、vmware-cmdとかいう名前だそうな。

Windowsでは残念ながらLinuxと同じ名称のファイルは存在せず。。
で、とにかく色々とexeを叩いてたらみつけました!

vmrun.exeというファイルです。

例:
C:\Program Files (x86)\VMware\VMware Server\vmrun.exe

vmrun.exeを実行するとヘルプが表示されます。
ヘルプをみながらゴニョゴニョ。

■VMの起動
start コマンド

vmrun.exe -T server -u user -p password -h https://localhost:8333/sdk  start "[standard] myvm\myvm.vmx"



オプションが長い。。。



2012年7月11日水曜日

Bazaarでファイル名を変更する。


エクスプローラで名前を変更してしまうと。
BazaarExplorerで見た時に削除と追加になってしまい。
今までの履歴を引き継ぐことが出来ない。

調べてみると。
BazaarExplorerの作業ツリーで名前を変更すると、
ファイル名やフォルダ名の変更扱いとなり、
履歴を引き継ぐ事ができます。


が、
Visual Studio上でファイル名を変更してしまうと、
エクスプローラ同様に追加と削除になってしまう。

履歴を引き継ぐためにはプロジェクトファイルとファイル名を、
手動で変更する必要がある。
非常に面倒。。。。




発見!

bzrにmvというコマンドがありました。
bzr mv --auto
でエクスプローラやVisualStudio上で変更しても履歴を引き継げるようになります。

フォルダ名を変更した場合は。
bzr add でフォルダを追加する必要があり。



参考サイト:
http://kashfarooq.wordpress.com/2009/09/21/renaming-files-with-bazaar-source-control/



2012年7月4日水曜日

iGoogleがもう少しで廃止だそうな。

iGoogleは2013 年 11 月 1 日で廃止だそうです。


私自身はよく使っていたので、代わりになるアドインなんかを探さないといけないですね。


http://support.google.com/websearch/bin/answer.py?hl=ja&answer=2664197

2012年7月3日火曜日

centos で windows共有フォルダにアクセスする。


Windowsの共有フォルダにデータのバックアップを取りたかったので、
調べた結果を残しておきます。

共有フォルダをディレクトリに割り当てる。
mount -t cifs -o username=xxxxx,password=xxxxx //hostname/share /var/share

割り当てを解除する。
umount /var/share

が!
ビジー状態とかで解除出来なかった。。。

その場合は以下のように強制的に解除する。
umount -l /var/share



2012年7月2日月曜日

バッチファイルでフォルダ内のファイル毎に処理を行う。


フォルダに入っているファイル毎に、
特定の処理を実行させる方法。

for %%i in (directory\*.txt) do  (
    echo %%i
)




2012年6月29日金曜日

ファイルの排他制御のサンプル

C#でファイルの排他制御の動作確認用プログラム。 FileShareの使い方のサンプルです。

using System;
using System.IO;

namespace sample
{
    class Program
    {
        static void Main(string[] args)
        {


            File.WriteAllText("aaa.txt", "sample");

            // 読み込み中に書き込み可能
            Console.WriteLine("------------------");
            Console.WriteLine("FileShare.ReadWrite");
            using (FileStream stream = new FileStream("aaa.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (new StreamWriter("aaa.txt", true))
                {
                    Console.WriteLine("OK write");
                }
                using (new StreamReader("aaa.txt"))
                {
                    Console.WriteLine("OK read");
                }
            }

            // 読み込み中に読み込み可能
            Console.WriteLine("------------------");
            Console.WriteLine("FileShare.Read");

            // FileStreamのデフォルトはFileShare.Read
            using (FileStream stream = new FileStream("aaa.txt", FileMode.Open, FileAccess.Read))
            {
                using (new StreamReader("aaa.txt"))
                {
                    Console.WriteLine("OK read");
                }
                try
                {
                    using (new StreamWriter("aaa.txt", true))
                    {
                        Console.WriteLine("OK write");
                    }
                }
                catch (IOException ex)
                {
                    Console.WriteLine("NG write");
                }
            }
            // 読み込み中に読み込み可能
            Console.WriteLine("------------------");
            Console.WriteLine("FileShare.Write");

            // FileStreamのデフォルトはFileShare.Read
            using (FileStream stream = new FileStream("aaa.txt", FileMode.Open, FileAccess.Read, FileShare.Write))
            {
                using (new StreamWriter("aaa.txt", true))
                {
                    Console.WriteLine("OK write");
                }
                using (new StreamWriter("aaa.txt", true))
                {
                    Console.WriteLine("OK read");
                }
            }
        }
    }
}

2012年6月15日金曜日

Bazaarでproxy設定


BazaarでProxyを設定する方法

環境変数で設定する
http_proxy=http://example.com:8080
https_proxy=https://example.com:8080

プロキシを使いたくないアドレスの設定はカンマ区切りのリスト
no_proxy=local,localhost




2012年6月13日水曜日

Bazaarでプッシュを取り消す


Bazaarでコミットを取り消した後で行うこと。
bzr push --overwrite




Bazaarで最後のコミットを取り消す


bzr uncommit
bzr revert




2012年6月8日金曜日

easyui treegrid 特定の項目のみを更新


findやgetselecedで行を取得した後で必要なプロパティを更新して、refreshを行う。

var row = $('#tt').treegrid('find' id);
row.name = 'new name';
$('#tt').treegrid('refresh', row.id);




2012年6月4日月曜日

CentOSにNGIRCDをインストールする


初期状態のyumではインストールできないため、
必要なリポジトリの追加が必要になります。
リポジトリの追加からIRCDの設定までを順に書いておきます。

■リポジトリの追加
以下のサイトより環境に合わせてダウンロード
http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/

CentOS6の32bitなので、以下のファイルを使いました。
# wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/i386/epel-release-6-5.noarch.rpm
# rpm -ivh epel-release-6-5.noarch.rpm

リポジトリが追加されたかの確認。
# yum list |grep ircd

私の環境ではエラーがでてしまいました。。
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

エラーを回避sするため、以下のファイルを編集します。
# vi /etc/yum.repos.d/epel.repo

#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch

baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch

再度リポジトリが追加されたかの確認。
# yum list |grep ircd
nagios-plugins-ircd.i686             1.4.15-2.el6              epel
ngircd.i686                          18-2.el6                  epel

# yum install ngircd


ngircdの設定変更
# vi /etc/ngircd.conf
[Global]
Listen = 0.0.0.0

ファイアーウォールの設定
以下の行を追加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6667 -j ACCEPT

ngircdの起動
# /etc/init.d/ngircd start

ngircdの自動起動設定
# chkconfig ngircd on

以上でngircdのとりあえず公開する設定が完了


2012年5月30日水曜日

Windbgで .NETFrameworkのバージョンが違うよと怒られたら

Windbgでダンプファイル解析時にSos.dllを読み込んでコマンドを実行してもエラーになってしまう。。 ダンプファイルを取得したPCの.NETFrameworkのバージョンと 解析時に使っているPCの.NETFrameworkのバージョンが異なっていると起こるみたい。

以下エラー内容


0:000> !threads
Failed to load data access DLL, 0x80004005
Verify that 1) you have a recent build of the debugger (6.2.14 or newer)
            2) the file mscordacwks.dll that matches your version of mscorwks.dll is 
                in the version directory
            3) or, if you are debugging a dump file, verify that the file 
                mscordacwks___.dll is on your symbol path.
            4) you are debugging on the same architecture as the dump file.
                For example, an IA64 dump file must be debugged on an IA64
                machine.

You can also run the debugger command .cordll to control the debugger's
load of mscordacwks.dll.  .cordll -ve -u -l will do a verbose reload.
If that succeeds, the SOS command should work on retry.

If you are debugging a minidump, you need to make sure that your executable
path is pointing to mscorwks.dll as well.


【対処】
以下のシンボルファイルのパスに以下を追加して再起動すれば実行できました。

symsrv*symsrv.dll*c:\localcache*http://msdl.microsoft.com/download/symbols

2012年5月14日月曜日

editor typeの設定


treegridのドキュメントを見ても載ってないんですよ。
で、似たようなgridのドキュメントが参考になりそうです。
多分同じです。
http://www.jeasyui.com/documentation/datagrid.php

editorのtypeは以下の通り。
text,textarea,checkbox,numberbox,validatebox,datebox,combobox,combotree.

treegridのドキュメントはいろいろ足りてないなー。


easyui treegrid サンプル


一通りの設定を確認できるのがGoogleCodeにあった。
http://code.google.com/p/jquery-easyui/source/browse/trunk/demo/treegrid.html?r=498



2012年5月7日月曜日

Redmine1.4.0をWindowsにインストールしてみる。


データベースはSQLiteを使う。

■Rubyのインストーラ
http://rubyinstaller.org/downloads/

今回使用したバージョン
Ruby 1.9.3-p125

exeを実行しインストールする。
OKの連続で問題ない。

環境変数のPATHに以下を追加。
C:\Ruby193\bin;

インストール後にコマンドプロンプトを起動してインストール確認
>ruby -v
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
>gem -v
1.8.16

■Redmineのインストール
http://rubyforge.org/frs/?group_id=1850

今回使用したバージョン
redmine-1.4.0.zip


解凍してC:\redmine-1.4.0に移動する。


■データベース設定
C:\redmine-1.4.0\config\database.yml.exampleを
C:\redmine-1.4.0\config\database.ymlに名前を変更

database.ymlのデフォルトのmysqlの設定をコメントアウトしてSQLiteに書き換える
------------
#production:
#  adapter: mysql
#  database: redmine
#  host: localhost
#  username: root
#  password:
#  encoding: utf8
production:
  adapter: sqlite3
  database: db/redmine.db
------------


■Bundlerのインストール
>gem install bundler


■Bundleで必要なGemのインストール
>bundle install --without development test rmagick


■秘密鍵を生成
>rake generate_session_store

■データベース上にテーブルを作成
>rake db:migrate RAILS_ENV=production

■データベースに初期データを設定
>rake redmine:load_default_data RAILS_ENV=production

■実行する。
ruby c:\redmine-1.4.0\script\server -e production

ブラウザより以下のアドレスでアクセス出来るようになっているはず!
http://localhost:3000/


おまけ。
■公開設定
C:\redmine-1.4.0\config\setting.ymlを変更

動作するPCのIPアドレスに変更すると他のPCから見えるようになる。
---
host_name:
#  default: localhost:3000
  default: 192.168.1.1:3000
---



Redmine バージョンアップ 1.1.2→1.3.2


windowsで使っていたRedmineをバージョンアップした時の手順を残しておきます。

■Redmineのリリース済みパッケージをダウンロード
http://rubyforge.org/frs/?group_id=1850
今回は1.3.2にバージョンアップするのでredmine-1.3.2.zipを取得

■zipを展開
C:\redmine-1.3.2に展開しました。

ちなみに既存の1.1.2はC:\redmine-1.1.2にあります。

■インストールしているプラグインを確認
インストールしているプラグインの一覧を控えておく。
・Redmineに管理者でログイン
・管理→プラグイン
ここに一覧で出ているプラグイン名を記録しておくこと。
後でプラグインフォルダをコピーする時に使う。

■1.3.2に必要なライブラリをgemでインストール。
gem install rack -v=1.1.1
gem install rdoc -v=2.4.2

■データの移行
・データベース設定
redmine-1.1.2/config/database.yml

・データベース
データベースのデータはsqliteを使っていたので以下のフォルダにあるファイルをコピーした。
redmine-1.1.2/db/*

・添付ファイル
redmine-1.1.2/files/*

・ログ
redmine-1.1.2/log/production.log

・プラグイン(自分がインストールしたプラグインのみを移動すること)
redmine-1.1.2/vendor/plugins/*

■秘密鍵の生成
rake generate_session_store

■データベースの更新
rake db:migrate RAILS_ENV="production"
rake db:migrate:upgrade_plugin_migrations RAILS_ENV=production
rake db:migrate_plugins RAILS_ENV=production

■キャッシュのクリーンナップ
rake tmp:cache:clear
rake tmp:sessions:clear

■実行する。
今まで通りの方法で実行する。

無事に動きましたとさ。


2012年4月26日木曜日

バグレポートの書き方

http://alpha.mixi.co.jp/blog/?p=5864 どれも思い当たる節が…。 結果だけで、手順が無かったり。 そもそも結果が曖昧やったり。ヽ(;▽;)ノ 評価中は時間がない事が多いから、 曖昧なバグレポートが来ると困るのよね。 ログを出すアプリやったら一緒に ログも残して置いて欲しいですね。 3つとも大切なこと。 新人に読ませてあげよっと。

2012年4月25日水曜日

iPad対応製品

Simplism、The new iPad対応製品を発表 http://www.trinity.jp/news/2012/03/1921.html 保護フィルムやらケースやら。

ラベル