2011-03-05 [Java]Javaプログラマであるかを見分ける10の質問に答えてみた

これに答えてみた。間違いだらけなので参考にしないように!
http://d.hatena.ne.jp/shuji_w6e/20110305/1299288660
- オブジェクトがガベージコレクション(GC)される主たる条件は何か?
- 対象オブジェクトへの参照が無くなること
- チェック例外と非チェック例外の違いを型と例外処理の観点で説明せよ。
- 分かりません。
- フィールドのアクセス修飾子をprivateにしgetter/setterメソッドを提供する事でフィールドを参照する設計方針を取る主な理由を説明せよ
- あとあとatomicにアクセスしたくなったりするから?
- NullPointerExceptionが発生するのは主にどういう状況か?
- 分からない。引数のnullチェック漏れかな?
- インターフェイスを利用する目的を1つ説明せよ
- 依存関係を疎にしたいから
なんかすごい勉強不足だなと今更思った。
4,5,6,7,9あたりが特に怪しい。
せめてEffective Javaくらいは読もう。
ホーム言語Objective-Cだからゆるして!
2009-03-02
[DTM][備忘録]MU.LABとIndependence Free 2.0をWindows Vistaに導入したメモ
動機
Freeのツールだけで手軽に曲を作って遊びたい。
背中を押されたもの
http://www.nicovideo.jp/watch/sm2158098
この音源フリーのくせにすげぇ!!!
この導入メモを書く理由
環境
Windows Vista Home Edition (SP1)
MU.LAB導入手順
MU.LAB Windows版のダウンロード
http://www.mutools.com/downloads.html
MU.LAB のインストール
圧縮ファイルを解凍するのみ。
Independence Free 2.0 導入手順
Independence Free 2.0のダウンロード
- http://www.yellowtools.us/ に行く
- 「English」を選ぶ
- [Products]→[Independence Free]を選ぶ
- Independence Free Downloadを選ぶ
- Product Registrationでユーザ登録をする(必須っぽい)
- 登録が済んだら、メールアドレスとパスワード入力してログイン
- 「Download」へ。(注!Achieve Downloadではない)
- Windows XP用のインストーラをダウンロード
- サウンドライブラリ Part1 〜 Part8をダウンロード
Independence Free 2.0のインストール
- インストーラに言われるがままインストールをする
- サウンドライブラリPart1〜Part8を解凍する
- 解凍してできたytifファイルを、全て[C:\Program Files\yellow tools Independence Player\Independence Player Basic Path\image files]直下に置く
MU.LABにIndependence Free 2.0を認識させる
- MU.LABを起動
- [File]→[VST Manager]→[Add VST Plugins]
- [C:\Program Files\yellow tools Independence Player\data\Independence Player.dll]を選択
- [OK]を押下
http://jp.dll-download-system.com/dlls-download-w-/wkwin32.dll.html
- Independence PlayerのBasic Pathを設定しろ!と言われる
- [C:\Program Files\yellow tools Independence Player\Independence Player Basic Path]を選択
導入が成功したかどうかを確認する
- [Edit]→[Show Modular Plugin Area]を選択
- Modular Plugin Areaで右クリックし、[Add Plugin]を選択
- [Synths]→[VST]
- ここにIndependence Playerが表示されていればOK
2008-10-29
[地震]地震予知100%をうたうマユツバっぽいページを見つけた
あなたも簡単にできる100%地震予知
っていうページを見つけた。
http://blog.livedoor.jp/esasani/
このブログの10/29の追記で、
10/29 23:59
素直にみれば日本付近で反応してるのがわかると思います。
対応する電磁波シグナルまちの状況です。
m5規模程度ならいつ発震してもおかしくない強さです。
という予測の約1時間後
30日00時48分頃地震がありました。
震源地は宮城県沖 ( 北緯38.0°、東経141.7°)で震源の
深さは約90km、地震の規模(マグニチュード)は5.1と推定されます。
各地の震度は次の通りです。
※気象庁のページより引用
ほんとに予測できてるのかはサッパリわからないけど
とりあえずlivedoor readerには追加してみた。
エントリを見る限り、数うちゃ当たるって感じで予測してるわけではない様子。
けど予測の範囲が「日本付近」とだいぶ広いため、今後更新されて、予測が当たるにしても地域の予測は立てづらいんだろうな。
2008-10-03 javaのLoggerみたいなものを純C++で作ってみた
javaのLoggerみたいなものを純c++で作ってみた
↓を参考にさせていただきますた
http://goodjob.boy.jp/chirashinoura/id/101.html
何を変えたのかというと
- ログローテーション機能を搭載
- ところどころ高速化した(つもり)
- 外部に公開すべきものを最低限に削ってみた
ただし
- β版です。統一性ないとこ多数(ifstream使ってるかと思ったらfprintf使ってたり)
- 手元のVisual C++2005でひと通りテストはしてあるけど動作は保障しません。
ソース
- Logger.h
//============================================================================= /** * @file Logger.h * * @brief JavaのLoggerもどき。 * * +-+-+-+-+-+-+-+- 使い方 +-+-+-+-+-+-+-+- * #include "Logger.h" * * Logger::configure("./logger.ini"); * Logger::info("いんふぉ", __FILE__, __LINE__); * Logger::debug("でばっぐ", __FILE__, __LINE__); * Logger::warn("わーん", __FILE__, __LINE__); * Logger::error("えらー", __FILE__, __LINE__); * * * ・上記処理で、ログが出力されます。 * ・出力レベルはiniファイルのLOG_LEVELで調節できます(必須) * ・出力先のファイル名はFILE_PATHで設定します。 * ・LOTATE_SIZEとLOTATE_GENERATIONを設定すると、 * ログのサイズがLOTATE_SIZEを超えた段階でバックアップファイルにリネームします。 * バックアップは最大でLOTATE_GENERATION個まで保持します。 * * +-+-+-+-+-+-+-+- iniファイル詳細 +-+-+-+-+- * (必須) * LOG_LEVEL INFO、DEBUG、WARN、ERRORの順にエラーが出にくくなります * (オプショナル) * LOTATE_SIZE で指定されたサイズを超えたらログをバックアップします。 * LOTATE_GENERATION で指定された世代数分だけ、バックアップログを残します。 * FILE_PATH ログファイル名(相対パス、フルパスどちらでも) * 設定しなかった場合のデフォルトは"./logger.log" * # #から始めた行はコメントになります * +-+-+-+-+-+-+-+- いいところ -+-+-+-+-+-+-+-+- * * ・純c++で書いてるのでたいていの環境で使えるはずです。 * ・ソースに仕込むだけ仕込んでおいてもiniファイルを食わせなければ何もしません。 * ・引数のfile,lineは省略可です。 * ・指定したiniファイルが存在しなかったり、設定が間違ってても固まったりしません。 * ・スレッドセーフです(当たり前か) * * @author FunnyBunnyDizzy * * @date 2008/10/03 * * @version 1.0 */ //============================================================================= #ifndef _LOGGER_ #define _LOGGER_ #include <string> #include <map> using namespace std; class Logger { public: // 設定ファイルを食わせます static void configure(const string inifilePath); // informationレベルのメッセージを出力します static void info(const string msg, const string file="", const int line=0); static void info(const unsigned char* msg , const char* file = "" , const int line = 0); // debugレベルのメッセージを出力します static void debug(const string msg, const string file="", const int line=0); static void debug(const unsigned char* msg , const char* file = "" , const int line = 0); // warningレベルのメッセージを出力します static void warn(const string msg, const string file="", const int line=0); static void warn(const unsigned char* msg , const char* file = "" , const int line = 0); // errorレベルのメッセージを出力します static void error(const string msg, const string file="", const int line=0); static void error(const unsigned char* msg , const char* file = "" , const int line = 0); private: // 定数 static const int LOGGER_INFO; static const int LOGGER_DEBUG; static const int LOGGER_WARN; static const int LOGGER_ERROR; static const string PROFILE_KEY_LOG_LEVEL; static const string PROFILE_KEY_LOG_FILEPATH; static const string PROFILE_KEY_LOTATE_SIZE; static const string PROFILE_KEY_LOTATE_GENERATION; static const string DEFAULT_LOG_FILEPATH; static const string NULL_STRING; // 内部変数 - profile格納用 static int m_nLogLevel; static string m_strFilePath; static int m_nLotateGeneration; static int m_nLotateSize; // 内部関数 static string trim(const string& str); static int fsize( const string& filename ); static void lotate(void); static void do_lotate( const string& filepath ); static void loadProfile( const map<string,string> mapProfile ); static bool isEnabled(const int logLevel); static void log(const int level, const string msg, const string file, const int line); static string charToString( const unsigned char* src ); static string getLogLevelString( const int nLogLevel ); static string getCurrentTimeString( void ); static string getValue(const string key , map<string,string> mapProfile); static void splitstring(const string src, const string separator, string &first, string &second); }; #endif
- Logger.cpp
#include"Logger.h" #include <string> #include <iostream> #include <fstream> #include <sstream> #include <map> #include <time.h> #include <assert.h> #include <error.h> using namespace std; // 内部定数 const int Logger::LOGGER_INFO = 1024; const int Logger::LOGGER_DEBUG = 2048; const int Logger::LOGGER_WARN = 4096; const int Logger::LOGGER_ERROR = 8192; const string Logger::PROFILE_KEY_LOG_LEVEL = "LOG_LEVEL"; const string Logger::PROFILE_KEY_LOG_FILEPATH = "FILE_PATH"; const string Logger::PROFILE_KEY_LOTATE_GENERATION = "LOTATE_GENERATION"; const string Logger::PROFILE_KEY_LOTATE_SIZE = "LOTATE_SIZE"; const string Logger::NULL_STRING = ".*.*NULL.*.*"; // 無効な文字列を示す識別子 // +-+-+-+- iniファイル設定項目 +-+-+-+-+ // 高速化のため1度読み込んだら2度と変更しない。 // 読み取り位置は初めにconfigureメソッドをコールしたタイミング。 // 2度、3度とconfigureメソッドをコールしても、2度目以降は無視する。 string Logger::m_strFilePath = "./logger.log"; // デフォルトのログ出力先 int Logger::m_nLogLevel = INT_MAX; int Logger::m_nLotateGeneration = 0; int Logger::m_nLotateSize = INT_MAX; //============================================================================= /** * configure() * * @brief 設定ファイルを読み込ませる。 * * @param inifilePath 設定ファイルパス */ //============================================================================= void Logger::configure(const string inifilePath) { // configureは1度のみ可能 if( INT_MAX != m_nLogLevel ){ return; // configure済 } try{ // 読み込み用ファイルストリーム ifstream fin; // ファイルオープン fin.open(inifilePath.c_str(),ios::in); if( ! fin.is_open()){ cerr << "Logger configure file open failed : " << inifilePath.c_str() << endl; return; // ファイルオープン失敗 } // iniファイル解析 map<string, string> mapProfile; while (!fin.eof()) { string line; string key; string value; getline(fin , line); // 先頭#行はコメント if( '#' == line[0] ){ continue; } Logger::splitstring(line, "=", key, value); if (key == NULL_STRING || value == NULL_STRING) { continue; } mapProfile.insert(pair<string, string>(key, value)); } // ファイルクローズ fin.close(); // iniファイル解析情報をメンバ変数へ格納 loadProfile(mapProfile); }catch( ... ){ // どんな例外が出てもスルー } } //============================================================================= /** * info() * * @brief インフォメーションレベルのメッセージを出力する * * @param msg メッセージ内容 * @param file 出力元のファイル名(省略可) * @param line 出力元のファイル行数(省略可) */ //============================================================================= void Logger::info(string msg, string file, int line) { try{ if (Logger::isEnabled(LOGGER_INFO)) { Logger::log(LOGGER_INFO, msg, file, line); } }catch(...){ // 例外はスルー } } void Logger::info(const unsigned char* msg , const char* file, const int line) { Logger::info( charToString(msg) , file , line ); } //============================================================================= /** * debug() * * @brief デバッグレベルのメッセージを出力する * * @param msg メッセージ内容 * @param file 出力元のファイル名(省略可) * @param line 出力元のファイル行数(省略可) */ //============================================================================= void Logger::debug(const string msg,const string file,const int line) { try{ if (Logger::isEnabled(Logger::LOGGER_DEBUG)) { log(Logger::LOGGER_DEBUG, msg, file, line); } }catch(...){ // 例外はスルー } } void Logger::debug(const unsigned char* msg , const char* file, const int line) { Logger::debug( charToString(msg) , file , line ); } //============================================================================= /** * warn() * * @brief ワーニングレベルのメッセージを出力する * * @param msg メッセージ内容 * @param file 出力元のファイル名(省略可) * @param line 出力元のファイル行数(省略可) */ //============================================================================= void Logger::warn(string msg, string file, int line) { try{ if (Logger::isEnabled(Logger::LOGGER_WARN)) { log(Logger::LOGGER_WARN, msg, file, line); } }catch(...){ // 例外はスルー } } void Logger::warn(const unsigned char* msg , const char* file, const int line) { Logger::warn( charToString(msg) , file , line ); } //============================================================================= /** * error() * * @brief エラーレベルのメッセージを出力する * * @param msg メッセージ内容 * @param file 出力元のファイル名(省略可) * @param line 出力元のファイル行数(省略可) */ //============================================================================= void Logger::error(string msg, string file, int line) { try{ if (Logger::isEnabled(Logger::LOGGER_ERROR)) { log(Logger::LOGGER_ERROR, msg, file, line); } }catch(...){ // 例外はスルー } } void Logger::error(const unsigned char* msg , const char* file, const int line) { Logger::error( charToString(msg) , file , line ); } // 引数に指定されたレベルのログを出力すべきか判断する // 下記条件を満たす場合、[出力すべき]と判断する // ・iniファイルからログレベルを読込済であること // ・引数logLevelが、読み込んだログレベル以上であること bool Logger::isEnabled(int logLevel) { return logLevel >= m_nLogLevel; } // levelで指定されたログレベルにてログ出力を行います。 void Logger::log(int level, string msg, string file, int line) { // ログローテーション lotate(); // ログ出力 FILE *pf = NULL; if ((pf = fopen(m_strFilePath.c_str(), "at")) != NULL){ string logLevel = getLogLevelString( level ); string strCurrentTime = getCurrentTimeString( ); stringstream ssm; ssm << strCurrentTime << " [" << logLevel << "]"; if( "" != file ){ ssm << " " << file; } if( 0 != line ){ ssm << "(" << line <<")"; } ssm << " " << msg << endl; fprintf(pf, ssm.str().c_str()); fclose(pf); }else{ // ファイルを開けなかったら何もしない } return; } // 現在時刻を文字列形式で取得します。 string Logger::getCurrentTimeString( void ) { string strCurrentTime; time_t aclock; char *now; struct tm *newtime; // 現在の時刻を取得。 time(&aclock); newtime = localtime(&aclock); now = asctime(newtime); strCurrentTime = now; // nowの末尾の改行をチョップ。 return strCurrentTime.substr(0, strCurrentTime.size() - 1); } // ログレベル(数値)⇒ログレベル(文字列)の変換を行います。 string Logger::getLogLevelString( const int nLogLevel ) { string strLogLevel; if (nLogLevel == LOGGER_INFO) { strLogLevel = "INF"; } else if (nLogLevel == LOGGER_DEBUG) { strLogLevel = "DBG"; } else if (nLogLevel == LOGGER_WARN) { strLogLevel = "WRN"; } else if (nLogLevel == LOGGER_ERROR) { strLogLevel = "ERR"; } else { strLogLevel = "UNKNOWN"; } return strLogLevel; } // ローテーションを行うかの判断。必要であればdo_lotateを実行 void Logger::lotate( void ) { // ローテーション関連のプロファイルが未セットであれば何もしない if( INT_MAX == m_nLotateSize && 0 == m_nLotateGeneration ){ return; } FILE* pf = NULL; // サイズがローテーションサイズを超えていればローテーションを行う if ((pf = fopen(m_strFilePath.c_str(), "at")) != NULL){ fclose( pf ); int filesize = fsize(m_strFilePath); if( m_nLotateSize < filesize ){ do_lotate( m_strFilePath ); } } } // ローテーションの実行部 void Logger::do_lotate( const string& filepath ) { // バックアップログ拡張子の最低値 const int backupLogInitialNumber = 1; // 最古のログを削除 { stringstream ssm; ssm << "." << m_nLotateGeneration; string str = ssm.str(); string oldest = filepath + str; remove( oldest.c_str() ); } // 古い方のログから順にリネーム。 log.3⇒log.4、log.2⇒log.3、log.1⇒log.2 int index = m_nLotateGeneration; while( backupLogInitialNumber < index ){ stringstream ssm_old, ssm_new; ssm_old << "." << index-1; ssm_new << "." << index; string oldfile = filepath + ssm_old.str(); string newfile = filepath + ssm_new.str(); rename( oldfile.c_str() , newfile.c_str() ); index--; } // 最新のログをバックアップへ { stringstream ssm_old, ssm_new; ssm_new << "." << backupLogInitialNumber; string newfile = filepath + ssm_new.str(); rename( filepath.c_str() , newfile.c_str() ); errno; } } // filenameに指定したファイルのサイズを取得する(単位:byte) int Logger::fsize( const string& filename ) { fpos_t size = 0; FILE* pf = NULL; if( (pf = fopen(filename.c_str(),"rb")) != NULL ){ /* ファイルサイズを調査 */ fseek(pf,0,SEEK_END); fgetpos(pf,&size); fclose(pf); } return (int)size; } // 文字列をseparatorで2つに分割&トリムする。分割結果はfirst、secondに入れて返す void Logger::splitstring(const string src, const string separator, string &first, string &second) { first = ""; second = ""; int i = (int)src.find(separator); //find seperator if(-1 != i){ int y = 0; if(!src.empty()){ while(y != i){ first += src[y++]; //creating first string } y = y+(int)separator.length(); //jumping forward separator length while(y != src.length()){ second += src[y++]; //creating second string } } }else{ first = src; second = NULL_STRING; } first = trim( first ); second = trim( second ); } // 文字列前後の半角スペースを除去します string Logger::trim( const string& str ) { size_t startpoint = str.find_first_not_of( ' ' ); size_t endpoint = str.find_last_not_of( ' ' ); // spaceしか無い場合、空文字列にして返す if( -1 == startpoint || -1 == endpoint){ return ""; } size_t length = endpoint - startpoint; length++; // ###comment assert( 0 < length ); return str.substr( startpoint , length ); } // map内から設定に必要なプロファイル情報をメンバ変数へ読込みます void Logger::loadProfile( const map<string,string> mapProfile ) { // ログレベルの取得(必須) { string value = getValue( PROFILE_KEY_LOG_LEVEL ,mapProfile ); if( NULL_STRING == value.c_str() ){ return; } if (value == "INFO") { m_nLogLevel = Logger::LOGGER_INFO; } else if (value == "DEBUG") { m_nLogLevel = Logger::LOGGER_DEBUG; } else if (value == "WARN") { m_nLogLevel = Logger::LOGGER_WARN; } else if (value == "ERROR") { m_nLogLevel = Logger::LOGGER_ERROR; } } // 出力ファイル名取得(オプショナル) { string temporary = getValue( PROFILE_KEY_LOG_FILEPATH ,mapProfile ); if( NULL_STRING != temporary.c_str() ){ m_strFilePath = temporary; } } // ローテーションサイズ、世代数取得(オプショナル) { string temporary = getValue( PROFILE_KEY_LOTATE_GENERATION ,mapProfile ); if( NULL_STRING != temporary ){ m_nLotateGeneration = atoi( temporary.c_str() ); } } // ローテーション世代数取得(オプショナル) { string temporary = getValue( PROFILE_KEY_LOTATE_SIZE ,mapProfile ); if( NULL_STRING != temporary ){ m_nLotateSize = atoi( temporary.c_str() ); } } } // mapからkeyに対応するvalueを取得します。 // 取得できなかった場合、NULL_STRINGを返します。 string Logger::getValue(const string key , map<string,string> mapProfile) { // イテレータを生成 map<string, string>::iterator itr; // キーから値を検索 itr = mapProfile.find(key); if (itr != mapProfile.end()) { // キーを取得します。 string trash= itr->first; // 値も取得します。 string value = itr->second; return value; } return NULL_STRING; } // char文字列⇒string変換 string Logger::charToString( const unsigned char* src ) { if( NULL == src ){ return "(NULL)"; } stringstream ssm; ssm << src; return ssm.str(); }
設定ファイル
- logger.ini(サンプル)
# INFO、DEBUG、WARN、ERRORの順にログが出にくくなります LOG_LEVEL = INFO # ローテーションするサイズ。単位は[byte] LOTATE_SIZE = 32768 # バックアップに残すログの世代数 LOTATE_GENERATION = 5 # ログファイルの出力先 # バックアップはsample.log.1、sample.log.2という感じでできます。 # 数字が大きいほど古い感じ FILE_PATH = ./sample.log
2008-08-09 さくらにsubversionとvimをセットアップしたまとめ
さくらインターネットでSubversionをインストールしたメモ
できあがった環境
結果
参考にできるサイトさんが非常に充実してたので特に詰まらずあっさり使えるようになった。
多謝。
サーバ側前提
クライアント側前提
- Windows Vista home edition SP1
参考にしたとこ
- 全般
http://q.hatena.ne.jp/1168020870
http://saikyoline.jp/weblog/2007/04/subversion_1.html
- さくらサーバのSubversionに、svn+sshを使ってTortoiseSVNからアクセスする方法
http://mishuku.net/archives/2008/02/subversion-windows.php
http://www.gside.org/Gentoo/subversion/subversion_client.html