スキップしてメイン コンテンツに移動

投稿

11月, 2009の投稿を表示しています

Eclipseのプラグインメニューの英語化

私は英語版のeclipseを使っているのですが、インストールしたSubverionやFindBugsのプラグインのメニューやメッセージがデフォルトでは日本語になってしまいました。Google先生で調べたところ、 国際化プログラミングの常識 で答えが見つかりました。 eclipse.ini に以下の2行を追加してlocaleを変更すればよいようです。 -Duser.language=en -Duser.country=US 私の場合はこれでメニューを英語に統一できました。

Outlookにアクセスしてメールを送信するVBAコード

Public Sub GenerateOutlookEmail() Dim Outlook As Outlook.Application Dim message As Outlook.MailItem Set Outlook = CreateObject("Outlook.Application") Set message = Outlook.CreateItem(0)  With message  .Subject = "Test Mail"  .To = "foobar@foobar.com"  .HTMLBody = "Good morning life"  .Display End With End Sub

WinHttp.WinHttpRequestを使ってHttp PostでByte配列やString配列を送信するプログラム(Excel VBA)

WinHttp.WinHttpRequestオブジェクトを使って使ってHttp PostでByte配列のデータを送信するExcel VBAプログラムです。 WinHttp.WinHttpRequestを使う際には、 1. ExcelのMicrosoft Visual Basic エディタのメニューバーから「ツール->参照設定」とたどる。 2. 表示されたダイアログからMicrosoft WinHTTP Serviceにチェックを入れる。 という手順が必要です。 Byte配列をPOST Private Const BOUNDARY As String = "SOMETHING" Private Function httpPostServletByte(url As String, data() As Byte) As Byte() On Error GoTo e Dim WinHttpReq As WinHttp.WinHttpRequest If (WinHttpReq Is Nothing) Then Set WinHttpReq = New WinHttpRequest End If WinHttpReq.Open "POST", url, False WinHttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded; boundary=" & BOUNDARY WinHttpReq.send data Dim response() As Byte: response = WinHttpReq.ResponseBody httpPostServletByte = response Set WinHttpReq = Nothing Exit Function e: Set WinHttpReq = Nothing Debug.Print "httpPost Error:" & Err.

ADODB.streamオブジェクトを使って文字列とByte配列を相互変換(Excel VBA)

ADODB.streamオブジェクトを使って文字列をByte配列に変換するコードのサンプルです。 ExcelVBAでADODB.streamを使う際には、 1. ExcelのMicrosoft Visual Basic エディタのメニューバーから「ツール->参照設定」とたどる。 2. 表示されたダイアログからMicrosoft ActiveX Data Objectsにチェックを入れる。 という手順が必要です。 文字列からByte配列へ Private Function ADOS_EncodeStringToByte(ByVal cset As String, ByRef strUni As String) As Byte() On Error GoTo e Dim objStm As ADODB.stream: Set objStm = New ADODB.stream objStm.Mode = adModeReadWrite objStm.Open objStm.Type = adTypeText objStm.Charset = cset objStm.WriteText strUni objStm.Position = 0 objStm.Type = adTypeBinary Select Case UCase(cset) Case "UNICODE", "UTF-16" objStm.Position = 2 Case "UTF-8" objStm.Position = 3 End Select ADOS_EncodeStringToByte = objStm.Read() objStm.Close Set objStm = Nothing Exit Function e: Debug.Print "Error occurred while encoding characters" & Err.Description If objStm Is No

HTMLのMETAタグから文字エンコードを取得するコード

ExtractEncodingメソッドでRegexを使ってMETAタグからcharsetの部分を取り出しています。 Readメソッドでは、まず与えられたpathにあるhtmlファイルからExtractEncodingメソッドを使って適切な文字エンコードを取得します。その後取得した文字コードで読み取ったhtmlを変換しています。 using System; using System.Text; using System.Text.RegularExpressions; using System.IO; namespace Utility { public static class EncodingUtils { private static readonly Regex r = new Regex( @"<META\s+http-equiv\s*=\s*Content-Type\s+content=\s*""[^""]*\s+charset\s*=\s*(?<charset>[^""\s]*).*""\s*>", RegexOptions.IgnoreCase | RegexOptions.Compiled); public static string ExtractEncoding(string html) { string result = null; lock (r) { Match m = r.Match(html); if (m.Success) { result = m.Groups["charset"].Value; } } return result; }

ThreadPoolクラスのサンプル

ThreadPoolクラスのサンプルです。C#のソースコードを以下に示します。もっと有益な情報を載せないといけませんね。 using System; using System.Threading; namespace Test { public static class ThreadPoolTest { public static void RunThread() { ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadMethod), "A"); Console.ReadLine(); } private static void ThreadMethod(object state) { for (int i = 0; i < 10; i++) { System.Console.WriteLine(state+":"+i); Thread.Sleep(1000); } } } }

XmlTextReaderの使い方

備忘録としてSystem.Xml.XmlTextReaderのサンプルを載せておきます。 public static void ReadXMLSample(string path) { for (XmlReader textReader = new XmlTextReader(path); textReader.Read(); textReader.MoveToElement()) { Console.WriteLine("==================="); Console.WriteLine("Name:" + textReader.Name); Console.WriteLine("Base URI:" + textReader.BaseURI); Console.WriteLine("Local Name:" + textReader.LocalName); Console.WriteLine("Attribute Count:" + textReader.AttributeCount); Console.WriteLine("Depth:" + textReader.Depth); Console.WriteLine("Node Type:" + textReader.NodeType); } }

XmlTextWriterの使い方

備忘録としてSystem.Xml.XmlTextWriterのサンプルを載せておきます。 pathにxmlファイルを作成して保存するC#のプログラムです。 public static void CreateXMLSample(string path) { XmlTextWriter writer = new XmlTextWriter(path, Encoding.Default); writer.WriteStartDocument(true); writer.WriteStartElement("root"); for (int i = 0; i < 3; i++) { writer.WriteStartElement("element"); writer.WriteStartAttribute("path"); writer.WriteValue(@"c:\temp\test.txt"); writer.WriteEndAttribute(); for (int j = 0; j < 3; j++) { writer.WriteStartElement("attr"); writer.WriteStartAttribute("type"); writer.WriteValue("integer"); writer.WriteEndAttribute(); writer.WriteStartAttribute("value"); writer.WriteValue(j); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }

Python関連のリンク集・書籍

関連サイト Python公式サイト Python Tutorial ActivePython PythonWeb (Japanease) Effective Python すぐに忘れる脳みそのためのメモ ここのブログはHaskellについての投稿も充実しています。 RSS Feedのパーサモジュール Universal Feed Parser 数学関数のライブラリ(配列、行列計算で便利) NumPy kVerifeir Lab さんの ここのページ が参考になります。 書籍 Python クックブック 第2版 (Oreilly) Pythonクイックリファレンス(Oreilly) 初めてのPython 第3版(Oreilly) 柴田 淳著: みんなのPython

html読み込みの進捗状況を表示するjavascriptのプログレスバー

以下のコードの coutUp functionをhtmlの途中に埋め込むことで、そのhtmlページの読み込みの進捗状況を表示することができます。(こういう方法がいいかどうかはわかりませんが。) function ProgressBar(id) { this.div = setProgressDIV(id); this.init = init; this.countUp = countUp; var progress; function setProgressDIV(id) { if(!id){ id = "_progress"+(new Date()).getTime(); var creprgDIV = document.createElement("DIV") ; this.div = document.body.appendChild(creprgDIV) ; this.div.setAttribute("id",id) ; this.div.style.position = "relative"; this.div.style.top = "0px"; this.div.style.left = "0px"; this.div.style.width = "0px"; this.div.style.height = "0px"; } else { this.div = document.getElementById(id) } this.div.style.color = 'blue' ; this.div.style.margin = '0px' ; this.div.style.padding = '4px'; this.div.prog_bar= '|'; this.div.prog_count

JavascriptでProgressBarを実装

Javascriptで簡単な プログレスバー を実装してみました!ソースコードは以下の通りです。 function ProgressBar(id, max_count, bar_char, color) { this.div = setupProgressDIV(id, max_count, bar_char, color); this.startProgress = startProgress; this.stopProgress = stopProgress; this.finish = finish; var finishFlag = 0; function setupProgressDIV(id, max_count, bar_char, color) { if(!id){ id = "_progress"+(new Date()).getTime(); if(document.getElementsByTagName('BODY').length==0) document.write('<body>') var creprgDIV = document.createElement("DIV") ; this.div = document.body.appendChild(creprgDIV) ; this.div.setAttribute("id",id) ; this.div.style.position = "relative"; this.div.style.top = "0px"; this.div.style.left = "0px"; this.div.style.width = "0px"; this.div.style.height = "0px"; } else { this.div = document.

C#: ファイルパスから絶対URIを返すコード

ファイルパスから絶対URIを返すコードです。(特に相対ファイルパスで便利かも知れません。) public static string GetAbsoluteUri(string filepath){ FileInfo fileInfo = new FileInfo(filePath); Uri uri = new Uri(fileInfo.FullName); return uri.AbsoluteUri; } ちなみにコードの色づけには google-code-prettify を使わせて頂きました。さすがGoogle! 使い方は以下のリンクが参考になります。 Learning Log Book: Bloggerでシンタックス・ハイライト

Microsoft Outlookの.msgファイルをC#で読みこむ方法

.NetライブラリのMicrosoft.Office.Interio.Outlookを使う ディスクなどに保存された.msgファイルを読み込むことは難しいのではないかと思います。 未検証です。 CodeProjectで公開されているライブラリを使う このページ で公開されているプロジェクトファイルを使えばできそうです。こういうものをさくっと作れるのはうらやましいですね。 この記事は書き途中です。よりよい方法が見つかり次第更新します!

ActionScript 3.0 ライブラリ集

ライブラリのリンク集 ntt.cc で細かく紹介されています。記事へのリンクは こちら から。 noein さんの このページ でもいろいろ紹介されています。 phpspot開発日誌 さんでも大量にリンクが紹介されています。リンクは こちら から。 Adobe Labs でも有用なライブラリが このページ で多数公開されています! Spark project では非常に有用なライブラリが公開されています。是非チェックしてみてください! Adobe Open Source テスト flexunit :テストライブラリの定番 asunit : 私は2009年頃、このライブラリを使っていましたが、どうやら最近は更新をしていないようです。 Dukeさんの気になるライブラリをピックアップ printf-as3 : ActionScript 3.0で実装されたprintf AS3DS : データ構造(スタック、キューなど)のライブラリです。 log4as3 : ActionScript 3.0のためのlogging APIです。log4jのActionScript 3.0版といったところでしょうか。 Flex: Using the Flex3 Logging API でlog4as3以外のlogging APIについて比較・検討されています。 AS 3 Parametric Curve Library :パラメトリック曲線に関するライブラリ alivepdf :ActionScript 3.0で実装されたpdf生成のためのライブラリ as3xls : ActionScript 3.0 からMicrosoft Excelを読み書きするためのライブラリ ActionScript TIFF Encoder :ActionScript 3.0で実装されたTIFFエンコーダーです。 Kevin Hoyt さんで公開されています。素晴らしい!! as3gif :ActionScript 3.0で実装されたFlash上でGIFアニメを再生するためのライブラリです。 PaperVision3D :Flash上で高度な3Dグラフィックスを実現するためのライブラリです。Coolなデモがたくさん揃っています! ASTRA: Acti

Test Tools for .Net

Unit Testing Framework for .Net NUnit @ITのNunitの解説ページ Code Coverage Tool for .Net NCover :I think this is the famous one rather than the one below which has the same name. The problem is this tool is not free :(. NCover : Free open source code coverage tool for .Net. partcover : This is the alternative tool of NCover. I'll try to use it ;). ReportGenerator : This can generate cool and readble code coverage report.

Visual Studio 2008 のショートカットキー一覧

Microsoft公式(日本語) Visual Studio shortcut keys 10 Visual Studio Shortcuts You Must Know Visual Studio:Visual Studio ショートカット よく使うショートカット (独断と偏見) Ctrl+R, E : メンバー変数のカプセル化。Getter, Setter生成。 Ctrl+K, F : 選択した範囲のコードのオートインデント。 Ctrl+K, K : 行をブックマーク。 Shift+Alt+F10 : インタフェースの自動実装。 ちなみにVisual Studio Express Editionは ここ からダウンロードできます。