一定時間待機するサービス

先日、知人のマシンにイベントビューワに以下のエラーが出るので調べてほしいと調査依頼を受けました。
ソース:NETLOGON、イベントID:5719
ソース:Userenv、イベントID:1053
調査しましたところ、そのマシンが今流行のSSDを搭載しており、NETLOGON起動タイミングが速すぎて、他の初期化処理が追いつかずくエラーとなるようでした。
残念ながらそれ以上の詳細は解らないのですが、速すぎてだめなら一定時間待てばよいということでサービスを作成しました。
せっかくなのでシェアウェアとして公開します。
2009-03-04 | コメント:0件



C++/STLで数値の3桁区切り

久しぶりのC++/STLネタです。今回は数値の3桁区切りをやってみました。
ネットを探すとCのサンプルはあるのですが、少々トリッキーなコーディングのものが多いので、C++でのベタな実装というとこで作ってみました。

/**********************************************************************
 数値の3桁区切り
 試したコンパイル環境
    VC++ .NET 2003 / WINDOWS XP Professional 64 bit edition.
    GCC C++ 3.3.6 / glibc 2.3.4 / Vine Linux 4.2
**********************************************************************/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <sstream>
std::string formatNumber(int num)
{
    std::vector<int>    sepnum;
    int                 number = abs(num);
    int                 sgn = num >= 0 ? 1 : -1;
    while ( number / 1000 ) {
        sepnum.push_back(number % 1000);
        number /= 1000;
    }
    std::stringstream  ss;
    ss << number * sgn;
    for ( std::vector<int>::reverse_iterator i = sepnum.rbegin();
                                        i < sepnum.rend(); i++ ) {
        ss << "," << std::setfill('0') << std::setw(3) << *i;
    }
    return std::string(ss.str());
}
using namespace std;
int main(int argc, char* argv[])
{
    cout << formatNumber(0) << endl;
    cout << formatNumber(1) << endl;
    cout << formatNumber(12) << endl;
    cout << formatNumber(123) << endl;
    cout << formatNumber(1234) << endl;
    cout << formatNumber(12345) << endl;
    cout << formatNumber(123456) << endl;
    cout << formatNumber(1234567) << endl;
    cout << formatNumber(12345678) << endl;
    cout << formatNumber(123456789) << endl;
    cout << formatNumber(1234567890) << endl;
    cout << formatNumber(-1) << endl;
    cout << formatNumber(-12) << endl;
    cout << formatNumber(-123) << endl;
    cout << formatNumber(-1234) << endl;
    cout << formatNumber(-12345) << endl;
    cout << formatNumber(-123456) << endl;
    cout << formatNumber(-1234567) << endl;
    cout << formatNumber(-12345678) << endl;
    cout << formatNumber(-123456789) << endl;
    cout << formatNumber(-1234567890) << endl;
}

2009-02-16 | コメント:0件



複数あるネットワーク接続で、優先して使用するネットワーク接続を指定する(Windows XP編)

あけまして、おめでとうございます。
前回の更新からすっかり時間がたちました。月日の経つのは早いもので、まぁぼちぼち更新します。

今年一発目の技術ネタは、Windowsでのネットワーク接続に関するものです。
Windowsのネットワーク関係の設定で、知らないことはもうないとか勘違いしていましたが、最近知った設定を紹介します。

複数のネットワーク接続がある場合、Windowsではどちらかを優先して使用する設定があります。例えば、ワイヤレスネットワーク接続とケーブルのローカルエリア接続で、両方が有効な場合にローカルエリア接続を優先するように設定する等です。

設定方法ですが、マイネットワークのプロパティ(以下の図)の詳細設定メニューの詳細設定にあります。

以下のように詳細設定のダイアログが出てきます。ここで優先する接続をリストの上にもっていきます。
(下図の設定では、ワイヤレスネットワークが優先されます)

上記のダイアログですが、Windows XPでは、この方法でしか出せないようです。
2009-01-05 | コメント:0件



最近の世相と夏の暑さでヨメが壊れた

ある日のこと。
日々の疲れと二日酔いからくる頭痛に見舞われた自営業の働くオクサマは頭にアイスノンを巻きながら、
それでもせっせと仕事をしていましたとさ。
そこに相方。苦しむオクサマにひとこといったとさ。
”おなすみたい”
そうそう。真っ青な顔で下膨れで毛がはみ出てて・・・コラ~っ!!!!
異常気象に老後の不安。景気は悪くなる一方。親もお客も患者もみんなモンスターに成り果てた。
そりゃぁ、青くなる。怒りで赤くなりもする。
あわせりゃそうそう、いつのまに・・・。ムラサキの顔になっていた。
この世はおなすなことばかり。
2008-08-14 | コメント:0件



C++/STLでCSVファイルの読み込み

久しぶりのC++/STLネタということで、CSVファイルの読み込みです。
もともと、Apacheが出力するアクセスログの読み込みの為に作ったのですが、せっかくなので、Excelが出力するCSVにも対応しました。
CSVファイルの読み込みは他の言語ならsplit一発でお茶を濁すのですが、カンマ(,)やダブルクオート(")、改行があるデータにも対応してます。
/**********************************************************************
 CSVファイルの読み込みサンプル
 試したコンパイル環境
    VC++ .NET 2003 / WINDOWS XP Professional 64 bit edition.
    GCC C++ 3.3.6 / glibc 2.3.4 / Vine Linux 4.2
**********************************************************************/
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
/**********************************************************************
 クオート文字の定義構造体
**********************************************************************/
struct quote{
    char    start;  // 開始文字
    char    end;    // 終了文字
    char    escape; // エスケープ文字
    quote( char start_, char end_, char escape_) :
         start(start_), end(end_), escape(escape_) {}
};
struct cmpStartQuote : public std::binary_function<quote,char,bool> {
    bool operator()(const quote &l_s1, const char &l_s2) const {
        return l_s1.start == l_s2;
    }
};
/**********************************************************************
 CSVの読取
**********************************************************************/
bool readCSV(
    std::vector< std::string > &result, // 結果格納ベクター
    std::istreambuf_iterator<char> &i,  // 入力文字イテレータ
    std::string &separator,             // 区切り文字
    std::vector<quote> &quotes)         // クオート文字ベクター
{
    bool retval = false;
    result.clear();
    std::string item;
    char    bc = '\0';
    bool    first = true;
    std::vector<quote>::iterator    ff = quotes.end();
    while ( i != std::istreambuf_iterator<char>() &&
                    (ff != quotes.end() || *i != '\n') ) {
        if ( ff == quotes.end() &&
                            strchr( separator.c_str(), *i) != 0 ) {
            result.push_back(item);
            item.clear();
            first = true;
            retval = true;
        } else {
            if ( first &&
                (ff = find_if( quotes.begin(),
                            quotes.end(),
                            bind2nd( cmpStartQuote(), *i)))
                    != quotes.end() ) {
                first = false;
            } else if ( ff != quotes.end() && ff->end == *i ) {
                if ( ff->end == ff->escape ) {
                    bc = *i++;
                    if ( i == std::istreambuf_iterator<char>() )
                        break;
                    if ( *i == ff->end ) {
                        item.push_back(*i);
                    } else {
                        ff = quotes.end();
                        continue;
                    }
                } else {
                    if ( bc == ff->escape ) {
                        item.push_back(*i);
                    } else {
                        ff = quotes.end();
                    }
                }
            } else {
                item.push_back(*i);
                first = false;
            }
        }
        bc = *i++;
    }
    result.push_back(item);
    if ( i != std::istreambuf_iterator<char>() ) {
        retval = true;
        i++;
    }
    return retval;
}
using namespace std;

int main(int argc, char* argv[])
{
    basic_ifstream<char>        inputFile("access_log");
    istreambuf_iterator<char>   sin(inputFile);
    vector< string >            rec;
    // APACHEのアクセスログ
    string                      separator(" ");
    vector< quote >             quotes;
    // クオート文字(")の設定("を表示したいときは\"になる)
    quotes.push_back( quote( '"', '"', '\\') );
    // 時間部分のクオート文字([]で括る)
    quotes.push_back( quote( '[', ']', 0 ) );
    while ( readCSV( rec, sin, separator, quotes) ) {
        vector< string >::iterator i;
        for ( i = rec.begin(); i < rec.end(); i++ ) {
            cout << i - rec.begin() << ":" << *i << endl;
        }
        cout << endl;
    }
    return 0;
}
 
上記コードは、Apacheのログを読み込むサンプルで、CSVファイルの読み込みの場合は、
separatorとquotesの部分が、
 
    string                      separator(",");
    vector< quote >             quotes;
    quotes.push_back( quote( '"', '"', '"') );
 
になります。
2008-08-04 | コメント:0件
Previous Page | Next Page