火曜日, 4月 21, 2009

オラクルのサン買収、狙いはハードウェアとソフトウェアの統合システム

オラクルがサンを74億ドルで買収したということです。

サンの買収は、IBMなどの交渉など、メディアの注目が集まっていましたね。

→ オラクルのサン買収、狙いはハードウェアとソフトウェアの統合システム (2009-4-21)

オラクルはデータベースからの収益が約5割だそうです。

→ ■[企業経営]オラクル、サン買収の先にはCommentsAdd Star

サンは以前にMySQLを買収しているので、行方が気になるところではあります。

→ ■[雑感]どうなるMySQL。オラクルがサンを買収CommentsAdd Starshingotadahasaqui

水曜日, 4月 15, 2009

NHKのラジオ語学講座がネットで視聴できるようになりました

いつのまにかNHKのラジオ語学講座がネットで視聴できるように(一週間分のみ)なってました。

→ ラジオ番組の音声が聞けます 4月6日10:00~ストリーミング開始

快挙ですね。

復習できるし、リピーターとしても毎日の「収穫」が期待できるようになってます。

木曜日, 3月 26, 2009

MySQL: Counting Rows that Has Same Value

There are many ways to count rows in a database. Here shows grouping the rows and counting them in MySQL database. The keywords are: "group by" to sort out the rows and "as" keyword to set the value to a variable.

Suppose the database has a table 'species' with 'en' field. The "group by" command will set up just one row for each 'en' value. Along with 'en' value, count(en) value will be retrieved in descending order as being set by "order by" command. The results will be a table with representative 'en' value with the count of it.


SELECT en, count( en ) AS cnt
FROM `species`
GROUP BY en
ORDER BY cnt DESC

Java: Drawing Lines of Various Width

Line drawing in Java with Graphics2D, is simple and straight foward except that the line width matters in coordinating the figures you would like to draw. Setting stroke, any line width can be set as follows:


int lineWidth=3;
BasicStroke stroke=new BasicStroke((float)lineWidth);
g2D.setStroke(stroke);


The next step is, however, rather counter-intuitive. The line will be drawn half the pixels left from the coordinate that you specify.


int d=(int)((double)(lineWidth-1)/2.0);


The drawing command will draw line that fills the area (x0,y0) to (x1,y1).


g2D.drawLine(x0+d,y0+d,x1-(lineWidth-d),y1-(lineWidth-d));

火曜日, 3月 17, 2009

プログラミング言語の選択

いわゆる文学の書体というものもあるが、ベストセラーの類いはすでに書き方が変化している。つまり、軽く読める雑誌風の、ときにはファッション雑誌風の意味の取れない文章が「もっとも身近」な種類の人間がいる。

そのトレンドにあらがうつもりはないが、間投詞を多く使い、ひらがなを主体とし、論理より感覚に訴えるノリを好むかどうかは、個人の選択である。それっぽくさ、てな感じで、って書くやりかた?ちょっと抵抗あるっていうやつ?分かる?

プログラミング言語の選択は、まさに政治そのものである。強大な国力を持つ国の言語が、その性質にかかわらず周辺国を制覇するのと同様に、無理にも書き方を同化しろという圧力が常にかかる。

「たいていの人間は英語を話す」と言えば、その意は自明であろう。「たいていの人間は***を使う」と書いて別言語、別ライブラリの使用者の反感をもろに買う。もちろん、英語が主流となるかどうかは、フランスなど国の政策に大きく影響される。

言葉の習得は一生の仕事である。人間が安いところで常に軽はずみな判断による負担が個人にかかる。真剣に選択された言葉の重みは、一生引きずって歩かねばならない支えであり、重荷である。

金曜日, 3月 13, 2009

JTable から値を取り出すときの注意

JTable は、Java で表形式のデータを扱うのにとても便利。

Swing を読み込んで、TableModel を設定して、TableCellEditor クラスを使うなど使いこなすと応用が利きます。

ここで、気づいた点をひとつ。

入力済みの数値はそのまま Integer ですが、編集を可能にして入力を得ると、値は String になります。

下記のようにすると判別できます。



Object obj=table.getValueAt(i,0);
String className=obj.getClass().getName();
if(className.equals("java.lang.String"))
{
String str=(String)obj;
events.events.get(i).from=Integer.parseInt(str);
}
else if(className.equals("java.lang.Integer"))
{
Integer intValue=(Integer)obj;
events.events.get(i).from=(int)intValue;
}

水曜日, 3月 11, 2009

Java: ディレクトリ比較

今日はちょっと会社でいやなことがあったので...

言いたいことも言えず。

だから...Javaで書いて、動くのを確認 (こうでなきゃ)。

やっぱりJavaはいい。

単なる、ディレクトリ比較のプログラムです。



/* Compare.java -- directory comparison program
*
* Copyright (C) 2009 Erica Asai

* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/

import java.io.*;

public class Compare
{
public void compare(String src, String dest)
{
try
{
File srcDir=new File(src);
if(!srcDir.isDirectory())
{
return;
}
File destDir=new File(dest);
if(!destDir.isDirectory())
{
return;
}
String srcList[]=srcDir.list();
String destList[]=destDir.list();
for(int i=0;i<srcList.length;i++)
{
int j=0;
while(!destList[j].equals(srcList[i]) && ++j<destList.length);
if(destList.length<=j)
{
System.out.println("(-)"+src+"\\"+srcList[i]);
}
else
{
compare(src+"\\"+srcList[i],dest+"\\"+destList[j]);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}

public static void main(String args[])
{
Compare compare=new Compare();
if(2==args.length)
{
String src=args[0];
String dest=args[1];
compare.compare(src,dest);
}
}
}


水曜日, 2月 25, 2009

PHP: PDOやmysqliクラスのない環境

サーバーによって、PHPの環境が違うことがあります。

特に、データベース周りでいくつものパッケージがあるため、PHPのバージョンによって書き方が変わってきます。

PDOを使っていたのに、サーバーで使えない環境だった場合。

mysqliクラスを使っていたのにサーバーでクラスが発見できない場合。

せっかくあるコードが使えないということは、コードのリユースの面から不効率です。

対策としては、mysql*関数で書き直すか、あとは自前でクラスを作る。

そんなときのために、PHPでのクラスの書き方をアップしておきます。



if(!class_exists("mysqli"))
{
class mysqli
{
public $dbname;

function __construct($host,$dbuser,$dbpassword,$dbname)
{
$this->dbname=$dbname;
echo $dbuser;
if(!mysql_connect($host,$dbuser,$dbpassword))
echo "No DB connection established";
}
function query($sql)
{
if(!mysql_select_db($this->dbname))
echo "Database not selected";
return new mysqli_result(mysql_query($sql));
}
};

class mysqli_result
{
public $records;
function __construct($results)
{
$this->records=$results;
}
function fetch_assoc()
{
return mysql_fetch_assoc($this->records);
}
};



作り方としては、mysqliクラス、PDOクラスなど、クラスを作ってメソッドを実装する形となります。

クラス間でやりとりがある場合など、クラスを作って実装します。

ソースを変えずにポータブルなコードが可能になります。

日曜日, 2月 15, 2009

PHP: Resizing image files

The way to resize image files in PHP is straight foward yet not as simple as it should be. Nevertheless, the PHP image library is equipped with image manipulation functions. Here is a function that does the job -- resizing factor should be edited to suit your needs.



function resizePhoto($fileName,$dest)
{
header('Content-type: image/jpeg');

list($width, $height) = getimagesize($fileName);
$ratio=((float)$height)/$width;
$newWidth=90;
$newHeight=(int)($newWidth*$ratio);

$thumb = imagecreatetruecolor($newWidth, $newHeight);
$source = imagecreatefromjpeg($fileName);

imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

imagejpeg($thumb,$dest);
}

土曜日, 2月 14, 2009

Xampp on Vista

Xampp mysql won't start on Vista. Moreover, the admin app emits warnings relentlessly looking for a dll. The MySQL installation must be done separately, works fine with MySQL 5.1.

The Japanese messages appear on xampp control panel and administrator page seems to have mixed interpretation of the word "stop" and "stopped".

Calling the PDO class method query() crashes Apache -- stops the service. Apache 2.2, PHP 5.2.8, MySQL 5.1 (separate installation).

木曜日, 1月 29, 2009

デジタル・フォトフレーム

ひさしぶりに電気店へ行くと、新製品がオンパレードでこの業界の進歩にいまさらながら驚いた。

デジタル一眼レフも機能が向上して、ソニーのαシリーズのものなど、自動焦点の機能が向上して「一瞬にしてピントが合う」。

フォトフレームがはやりだという。液晶モニタにメモリリーダーがついたもので、デジカメ写真・動画などが額縁感覚で飾れる。スライドショー機能はデジカメにもついており、テレビ画面につなげばそのまま画像が楽しめるが、そのまま画像が表示できる手軽さがある。大きさはさまざまで、携帯サイズの安いものから、インテリア感覚の高級品まで勢ぞろいしている。無線LAN機能がついたものもあり、ネットにつなげるという。しかし、見たところFlickrやYahooフォト、Youtubeやニコ動などとの連携はないらしい。

どうぜ小さな画面なら、iPod、ミニノートを置けばいいというのもある。電力を食うというきらいがあるが、ネット接続に苦労するということはない。DVDプレーヤーを置けばいいというのもある。

店頭で商品を見て惹かれてしまい、帰ってきて使わなくなったデジカメを取り出してテレビ画面につないだ。フォトフレーム代わりにスライドショーで眺めている。画面はテレビ画面のほうが大きく、それなりに迫力はある。

火曜日, 1月 27, 2009

ImageIO.write(): To save transparent PNG image files

The ImageIO class and its write method that comes with JDK1.60 does not support writing out transparent GIF images (at least in the way shown below). The write method of the class won't write out proper GIF format files with a transparent color. The method will create PNG files all right. The following shows how to save an image file. Suppose you have (BufferedImage)bufferedImage that you want to save:



FileOutputStream out=new FileOutputStream(fileName);
String descriptor="PNG";
BufferedImage image=new BufferedImage(right-left,bottom-top,BufferedImage.TYPE_INT_ARGB);
Graphics2D g=(Graphics2D)image.getGraphics();
g.drawImage(bufferedImage,0,0,right-left,bottom-top,left,top,right,bottom,this);
g.dispose();
ImageIO.write(image,descriptor,out);
out.flush();

金曜日, 1月 16, 2009

JFileChooser: Directory Selection



Java's JFileChooser is a handy UI component in file(s) or directory(directories) selection. As with all Java OOP classes, the set up of the JFileChooser class goes through four steps: 1. instantiate the class 2. set the parameters 3. show off the class 4. wait for the return value (is modal). The JFileChooser class works fine with file selections -- selecting a single/multiple files, setting file extension filters, and retrieve a new file name if the file does not exist.

The trouble is, the case with a directory/directories selection. The JFileChooser class can filter out all the file names, and that part is ok. But when the user enters a new directory name, the filtering would hinder the class to get the non-existent directory name. The user can not select non-existent directory name.

Here shows DirFilter class that can avoid the situation and let the application have the choice either to create or reject the user request.



class DirFilter extends javax.swing.filechooser.FileFilter
{
public String getDescription()
{
return "Directories";
}
public boolean accept(File file)
{
if(file.exists())
{
if(file.isDirectory())
{
return true;
}
else
{
return false;
}
}
else
{
file.mkdir();
return true;
}
}
}



The idea is, to set up a filter for the JFileChooser class, by passing the filter class to JFileChooser. Then the application can decide whether to create a directory of the specified name or to discard it. The filter class should be the one that FileFilter interface be implemented. A word of caution is that there are java.io.FileFilter and javax.swing.filechooser.FileFilter -- the latter should be specified.

The following shows the setting of the new filter class via addChoosableFileFilter() method.



JFileChooser dlg=new JFileChooser(".");
dlg.setDialogType(JFileChooser.SAVE_DIALOG);
dlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
dlg.addChoosableFileFilter(new DirFilter());
int retval=dlg.showDialog(this,null);
if(retval==JFileChooser.APPROVE_OPTION)
{
...

木曜日, 1月 08, 2009

DIVタグをネストすると、マージンをとった場合にIE7とFirefoxで結果が違う。

Nested DIV -- Firefox3
Nested DIV -- Firefox3
Nested DIV -- IE7
Nested DIV -- IE7

DIVタグをネストすると、マージンをとった場合にIE7とFirefoxで結果が違う。IE7は内部のブロック要素のマージンの長さだけ外部のブロックのサイズを変更する。Firefoxでは、なぜか内部のマージンに合わせて外部のブロックも移動する。しかも不可解なことに、外部ブロックにボーダーをつけると位置が移動する。要注意。

ソースはこちら→ div.html

日曜日, 1月 04, 2009

The Art of UNIX Programming

The Art of UNIX Programming という本があって面白く書いてある。記述のどこまでが反語なのか計りかねるところがまた興味深い本である。さらに、おそらくは日本などでも散見される意見がちりばめてあってより熟考を迫られる。

まず、意図的にはUNIXに檄を飛ばす内容となっている。そのための、現状の把握の過程が書かれている。数々の、名の知れた頭のよい人たちのウインクが見えるような本である。立場から、マイクロソフトにはまったく「反対」を唱え、協調あるいは融和、妥協など交渉する気配を見せていない。これは政治的闘争というものに他ならない。政治問題化しては問題は解決しない。Windowsプラットフォームの問題点として、文書形式がプロプラエタリなバイナリであること、アプリ間でデータの交換がやりにくいことなどを列挙しているが、問題の解決方法として、Windowsと対決するなどまったく現実的ではない。政治的リアリティとしては、その筋からWindows製品にも多くの注文が寄せられ、さまざまな改変が加えられている。Word文書形式のオープン化などは、強い要望によって成し遂げられた改革である。XML形式での文書データの交換形式の普及は、UNIX対Windowsの対決より、より実際的であり、効果的な解決方法である。

本書には、プログラムに関するポリシーであり助言が書かれている。簡略化すること、モジュール化すること、「美しく入り組んだ構成物」は矛盾という。データ構造が重要なこと、最適化がコードを重く長くすること、「まず動かし、正しくして、速くせよ」というKent Backの台詞を引用している。が、固陋なまでにC言語を使い、Java言語をスクリプト扱いする記述には、「Javaのほうがずっとスマートに美しく書ける」「CのライブラリよりJavaのクラス構造」といいたい。

しかし、銃保有があたかも反体制であるかのように書くのはまったくばかげている。

日曜日, 12月 21, 2008

仮想マシンでUbuntuを動かす

Windows上で、VMWareなど仮想マシンを使うと、UbuntuなどLinuxマシンを動かすことができる。

仮想マシンに置く、システムのイメージが大きいため、ダウンロードに時間がかかることに注意。

まず、VMWare Playerをダウンロードする(登録が必要)。

起動したPlayerから、「Download」アイコンをクリックして、イメージの置いてあるサイトにアクセスする。

Ubuntu
など必要なシステムのイメージを選択し、ダウンロードする。

ダウンロードしたいファイルが、BitTorrent形式のものであれば、Vuzeなどをインストールしてダウンロードする。

ファイルが7-Zipなどの形式で圧縮されていれば、解凍用アプリをダウンロードして解凍する。

Playerから、イメージを選択して起動する。

パスワードは、イメージの置いてあるサイトに記載されている。

月曜日, 12月 15, 2008

正式版となったGoogle Chromeを試す

GoogleのChromeブラウザの製品版が出たというので、早速使ってみると、軽くて速い。とまどったのは、ブックマークの登録。右クリックにも、メニューにも項目がない。ドキュメントによると、登録にはアドレスバー左の星印をクリックする。ちょっとひっかかる設定ではある。

Javascriptに関して言えば、Firefoxと異なり、document.documentElement.scrollTop に設定はなく document.body.scrollTop を使わねばならない。同様に、screen.width には設定はなく、screen.availWidth を用いなければならない。バグかと思われたのは、moveTo() と resizeTo() を続けると、最後の設定しか有効でない点。つまり、moveTo() を最後に持ってくるとウインドウのサイズの設定が崩れ、resizeTo() を持ってくるとウインドウの位置が左上(0,0)に設定される。

→ 正式版となったGoogle Chromeを試す (2008-12-12)

木曜日, 12月 11, 2008

グーグル社長が交代、ソニー出身の辻野氏が就任

Googleは9日、Googleの日本法人社長に、2009年1月からソニー出身の辻野氏が就任すると発表したという。

→ グーグル社長が交代、ソニー出身の辻野氏が就任 (2008-12-9)

日曜日, 12月 07, 2008

ブラウザ間の差違

ブラウザ間の差違による調整は、ブラウザ開発社が各社で規格を適宜変更するため、困難である。ブラウザ規格が統一されていれば、ページ製作者の苦労は軽減される。OSが統一されていれば、プログラマの仕事の大半がより創造的なものになる。しかし、WindowsおよびIEの絶対的な支配権力を要求することは、独裁下の官僚のぐちにすぎない。すべての人間が理解できる程度に同じであることを要求するのは、独裁的支配権を要求するのと同意である。異なる団体間の調整をすることは、同じであることを強要するものではない。しかし、IEのバグをかばわなければならない理由はない。Internet Explorerには、背景がスクロールで出現したり消えたりするバグがある。ズームを指定すると直るという。ほかに、IEには、改行で隙間が開くというバグがある。さらに、IEでは、DIVのスタイルがテーブルのスタイルより優先される。

月曜日, 12月 01, 2008

IE8 does not support filter:alpha ...

The hell with it -- IE8 does not support filter:alpha. It works without DOCTYPE specification but not with any of the type being spedified at the top of the page like as you would do just like a good citizen that follow all those laws and orders. Just specify IE7 mode and it works fine with the filter:alpha css or whatever. This. Here.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

Flask の Blueprint のテンプレート問題

  Flask の Blueprint は、ルート、静的ファイル、テンプレートをまとめて管理できます。しかし、テンプレートが指定できません。 ここでは、Blueprint の template_folder の問題点と回避策を説明します。 Blueprint のテンプレート問題...