水曜日, 4月 17, 2013

PHPでJava風のstartsWith()とendsWith()がない件について

読みやすさ、美しさというのもプログラムの質に影響してくるとおもいます。

startsWith(), endsWith()という関数がJavaにはあります。

文字列を比較して、指定した文字列で始まっていれば startsWith()は true を返します。

指定した文字列で終わっていれば endsWith()で true を返します。

Javaのネーミングセンスは最高だと常々思うわけですが、これらの関数はPHPにはありません。

substr_compare()という関数を使って startsWith()とendsWith()を実現してみました。

#文字長を制限し比較するよう変更しました(2013-06-05)。

function endsWith($haystack,$needle,$case=FALSE)
{
  $len=mb_strlen($needle);
  if(0<mb_strlen($haystack) && mb_strlen($needle)<=mb_strlen($haystack))
    $res= (substr_compare($haystack,$needle,-$len,$len,$case)==0);
  return $res;
}

function startsWith($haystack,$needle,$case=FALSE)
{
  $res=false;
  if(mb_strlen($needle)<=mb_strlen($haystack))
    $res=(substr_compare($haystack,$needle,0,mb_strlen($needle),$case)==0);
  return $res;
}


火曜日, 3月 26, 2013

Firefox で「パスワードを保存しますか」が危険な件について

Firefoxのデフォルト設定では、ログイン時に
 「ID/パスワードを保存しますか?」


と聞いてきます。

ここでID/パスワードを保存すると、次にログインするときには自動で値が設定されます。

確かに便利な機能ではあるんですが、これなんとテキストでそのまま見えてしまうんですね。

パスワードはパスワードであって、テキスト表示されるのはセキュリティ上問題がある、と考えられる方は以下のサイトでパスワードを削除できます。

「オートコンプリート」機能で保存されたパスワードの削除方法

 

木曜日, 1月 10, 2013

jQueryでページ内移動するには

ページ内移動には、ページ内アンカータグなどを指定して移動します。

index.html#position といった形で指定してやると、その箇所にページがスクロールします。

ページ内アンカータグについては、アンカータグでname属性を、divタグでid属性で指定します。

では、jQueryではどう処理するか、というのが表題の「jQueryによるページ内移動」です。

以下はアニメーションでページをスクロールするスクリプトです。

     var y=getY(document.getElementById("top"));
     $('body,html').animate({
      scrollTop: y
   }, 800); 

木曜日, 11月 29, 2012

Microsoft Seminar: "The New Era of Work" (Windows 8)

Chicago
At the Microsoft hosted seminar "The New Era of Work", it claimed the year 2012 is an important era for the operating systems, which will incorporate touch screen capabilities, mostly due to the widespread use of mobile phones and tablets. 

Windows 8 does come with the brand new Metro style interface with boxes occupying the screen rather than icons, together with gesture recognition.  Swiping down will close the applications.  SNS updates will be tied with your directory information.  Picture password.  Start typing in and the app comes up, the Microsoft IT evangelist Brian Lewis told the audience.  It took him half a year just to come across the feature, he said. 
IT Pro Evangelist: Brian Lewis

Microsoft has a Metro style app store online.  The apps are searchable there as well, including those being sold online.  On app search box, a question came from the audience.  Can you set parental permissions? There the speaker offered a very modern answer to all possible questions.  Go online, visit his site, ask him the question there. 

http://mythoughtsonit.com/ITcamp/

There should be a lot of questions indeed.  Microsoft claims to have authority over all Metro apps distribution.  Developers need to get its approval to put their apps online for use for other machines than theirs.  Can Microsoft then take the sole responsibility of the apps? How long will be the wait time?  Would the developers' rights be severely restricted?  There are reports that the pre-installed Windows 7 apps seem to run, but the installers may not work.  It costs $49 (personal) or $99 (corporate) to submit your apps for sale at the Windows Store.

Windows 8 is going to be installed in EVERY machine available in the market.  FSF, the Free Software Foundation is asking for signing the petition: "Windows 8 doesn't offer me the privacy and freedom I deserve. I won't be upgrading to Windows 8; instead, I'm standing with the free software movement."

We had a little discussion on this topic back here.  Would it is not practical for Microsoft to have oversight over all Metro apps?  The Apple store does that, they told me.  It is for security and to make money. 

Other topics that got many asking questions is on Windows to go or USB/SSD to go feature that can put your system in the removable storage and boot the system from there.  There are such bootable image available online but not from Microsoft official site.  Now it is all possible to carry your system along wherever you go.  The questions from the audience: Security?  Partitions?  Data protections?  Will it erase the data?  There was no question, however, on how to prevent pirated such bootable systems from being sold.  Will it be protected from piracy?

Microsoft Seminar: "The New Era of Work" (Surface)

Chicago

Microsoft hosted a seminar in Chicago on Wednesday titled "The New Era of Work".

Microsoft claims this is the new era of for Operating Systems.  The Internet, iPhone/iPad, and cloud has changed the nature of computer systems. 

Microsoft has long been pushing for tablet machine for some time.  And the competition is a nice thing.  The latest iPad 4 offers hardly hardware improvements other than resolution.

At the conference room, the Surface RT's were on display along with Lenovo and Toshiba machines.  All those tablet machines have no home buttons.  Swiping out to the edge does the trick.  And they come with keyboards. 

At the Surface booth, they explained to me that Surface RT has somewhat unique capability that Apple's iPad does not.  It works as a remote terminal and runs apps on the host machine just like a workstation.  That, is a wonderful idea, I thought.  There could be many application for it.  "Can you show me how it works?" I asked.  The machines are not connected, they told me.  They were not able to show me how it works as a terminal. 

The only reason why iPad or iPhone can not be loaded as a removable drive is because of security concerns.  The MP3's and eBooks are copyright protected.  If only those directories that contain the copyrighted files then they will be more accessible by the possibly criminals.  What the remote terminal does is that the files in tablets would be accessible freely.  The remote terminal apps might have security concerns. 

Instead of that wonderful feature, they showed me the Surface apps fully loaded with shop icons.  The sight of the ads of all those stores on the screen overwhelmed me.  It looked much bigger than the simple and elegant Apple Store.  "This may change the business style, and consumer life style", keynote speaker said. 

So how about Surface Pro?  The new version of Surface runs on Intel chip.  It means, it runs Windows 8.  And that means, every desktop apps should work on Surface Pro.  Would it be a killer machine?  Does that mean my desktop apps works on my tablet machine?  "You must recompile all apps for that machine," one of the participants told me.  "Surface Pro will be coming in January," the Microsoft people told me.  "The pricing is not yet announced.  It will be as big as the RT machine," they said in answering my questions. 

to be cont.

火曜日, 11月 27, 2012

ボックスレイアウトが absolute で破綻

表題の通りです。

Firefox, IE でボックスレイアウトを使用する場合。

位置指定に absolute を指定するとレイアウトが壊れます。

<div style="display:box;display:-moz-box;display:-webkit-box;position:absolute;top:100px">
<div style="width:100px;height:100px;border:1px solid blue"></div>
<div style="width:100px;height:100px;border:1px solid blue"></div>
</div>

見事に人柱となった気分です。

#厳格とかいう問題じゃないですよね。これ。

月曜日, 11月 19, 2012

Google Analytics API: フィルターをつける

本日の出来事。

ダメ上司の典型。「これネットで見付けんたんだけどどお」
どおって... システム全部書き直せって?

え、あのタグってこちらがつけたものじゃないし、むこうが取り外すだけで話は解決じゃないでしょうか。
こちらがフィルターつけて取り外すのって、それって仕事の一部ですか?!

で、仕事が遅くなったとかいって嫌がらせ。最低。最悪。ほんと性格と頭が悪い。

愚痴はさておいて。本題。

Google Analytics のデータを取り出す方法。

フィルターをつける場合について、書いておきます。

$filter="ga:hostname!=ホスト名";
$ga->requestReportData(homepageId,null,array('pageviews','visits','bounces','entrances','timeOnSite','exits','newVisits'),null,$filter,$startDate,$endDate);

火曜日, 11月 13, 2012

IEでリンク切れ画像を表示しない

リンク切れ画像は、Firefox では表示されません。

ところが親切設計の IE や Chrome では、画像が見当たらないとそれ専用のアイコンを表示してしまいます。

これで困ったのが、画像リンクを利用してスクリプトを走らせるハックを使うアクセス統計サービスの場合。

きちんと表示されれば問題なく img タグだろうとなんだろうと構わないわけですが、ところがサーバーの都合でスクリプトが動かないという状況が発生。

動かないだけ「画像ありません」というアイコンかしっかり表示されてしまいました。

アクセス統計などアナリティクスに任せとけばいいのに、マイナーブランドなど使うからサーバーの都合で対応をせざるを得ないはめに。

そこで、画像切れリンクは問答無用で「表示しない」という方針といたしました。これで振り回されずにすみます。

本題へ。リンク切れ画像の IE と Chrome 対応策です。

img タグのすべての要素を取り出し、画像読み込みが終らないものをすべて非表示とすればよいようです。

$(function(){

$('img').each(function(){

if(!this.complete){
$(this).hide();
return;
}

});

});

月曜日, 10月 29, 2012

Object-C 文字列;Makefile

Object-Cでは文字列はNSStringなどを使うことができます。

文字列へのポインタとして扱うことができます。

メンバ関数 UTF8String を使うと、char*として扱うことができます。


#import <stdio.h>
#import <foundation/foundation.h> 
#import <Foundation/NSObject.h>

@interface Verb:NSObject
-(void)print: (NSString*)stem;
@end

@implementation Verb
-(void)print: (NSString*)stem
{
  char* str=[stem UTF8String];
  printf("%sim\n",str);
  printf("%sis\n",str);
  printf("%si\n",str);
  printf("%sime\n",str);
  printf("%site\n",str);
  printf("%si\n",str);
}
@end

int main()
{
  NSString *stem=@"rozumim";
  id obj=[Verb alloc];
  [obj print:stem];
  return 0;
}

GNUmakefile ファイルにおいて、以下のようにコンパイルの条件を指定すると、make 一発でコンパイルできます。

GNUSTEP_MAKEFILES=c:/GNUstep/GNUstep/System/Library/Makefiles
include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = verb
verb_OBJC_FILES = verb.m

include $(GNUSTEP_MAKEFILES)/tool.make


土曜日, 10月 27, 2012

Objective-Cのプロトコルとは

Objective-C では、クラス継承の際に必須のメソッドを規定するプロトコルという概念があります。

まさしく、Java でいうところのインターフェースの概念と同じもので、メンバ関数を持たないクラスとして実装されます。プロトコルで指定されるメソッドは宣言のみで、抽象クラスとして実装されます。

#import >stdio .h=".h">
#import >foundation bject.h="bject.h">

@protocol ToString
-(void)toString;
@end

@interface Test:NSObject>tostring>
@end

@implementation Test
-(void)toString
{ 
  printf("This is class Test.\n");
}
@end

int main()
{
  id obj=[Test alloc];
  [obj toString];
  return 0;
}



火曜日, 10月 23, 2012

Objective-C のクラスメソッド

Objective-Cにも静的なメソッドというものがあります。

Objective-Cの用語ではクラスメソッドというものです。

Javaでいうところのstaticにあたります。

当然ながら、メンバ変数を持つことはありません。

メソッドの宣言に+(プラス記号)をつけます。

#import <stdio.h>
#import <Foundation/NSObject.h>

@interface Test:NSObject
{
  int index;
}
- (void) hello;
- (void) setIndex:(int) i;
+ (void) dump;
@end

@implementation Test
- (void) setIndex:(int) i
{
  self->index=i;
}
-(void)hello
{
  printf("Hello NSObject %d\n",self->index);
}
+(void)dump
{
  printf("Class method = static");
}
@end

int main()
{
  [Test dump];
  return 0;
} 

他にも@propertyや@synthesizeなどいうキーワードがありますが、GNUstepはサポートしていません。

参照先がreleaseされたときの挙動を変えるものです。
@property(nonatomic, assign)
@property(nonatomic, retain)

月曜日, 10月 22, 2012

OOP, any problems?

Do not compare apples and oranges.

OOP is implemented as an extension of C.  But it is a completely different concept. 

What is good about OOP is the change of the design framework of programming.  Say, Lisp can be converted to C and that indeed is what the compiler does.  But they are different languages with more focuses on its abstraction.  Likewise, OOP is a way of abstraction, a way to express it.

Writing in Lisp is different from writing in C.  They are not interchangeable.  It may be the same to the machine but not to programmers.

Not even knowing the importance of its concepts and talking about issues of implementation, is somewhat like looking at trees and not seeing the woods.

It is just a way to devalue OOP. 

The reason why they are to denigrate the importance of the revolution, is totally of theirs, not ours.

In the year 2012, why should we need to emphasize the importance of OOP for Pete's sake?

Please.  Let us have the freedom of thoughts and religions.

日曜日, 10月 21, 2012

Object-Cのクラスについて

それでは試行錯誤でどうやら動くようになったGNUstepの話の続きを。

Object-CはC++に似て、クラスの定義にヘッダーを必要とします。

変数・関数の宣言に順番を気にしなければならなかったCの名残りといえるでしょう。

定義と実装は別々に行います。

Javaの場合には、そんなものは必要がなく、publicクラスにそれぞれ独自のファイルを用意してクラスの実装のみを記述します。

#importでクラスを指定さえすれば、順番も関係なく使用することができます。

Object-Cのクラス宣言と実装、呼び出しの方法を下記に示します。

#import <stdio.h>
#import <Foundation/NSObject.h>

@interface Test:NSObject
-(void) hello;
@end

@implementation Test
-(void)hello
{
  printf("Hello NSObject\n");
}
@end

int main()
{
  id obj=[Test alloc];
  [obj hello];
  return 0;
}

コンパイラオプションはこちらを使いました。
gcc nsclass.m -I c:/GNUstep/GNUstep/System/Library/Headers -L c:/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base 


Objective-Cは引数の指定の仕方が独特です。

型をいちいち指定して呼び出します。

Javaのように引数とメンバ変数を同名にすると警告が出ます。

#import <stdio.h>
#import <Foundation/NSObject.h>

@interface Test:NSObject
{
  int index;
}
- (void) hello;
- (void) setIndex:(int) i;
@end

@implementation Test
- (void) setIndex:(int) i
{
  self->index=i;
}
-(void)hello
{
  printf("Hello NSObject %d\n",self->index);
}
@end

int main()
{
  id obj=[Test alloc];
  [obj setIndex:10];
  [obj hello];
  return 0;
}

土曜日, 10月 20, 2012

Windows で GNUstep を使った Object-C プログラミング

iPad が隆盛を極めてはや数年、マイクロソフトもついに(高額)タブレットPCを発売。

キーボードに凝りまくったというCMがネットで流れています。26日にはARMベースのマシンが発売されます。

最安モデルで499ドル。まさにアップル並みの値段。

競合モデルとしては、もっさりと遅いでも安いAndroidマシンか、アップルの小型iPadマシンか。

1月には Windows 8 ベースのマシンが発売されます。

Windowsベースのアプリが動くとなれば、これは革命です。


開発者として、傲慢なアップルの「開発しにくくしてカネをとろうとする」態度は正直なところ好きになれません。

頭(か性格か)の悪すぎるやりかただと思います。

と正直な感想から、Object-Cのはなし。

WindowsでもGNUstepというプロジェクトがあって、Object-Cでプログラムが書けます。

こちらを参照しました。

OOP言語であるObject-Cですが、C#よりJavaに遠い。

PC販売に影響したというタブレット市場がどのように変化していくのか、新製品を横目にプログラムにいそしむ週末になりそうです。

金曜日, 10月 05, 2012

Elispで文字列置換

久しぶりに elisp でプログラム。

オープンソースの始祖であるところのGNUの鉄則に従って、書いた分だけここに置いておきます。

文字列変換というごくごくシンプルなものですが、変換後にバッファでのポイントの位置がずれることに注意。

(defun replace-tags-region (from-string to-string begin end)
"Replaces from-string to to-string in the region from begin to end."
  (let ((len (- (length to-string)(length from-string))))
    (goto-char begin)
    (while (search-forward from-string end t)
      (replace-match to-string t)
      (setq end (+ end len)))))

(defun replace-tags-list (tag-list)
"Takes a list of (from-string to-string) and replaces all from-string to to-string in the buffer."
  (replace-tags-region (car tag-list) (cadr tag-list)(point-min)(point-max))) 

  

;; Usage:
;; (setq tag-list '(("TABLE" "table")("TD" "td")("TR" "tr")))
;; (replace-tags tag-list)

(defun replace-tags (tag-list)
"Takes a list of lists of (from-string to-string) and replaces all from-string to to-string in the buffer."
  (mapcar 'replace-tags-list tag-list))

(defun create-end-tag (tag-name)
  "Creates closing tag from the given tag-name."
  (concat "</" tag-name ">"))

(defun create-half-begin-tag (tag-name)
  "Creates opening tag from the given tag-name."
  (concat "<" tag-name " "))

(defun create-attribute-tag (tag-name)
  "Creates attribute string from the given tag-name."
  (concat " " tag-name "=\""))

(defun create-begin-tag (tag-name)
  "Creates opening tag from the given tag-name."
  (concat "<" tag-name ">"))

 

;; Usage:
;;(setq tag-list '("TABLE" "TD" "B" "BR" "A" "HTML" "NOSCRIPT" "SCRIPT" "HEAD" "BODY" "TR" "TITLE" "I"))
;;(mapcar (lambda (x)(create-replacement-list 'create-end-tag x)) tag-list)
(defun create-replacement-list (create-list tag-name)
"Creates a list of tag name and lowercase tag name lists."
  (cons (funcall create-list tag-name) (list (funcall create-list (downcase tag-name)))))

(defun lowercase-html-tags()
"Converts uppercase HTML tag names to lowercase."
  (interactive)
  (let* ((tag-list '("TABLE" "TD" "B" "BR" "A" "HTML" "NOSCRIPT" "SCRIPT" "HEAD" "BODY" "TR" "TITLE" "I"))
  (attribute-list '("VALIGN" "ALIGN" "WIDTH" "HEIGHT" "BOTTOM" "CLASS" "BGCOLOR" "BORDER" "LEFT" "RIGHT" "TOP" "CELLPADDING" "CELLSPACING" "BORDERCOLOR" "CENTER" "MIDDLE" "HREF" "COLSPAN" "ROWSPAN" "SRC" "onMouseOver" "onMouseOut" "ALT" "NAME" "ID" "VSPACE" "LINK" "META" "LEFTMARGIN" "TOPMARGIN" "MARGINWIDTH" "MARGINHEIGHT" "onLoad" "BACKGROUND" "TYPE" "HTTP-EQUIV" "CONTENT" "REL" "LANGUAGE"))
  (half-tag-list '("TABLE" "TD" "A" "IMG" "LINK" "META" "SCRIPT" "BODY" "TR" "DIV"))
  (replacement-end-tags (mapcar (lambda (x)(create-replacement-list 'create-end-tag x)) tag-list))
  (replacement-begin-tags (mapcar (lambda (x)(create-replacement-list 'create-begin-tag x)) tag-list))
  (replacement-half-begin-tags (mapcar (lambda (x)(create-replacement-list 'create-half-begin-tag x)) half-tag-list))
  (replacement-attribute-tags (mapcar (lambda (x)(create-replacement-list 'create-attribute-tag x)) attribute-list)))
    (replace-tags replacement-attribute-tags)
    (replace-tags replacement-end-tags)
    (replace-tags replacement-half-begin-tags)
    (replace-tags replacement-begin-tags)))

水曜日, 9月 19, 2012

IE でCSS3の display:box を使うには、flexie.js を使えばいい

そうです。IEはまだCSS3の display:box 仕様に対応していません。

このボックス仕様を使うと、横並びのボックスがエレガントに書けます。


外側のDIVに、このように指定します。

    display: -webkit-box;
    display: -moz-box;    
    display: box; 
 
内部のDIV要素がきれいに並んでくれます。
 
ただし、上記のようにIEには対応していません。

そこで、この flexie.js を導入すると、見事に横並びボックスが実現できます。

ダウンロード:http://flexiejs.com/
 
これでページのHTMLタグが整理できそうです。
 
 

土曜日, 9月 08, 2012

シームレスの背景画像をGIMPで作るには

シームレスの背景画像をGIMPで作るには、メニューからFilters|Map|Make Seamlessを選択します。

すると画像を一発でシームレスにできます。

こんな感じです。

http://easai.web.fc2.com/odonata/photoindex/


木曜日, 9月 06, 2012

Excel のマクロを消すマクロ

Excel のマクロを消すマクロを書こうと思ったら、警告が出ました。

マクロはこんな感じです。

こちらのページ「VBAでマクロのソース削除と標準モジュール削除」を参照させていただきました。

Dim objVBCOMPO     As Object
        For Each objVBCOMPO In ActiveWorkbook.VBProject.VBComponents
            With objVBCOMPO.CodeModule
                If .CountOfLines <> 0 Then .DeleteLines 1, .CountOfLines
            End With
            If (objVBCOMPO.Type = vbext_ct_StdModule Or objVBCOMPO.Type = vbext_ct_MSForm) Then
                ActiveWorkbook.VBProject.VBComponents.Remove objVBCOMPO
            End If
        Next objVBCOMPO
        Set objVBCOMPO = Nothing
End Sub


これをデフォルトの設定で走らせると警告が出ます。



これは、マクロセンターの Trust access to the VBA project object model オプションをオンにすると動くようになります。

金曜日, 8月 31, 2012

クリックで表示を切り替える(単位変換など)

米国での長さの単位はきわめていまいましいことにすべてインチ・フィートです。

 ここで、インチ・フィートに要素を変換する jQuery スクリプトを示します。

 $(document).ready(function(){
  $(".millimeters").hide();
  $("#convertIN").click(function(){
   $(".millimeters").hide();
   $(".inches").show();
      });
  $("#convertMM").click(function(){
   $(".millimeters").show();
   $(".inches").hide();
      });
     });

JQuery であると容易に要素の表示を切り替えることができます。

 ... there was a question in the Reddit session to Obama whether the US would ever move to metric system.

リンクをかけたブロックの中に、別のリンク先に飛ぶエレメントを置く

リンクをかけたブロックの中に、別のリンク先に飛ぶエレメントを置きたいとします。

ブロックにはリンクがかかっているので、内部の要素をクリックしてもリンク先に飛んでしまいます。

どのようにリンクを無効にするか。

jQuery には event.preventDefault() というメソッドがあります。

これを呼ぶと、ブロックにかかっているリンクを無効にできます。

     $(document).ready(function(){
         $(".クラス名").click(function (event){
             event.preventDefault();
             document.location="飛ばしたい先のアドレス";
         });
     });


これで、内部要素をクリックすると、ブロックにかかっているリンクを無効にして指定されたアドレスに飛ぶよう指定できます。

(はいはい。ブロックにリンクをかけるというのは推奨されない方法です。)

水曜日, 8月 29, 2012

好みのエディタでオンラインの文章を編集する

ブログ編集画面などで、テキストエリアの文章を好きなエディタで編集可能な Firefox のアドオンがあります。

→ It's All Text!

このアドオンを使うと、テキストエリアにボタンがついて、押すと指定されたエディタが起動します。

ホットキーやエディタの設定は、Firefox のメニューから、Add-ons の Extensions で設定します。

 It's All Text の Options ボタンを押すと、設定画面が表示されます。


このアドオンがあると、オンラインでのテキスト編集の精神的負担が軽くなります。

ブログなどでオススメです。

火曜日, 8月 28, 2012

xampp 1.8 にアップグレードしました。

xamppをアップグレードしました。Ver. 1.8が最新のようです。

MySQLもアップグレードとなるので、データベースも移動することになります。

このあたりは、data以下をすべてまるごとコピーでOK。

phpMyAdminでID/Passwordの設定を行ってデータベースがきちんと移動できたかどうかを確認して一安心。

ファイル: config.inc.php
$cfg['Servers'][$i]['user'] = 'ユーザー名';
$cfg['Servers'][$i]['password'] = 'パスワード';

PHPのデフォルトがすべての警告を表示するとなっているので、まずそいつに黙ってもらって無事にアップグレードを完了。

ファイル: /php/php.ini
;error_reporting = E_ALL | E_STRICT
error_reporting = E_ERROR

を使えるようにして、curlを有効にする。

short_open_tag = On

extension=php_curl.dll
 
コントロールパネルもアップグレードされておりました。

月曜日, 8月 06, 2012

Excelのキャッシュをクリアする

Excelマクロの問題です。

サブルーチンの文字を書き換えるとExcel自体が壊れる。

といういかにもプログラミング環境の不備という問題に直面しました。

プレコンパイルしているとすればキャッシュファイルを消すという手順が必要となるわけですが、ネットに情報がない。

ActiveXのキャッシュがあるとされる場所には.exdファイルは見当たらず。
C:\Users\ユーザー名\AppData\Local\Temp\VBE

...

結局サブルーチン名を書き換えるということで問題を解決。

木曜日, 8月 02, 2012

Windows上でepubを作成する方法

とはいっても、改造したファイルをepub形式に変更する方法の紹介です。

.epubファイルは、.zipファイルそのものです。拡張子を.zipにして 解凍するとファイルが読めます。

基本的にはxhtmlファイルで構成されます。

音声を追加したい場合には、xhtmlファイルにaudioタグを追加します。

<audio autoplay="false" controls="true" src="ファイル名"></audio> 
 
改造したファイルをepub形式に変換するときは、単に圧縮するだけでは.epub形式とはなりません。 

Windows上でepubを作成するには、

memetypeは圧縮しない。まずmimetypeをzipファイルに変換。
次いで他のファイルを追加する。拡張子を.epubに変換する。→完成



月曜日, 7月 16, 2012

cygwin 上でGCC 4.6.3 を導入して range-based-for を使う

range-based-for を使いたくて、g++4.6.3 にアップグレードしました。

cygwin の最新版は 4.5で、range-based-for は実装されていません。

[windows][cygwin]最新のg++コンパイラをCygwin上で導入する

コンパイルには ↑ このページを参照させていただきました。

↓ ソースはここからダウンロードできます。

GCC miror sites

 range-based-for を使ったコードを以下に示します。

#include<iostream>
using namespace std;
int main()
{
  int arraytest[5]={1,2,3,4,5};
  for(int i:arraytest)
    cout<<i;
  cout<<endl;
  for(int &i:arraytest)
    i=0;
  for(int i:arraytest)
    cout<<i;
}
コンパイラオプションは以下の通り。
$> g++ -std=c++0x range.cc

日曜日, 7月 15, 2012

chronoの使い方のメモ。

c++11で定義されているchronoの使い方のメモ。
#include <iostream>
#include <chrono>

int main()
{
  auto tp=std::chrono::system_clock::time_point();
  std::time_t t=std::chrono::system_clock::to_time_t(tp);
  std::cout << std::ctime(&t)<<std::endl;

  std::chrono::seconds sec(10);
  std::chrono::minutes min(3);
  auto result=sec+min;
  std::cout << result.count() << std::endl;
}
コンパイラのオプションは以下の通り。
/usr/bin/g++-4 -std=c++0x chrono.cpp
c++11ではラムダ式も使えます。
std::cout << [](int x, int y){return x+y;}(1,2) << std::endl;

土曜日, 7月 14, 2012

Java 5.0 可変長パラメータとfor-each

メモのために可変長パラメータとfor-eachを使ったコードを載せておきます。

public class VarLen
{
    int sum(int ... list)
    {
 int s=0;
 for(int i:list)
     {
  s+=i;
     }
 return s;
    }

    public static void main(String args[])
    {
 VarLen varLen=new VarLen();
 System.out.println(varLen.sum(1,2,3,4,5,6,7,8,9,10));
    }
}

金曜日, 5月 11, 2012

データベースでレコードを複製したい場合。

既出だとは思いますが、データベースでレコードを複製したい場合。

このテーブルの場合、IDがauto incrementで主要キーに指定されています。

複製したいレコードのIDを指定し、SELECT構文で値を取得。

その値を新規レコードとして登録します。

INSERT INTO pages SELECT '',title,contents,url FROM pages WHERE ID=$id

木曜日, 4月 12, 2012

Firefoxでフロート位置が不可思議な件

HTMLは常にシーケンシャルでコードを読み解きます。

ところが float などを指定すると、位置が自動的に計算され、時には思いもよらない場所に要素が出現します。



  <div style="padding-bottom:0px;">       <div style="float:left;"> Floating block       </div>   </div>
<div style="margin: 20px 0;border:1px solid red;"></div>


フロート要素があって、marginつきのブロック要素が並んでいます。

では、この場合どちらの要素が先に表示されるでしょう。

FirefoxとIEでは結果が違います。

IEではそのまま表示されます。つまり、フロート要素が上に表示されます。

ところが。Firefoxで見てみると分かりますが、Firefoxではブロック要素が上に表示されます。

そして、さらに不思議なことに、paddingを0ピクセルではなく1ピクセル以上に指定するとまた順番が逆になります。

同じコードでブラウザによって見え方が異なる困ったケースのひとつと言えるでしょう。

月曜日, 4月 02, 2012

Javaの内部匿名クラスからローカル変数にアクセス

Javaの内部匿名クラスから、実はローカル変数にアクセスできたわけですね。

finalをつけておくとコンパイルできます。

(finalでなければコンパイルできません。)


 public class Closure
{
    class Test{};
    
    Closure()
    {
    final int i=0;
    (new Test()
    {
        void test()
        {
        System.out.println(i);
        }
        }).test();
    }

    public static void main(String args[])
    {
    Closure closure=new Closure();
    }
}

もちろん値は変更できません。:)


水曜日, 3月 14, 2012

PHP: get relative path expression

The following code calculate the difference of paths given and return a relative path expression.
 

function getCommonPos($s0,$s1) {   $len=strlen($s0);   $len1=strlen($s1);   if($len1<$len)     {       $len=$len1;     }   while($s0[$i]==$s1[$i] && ++$i<$len1);   return $i; } function diffStr($s0, $s1) {   $pos=getCommonPos($s0,$s1);   $end=strrpos(substr($s0,0,$pos),"\\");   return substr($s0,$end); } function countSlashes($str) {   return substr_count($str,"\\"); } function getRelativePath($p0,$p1) {   $p0=realpath($p0);   $p1=realpath($p1);   $dir=diffStr($p0,$p1);   if(!empty($dir))     {       $n=countSlashes($dir);       $path="";       for($i=0;$i<$n;$i++)     {       $path.="..";       if($i<$n-1)         {           $path.="\\";         }     }     }   $newDir=diffStr($p0,$p1);   $newDir=$path.$newDir;     if(empty($newDir))     $newDir=".";   return $newDir; }

日曜日, 3月 11, 2012

Creating bookmarks with Silhouette Cameo

As the Silhouette Cameo is here, I wrote a Java program to draw regular convex polygons and cut out shapes from paper.  The photo shows the final product, a bookmark.  You can put any of your design into 'production'.  With Silhouette Cameo, you get the final products right away. 



The Studio software detects the outline of shapes automatically.  The procedure would be as follows:

  1. Print out shapes with your own software or draw it with Studio.
  2. Select Object|Trace... from the menu. 
          

            
    1. Click the "Select Trace Area" button.
            
    2. Select the area of the figure.
            
    3. Select "Trace Outer Edge".
            
    4. The red line appears surrounding the image.
            
    5. Delete the original image.
            
    6. Edit the outline.  Typically you would want to "Edit Points" from the left column of the window.
            
    7. When the editing is done, click the Silhouette icon from the tool menu.
            
    8. Place the paper on the cutting mat and set it to the machine.
            
    9. Click "Cut" button when everything is ready.
           


Send any shapes to Silhouette and find designs of your choice.  Try cutting shapes and figure out balances and sizes that fit your needs.  

土曜日, 3月 10, 2012

Silhouette Cameo arrived

Silhouette Cameo, the cutting machine arrived yesterday.

Silhouette Cameo

This is the machine of the future. Basically what this machine does is to cut flat and thin materials in any shapes that you specify. It should cut anything paper made that you look at in our lives, including packages, cards, paper craft, etc.

Shamrock

What more, it can detect markings on a printed surface. Any figures that can be printed out on a piece of paper can be cut out. There are a lot of designs for 3D models made out of paper.


A word of caution is that creating cutting pattern can be a little tricky and time consuming. Very thin materials such as copy paper needs extra caution to take it off from the adhesive mat. Heavier thicker paper than copy paper would do a better job.

This paper cutting machine opens up great many fronts in many areas of technologies, sciences, and crafting. This is an excellent tool for education as well. Cut shapes would appeal more to students. The assembled 3D models is much more than the printed images of polygons. Printing out the images of makes 3D modeling not only makes it much more fun but means even more to students of science when it has three dimensions.

Free download of the Silhouette Cameo Studio is here: silhouettestudio

金曜日, 3月 02, 2012

Screen refresh trigger of an input element value or src change

To which extent does a browser redraw the screen?  Would an element's value change trigger refreshing the screen?  

It turns out to be that the Javascript's setting values of an element, actually does not trigger redrawing. 

document.getElementById("test").value="new value";

What puzzled me was, why then the browser redraw the screen in case with setting an img element's src?

document.getElementById("test").src="data:image/png;base64, ...";

This makes it trickier to implement functions that changes value, or src since the behavior will differ when you would want to retain some values for the session.  

I hit upon this problem when I tried to implement a div section that is shown and hidden at a trigger of pressing a button.  The functionality was implemented in the Javascript function and first I implemented it so that it alter the value of an input element.  It worked.  When you press the button, the Javascript function altered the value of the type='button' input element, without refreshing the screen, that is retaining all the variable values.  Then I switched it so that it would alter an image of an type='image' input element.  Now it does not work.  It reset and initialized the screen, namely to a certain initial state and not the state that was specified as. 

日曜日, 2月 19, 2012

Holiday thoughts; high-tech items of the (very near) future

There are four items that I want to purchase.  All of them, I feel the future; with the advancement of technology, or rather, the availability of it.  So much can be accomplished with the right idea, better concepts, and better management. 

One is, Raspberry Pi, a small Linux box that costs $25, or $35 with network connection.  Just at those prices, the full fledged net book equivalent machine power will be offered to so many people in the world.  The 'charitable' organizations offer them 'for educational purposes' -- never a Windows machine.  With its graphics chip that can connect to TV screens, however, this can be a game changer. 

Another is, Craft ROBO, a cutting plotter.  There are numerous other machines that cuts paper, plastic, vinyl sheets, and other materials, but this machine, cuts items that are drawn on your PC.  No cartridges, no nonsense about those black-boxes to set cut patterns.  Its software takes a figure, calculate the outline, and the machine cuts it out for you.  Unfortunately, the latest model is out of stock.  Its manufacturer, Graphtech Inc, says the new model would be coming in March 2012. 

The other is, iPad3 or Windows 8 tablet PC.  App-wise, the share number one is the Android machines, however.  The Windows 8 tablet PC on ARM is yet to come, reportedly in March. 

Lastly, it is the 3D printer.  There are many types of them; stacking shaped plastic lump, cutting out a shape from a resin block, or even binding composite powder layer by layer.  iModela might be the one, but I need more research on these.  Taking out a plastic material, shape them in the way that you like as in printing figures on paper, and use them as in any way that you like, in modeling for fun and for any other useful purposes in research and engineering, replaceable parts of an equipment anywhere, etc.

水曜日, 2月 15, 2012

PHP's overload: __call()

In my last blog, I wrote about PHP's get/set "overload", or hooking those methods for private members. There are more overloading method in PHP. The __call() method overload methods. This method "overloads" hidden member functions; including those methods that are non-existent. That is, you can create on the spot a brand new method just by calling __call().
class Test
{
  function __call($name,$parameter)
  {
    $value=$parameter[0];
    switch($name)
      {
      case "round":
        $value=round($value);
        break;
      case "floor":
        $value=floor($value);
        break;
      case "ceil":
        $value=ceil($value);
        break;
      }
    return $value;
  }
}

$test=new Test;
echo "Rounding: round(16.4) = ".$test->round(16.4);
echo "<br />";
echo "Floor: floor(16.4) = ".$test->floor(16.4);
echo "<br />";
echo "Ceiling: ceil(16.4) = ".$test->ceil(16.4);
echo "<br />";
This actually is a potential technological breakthrough -- in that the methods bears arbitrary names that are pseudo-defined and typed not dynamically then at programming time. This is a conceptual revolution in the programming. Remember, OOP is just a different form of C's structure.
Rounding: round(16.4) = 16
Floor: floor(16.4) = 16
Ceiling: ceil(16.4) = 17

月曜日, 2月 13, 2012

"Overload"? or hooking get/set in PHP

In PHP, there are a set of functions that hooks getting and setting private member variables.  When the variable is set, __set() method will be called.  When the variable is accessed, __get() method is called.  In PHP's terminology, hooking variable definition and retrieval are called overloading. 

class HookTest
{
private $a=1;

public function __get($name)
{
  echo "$name is being retrieved<br />";
  return $this->$name;
}

public function __set($name,$value)
{
  echo "$name is being set<br />";
  $this->$name=3;
}
}

echo "<pre>";

$test=new HookTest;
$test->a=2;
echo $test->a;

金曜日, 2月 10, 2012

Newline in select-option tags

Our site had a list of fonts available for our clients. The list included, European and Cyrillic fonts. We put them in a drop-down list.

List of fonts:
     European
     Cyrillic

Then, it turned out to be that Cyrillic fonts were included in European fonts. We had to select/deselect both at the same time. The trouble is, the HTML's select's option does not take br tags, or new lines. All lines have to be in a single line. Here is a jQuery code that select/deselect European and Cyrillic fonts at the same time. The code hooks any click on the European fonts to a handler that select/deselect Cyrillic fonts.
 
    $('#European').live("click",function(){
     var selected=$('#European').attr("selected");
     if(selected=="selected") 
  {
      $('#Cyrillic').attr("selected","selected");      
  }
     else
  {
      $('#Cyrillic').attr("selected",false);      
  }    
 });

Here is a word of caution; we had yet another problem with the Cyrillic option with the reset operation. The Cyrillic option has to be deselected manually.
 
    // de-selects the Cyrillic option.
    $("#reset").click(function(){
         $('#Cyrillic').attr("selected",false);      
 });

水曜日, 1月 25, 2012

同じエレメントを指定して、なぜか表示が変わらない。

スタイルシートというのは、いまだ原始的な形態を保ち続け、多少なりとも論理を重視するプログラマ人種にとっての頭痛の種といえるでしょう。進化を続けるネット世界で、基準を設定するのは至難の業、軍閥割拠のジャングルのなかで右往左往してサバイバルゲームを続けるしかない。

で、今日の話題はエレメントの指定方法。スタイルシートで、同じエレメントを指定して、なぜか表示が変わらない。

table.background tr td
{
background-color:red;
}
table.background td
{
background-color:blue;
}

赤い指定をオーバーライドしているのに、これが青くならない。

<table class="background">
<tr><td>test<td>test
<tr><td>test<td>test
</table>

上記のスタイルの指定をよく見てみると、エレメントの指定方法に違いがあります。なぜか tr タグの指定が効いてるんですね。構造を書くと、そちらが優先されるアルゴリズムであるわけです。

これが意味のある基準であるかどうかはさておいて、知っておかないと他人のスタイルシートを使うときに困ることは間違いなしです。

金曜日, 12月 30, 2011

Javascriptの多次元配列

やられましたね。これ。Javascriptの多次元配列。

var array=new Array();
array[0,0]=0;
array[1,0]=1;

alert(array[0,0]);
alert(array[1,0]);

結論的には、双方ともに1を表示します。

皆さんも気をつけましょう。

謹賀新年

月曜日, 12月 12, 2011

桁数を取得するコード

間違い探し、です。よくありそうな感じもしますが載せておきます。

ある数字の桁数を得たいとします。valに格納されていると仮定してください。

10進法であるか、16進法であるか、ベースはbaseで示すことにします。

  int index=1;
  while(val/=base && ++index<len);

一見これで桁数が出る... と思った方。

悩みましたね。これだと浮動小数点エラーが出ます。GCC使ってます。

知ってしまえばどうということはないことです。

ここであっさりと書いておきますが、オペレーターの優先順位の問題でした。

括弧で囲ってやると正常に機能します。

お騒がせしました。

金曜日, 11月 18, 2011

Multiple OS's causes DLL problems.

Theoretically -- is it a theory -- any program that runs on the particular Framework should run in the same way. But -- WINDOWS, how else could it be? The application does not find COM components and fails to initialize classes. Is it the issue of registry keys damaged by the installation?

After close monitoring of Windows event, it turned out that when multiple OS's are installed in a machine, the OS seems to assume C: drive even when the system is installed in other drives. The application looks for drivers -- but in which drive, is the question. The C: drive application looks for D: DLL's when E: application looks for E: DLL's. Either case does not work. Only the D: application with D: DLL's worked.

日曜日, 11月 13, 2011

OAuth

Twitter uses OAuth for id verification. The encryption of the data is
using HMAC-SHA1 algorithm.

HMAC, Keyed-Hashing for Message Authentication Code
hash((key xor 0x5c5c...5c)
or (key xor 0x3636...36)
or message)

SHA, Secure Hash Algorithm
SHA-1 160 bit, MD4 based encoding

水曜日, 11月 09, 2011

C#: FontDialog unable to set font sizes; Firefox 8

The FontDialog class of C# is not overridable to change its settings. There are flags to remove underline and strike options, but there is no ways to limit font styles nor font sizes.

However, C# is a language that has ready-to-use off-the-shelf components that can replace the font dialog with ones of your own.



The new features in Firefox 8:
- twitter search
- delay loading tabs at start ups (when you set it the opening screen)
- WebGL, HTML5 improvements

月曜日, 11月 07, 2011

C#: WebBrowser.DocumentText does not support the += operator

WebBrowser.DocumentText does not support the += operator.

That is it. It does not. The String class should be formatted separately and assigned to that member variable.

金曜日, 11月 04, 2011

C# DataGridView's SetValue

When a DataTable is set for a DataGridView, the value can not be set
to DataGridViewCellFormattingEventArgs.Value, which is passed by to a
method that is hooked to CellFormatting event.

The way to avoid it, is to access to the cell value directly.
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
  if(e.ColumnIndex==5)
    {
      // If set, the following will be shown in the cell.  The Cell's value typed as an int will not be set correctly.
      //e.Value = "1";
                        
      // Instead, directly access the Cell object.
      int row = e.RowIndex;
      int col = e.ColumnIndex;
      dataGridView1.Rows[row].Cells[col].Value = 1;
                   
      break;
    } 
}

木曜日, 10月 27, 2011

C#: TimeZoneInfo.GetSystemTimeZones()

TimeZoneInfo.GetSystemTimeZones() returns a reference to a same instance, no matter how many times it is called.

When the time zone list is added to combo boxes, they select the same values.

comboBox1.DataSource = TimeZoneInfo.GetSystemTimeZones();
comboBox2.DataSource = TimeZoneInfo.GetSystemTimeZones();

The Collection class must be copied to some other forms.

System.Collections.ObjectModel.ReadOnlyCollection list 
= TimeZoneInfo.GetSystemTimeZones();
TimeZoneInfo[] tzList = list.ToArray();
comboBox1.Items.AddRange(tzList);
comboBox2.Items.AddRange(tzList);

火曜日, 10月 18, 2011

Excel / VBA: type conversion from integer to text

Excel uses VBA for its macros. The programming language, or the formula format, differs. Whereas Excel uses "TEXT()" with a format string as its argument, VBA uses "CStr()" to convert types from integer to string.

月曜日, 10月 10, 2011

C# field initializers

C# differs from Java in that the field initializers must be static.

This is perfectly OK in Java.

public class InitTest
{
    int test=0;
    InitTestClass testClass=new InitTestClass(test);
    
    public static void main(String args[])
    {
 InitTest test=new InitTest(); 
    }
}

class InitTestClass
{
    int test=0;
    InitTestClass(int test)
    {
 this.test=test;
    }
}

The following code, however, is not (C#).

namespace InitTest
{
    class Program
    {
        int test = 0;
        // Error
        InitTestClass testClass = new InitTestClass(test);

        static void Main(string[] args)
        {
        }
    }

    class InitTestClass
    {
        int test = 0;
        public InitTestClass(int test)
        {
            this.test = test;
        }
    }
}

木曜日, 9月 29, 2011

The merit of using C#

The code library in C#, comprised of classes that abstract and encapsulate such notions such as instruction set, font data, model number etc. What is good at this library is it runs threads and the 'server' takes commands and send them for number of times until they are passed to the module. Namely, the commands is queue until the event is processed.

A server is also called daemon that runs as a separate process along with the main procedure.

A queue is a FIFO that stack data for processing when the resources are available.

An event is a chunk of data that will be passed to the queue which contains the necessary data for each transaction.

Abstraction is a process that parameterize any variables that can be applied to same sort of procedure.

Encapsulation is a process to separate a set of data from direct manipulation so that any modification to the data will be monitored.

A thread is a process that can be processed pseudo simultaneously. The processor process each thread one at a time so it is pseudo-simultaneous.

With this library, commands are passed to the module in a safer and more secure manner. The server can wait, for sending data and receiving the data at the same time while queuing other data as well.

水曜日, 8月 31, 2011

Java and C++ Exception Handling

Java and C++ differs in how to handle exceptions. In Java, every possible exception must be handled. In C++, the exceptions handling can be omitted.

The demerit of not having to write exception handling procedure is not of optimization but in the safe programming practice. The exceptions readied for the methods will be thrown away, which might cause some fatal errors. Java has it that those have to be taken care of. Every method that throws exceptions must declare as "throws Exception" or any exception class. When the method is called, it must be in the try-catch block.

The counter argument is that when exception handling can be omitted, the code can be short as pointed out by this g++ user(s), the program size will not be affected unless the exceptions are explicitly stated to be thrown and handled in case of the g++ compiler. You can safely ignore any error message the original library writer tried to warn you in calling the methods. And those who use the method won't be warned as well.

There is no way to assume that any method won't throw exceptions, unless explicitly stated as in Java code, as throws Exception. Going through all the possibilities to make sure that the method that you are calling does not call just any method that throws exceptions, is if not an impossible task then tedious work. Therefore, this practice may leave the programmer unsafe and the products made from those libraries.

火曜日, 8月 16, 2011

Why, just why?


The Professional edition of Visual Studio 2010 C++ does not compile dependent projects right. 

It does not compile the static or dynamic libraries even when the configuration is set to compile them.  This bug is more annoying since it says Rebuild All Succeeded when it is set to be compiled from the main project.  This can be avoided if the project is compiled separately. 

This is such a major bug that it is rather puzzling it is not set in that way, particularly in C++.  Could there a way to compile them all together?

土曜日, 8月 13, 2011

Visual Studio: Refactoring

Microsoft's Visual Studio has a very nice feature called 'refactor'.  It replaces the names of a method or function to whatever you rename it.  It does contextual search and replace.  The same name used in other namespace or scope will not be affected.  It alleviates all the troubles associated with renaming.  In the end, the code would come up closer to the final products no matter how you change your course of programming.

Visual Studio's C# refactor, however, is not perfect.  It replaces the names even when there are the same names within the scope.  There is no way to distinguish the variables that has renamed and the existing variables with the same name.  That certainly is detectable.  As for C++ version of the IDE, there isn't such a function to rename methods and variables with contextual searches.

土曜日, 8月 06, 2011

C#の列挙型

C#の列挙型は特殊です。

列挙型は、Cなどでは定数程度としか使えませんが、C#では名前を取得したり、オブジェクトから列挙型の値を得ることができます。

FontStyle fontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), (string)obj);




「今までと違う」列挙型は、なにも嫌がらせのためにあるわけではなく、これこそはコンピュータ科学の成果であり、技術の進歩...と声を大にして言いたいところですが、あまり主張すると「シカト」などの憂き目にあうのでリーマン稼業の人間には注意が必要です。

改革は、草の根から...ですね。

木曜日, 7月 28, 2011

C#: ComboBox をカスタマイズする

ComboBox リスト項目の描画をカスタマイズし、チェックマークなど描く方法を説明します。

ComboBox のリスト項目は、単なる Object クラスです。つまり、リスト項目クラスを継承などしてデータを追加することはできません。適宜、ComboBox クラスにリストなどデータ構造を用意してデータを保存します。

データの準備ができたら、ComboBox のプロパティで DrawMode を OwnerDrawVariable に変更してやります。ここを変更すると、リスト項目の描画イベントをオーバーライドすることができます。DrawItem イベントに、イベントハンドラを追加し、描画手順を記述します。

具体的にはこのように描画をすべて記述することになります。

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();

            if (e.Index < comboBox1.Items.Count)
            {
                e.Graphics.DrawString((string)comboBox1.Items[e.Index], e.Font, Brushes.Black, e.Bounds);

                if (e.Index < modifiedMessages.Count() && modifiedMessages[e.Index])
                {
                    Bitmap bmp = new Bitmap(Properties.Resources.checkMark);
                    int iconWidth = 16;
                    int iconHeight = 16;
                    e.Graphics.DrawImage(bmp, e.Bounds.Right - iconWidth, e.Bounds.Bottom - iconHeight, iconWidth, iconHeight);
                }
            }

            e.DrawFocusRectangle();
        }

火曜日, 6月 21, 2011

iPad Safari's Arabic/Persian scripts drawing bug

Safari on iPad has a bug -- does not draw Arabic/Persian scripts right when font tag is in between.



It should look like the bottom but looks like the top, the supposed connected form of the letter appear in an independent form.

Firefox either on the Ubuntu platform or the Windows seems to draw it correctly.

水曜日, 6月 08, 2011

DataGridView: 初期値を指定する

DataGridView を使うと、テーブル形式でデータを扱うことができます。

それぞれのコラムで、値を限定し、ドロップダウンリストで選択できるようにすることもできます。

ただし、この場合には、値に制限がつくことになるので、つねに決められた値を設定してやる必要があります。

つまり、新規にデータを追加する場合など、値を空白とすることはできません。

この際には、データを追加するたびに、初期値を設定してやる必要があります。

なぜかDataTableなどではデフォルト値を設定するメソッドがありません。

イベントをフックし、値を設定してやります。

次に示すコードは、それぞれのコラムの値に適応した初期値を新規作成されたデータに設定するやり方を示したものです。

private void dataGridView1_CellFormatting(object sender
                                    , DataGridViewCellFormattingEventArgs e)
        {
            if (e.Value == null)
            {
                switch (e.ColumnIndex)
                {
                    case 0:
                        e.Value=dataGridView1.Rows.Count;
                        break;
                    case 1:
                        break;
                    case 2:
                        e.Value = "Instant";
                        break;
                    case 3:
                        break;
                    case 4:
                        e.Value = "0";
                        break;
                    case 5:
                        e.Value = "0 sec";
                        break;
                }
            }
        }

本来ならば、設定するコラムでそれぞれデフォルト値を設定できるような仕組みになっているべきではあると思います。

The formality problem: Java and C# -- extended class

Small things get in the way.

The way to write extended classes in Java and C# differs slightly.

Just for the record the following cases depicts the differences.


The extended class -- the case with Java:
public class NewClassTest
{
class A
 {
   int i=0;
   A(int i)
     {
        this.i=i;
     }
 }

class B extends A
 {
   B()
     {
        super(1);
     }
 }

public void test()
 {
   System.out.println(new B().i);
 }

public static void main(String args[])
 {
    new NewClassTest().test();
 }
}


The extended class -- the case with C#:
class Class1
    {
        protected string value = "to be overwritten";
        public Class1(string convert)
        {
            value = convert;
        }
    }

    class Class2 : Class1
    {
        public Class2(string additional, string convert)
            : base(convert)
        {
            value = convert + additional;
        }
        public string value { get; set; }
    }

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Class2 test = new Class2(" additional text", "original text");
            label1.Text = test.value;
        }
    }

土曜日, 6月 04, 2011

C# プログレスバーの色を変える

C#のライブラリでは、プログレスバーの色を変えるメソッドが用意されていません。

そこで、「メモリ容量がいっぱいになりました」的な状態を示すために、プログレスバーの色を緑から赤に変える方法を紹介します。

using System.Runtime.InteropServices;

const int WM_USER = 0x400;
const int PBM_SETSTATE = WM_USER + 16;
const int PBM_GETSTATE = WM_USER + 17;

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

このように、Win32APIを呼び出す関数を用意して、エラー状態をセットしてやります。

public enum ProgressBarStateEnum : int
        {
            Normal = 1,
            Error = 2,
            Paused = 3,
        }

public static void SetState(ProgressBar pBar, ProgressBarStateEnum state)
        {
            SendMessage(pBar.Handle, PBM_SETSTATE, (IntPtr)state, IntPtr.Zero);
        }

SetState(progressBar1, ProgressBarStateEnum.Error);

もとの緑色に変更するには、ノーマル状態に戻してやります。

SetState(progressBar1, ProgressBarStateEnum.Normal);

追記: ここで注意せねばならないのは、プログレスバーのバグで、エラー状態を設定した時点では値が変更されません。

エラー状態を設定したら、値の変更を再度行う必要があります。

これはWindowsのバグらしいです。

if (progressBar1.Maximum * .9 < len)
       {
           progressBar1.Value = 0;
           SetState(progressBar1, ProgressBarStateEnum.Normal);
           progressBar1.Value = len;
           SetState(progressBar1, ProgressBarStateEnum.Error);
       }
else
       {
           progressBar1.Value = len;
           SetState(progressBar1, ProgressBarStateEnum.Normal);
       }

水曜日, 6月 01, 2011

フォームで、まとめてイベントを管理 AddMessageFilter()

Windows フォームで、まとめてイベントを管理したいとします。

その場でテキストエディターを立ち上げて、文字列を編集するときなど、部品全てについてイベント処理しなければなりません。

テキストエディターで編集して、コンポーネントからフォーカスが外れたとき、イベントを管理する必要があります。

これが意外な難関で、WinProcをオーバーライドしても、このメソッドではイベントが処理されません。個々のコンポーネントで処理しなければなりません。

そこで用意されているのが、ApplicationクラスにあるAddMessageFilter()メソッドです。

Application.AddMessageFilter(new MyMessageFilter())

このような形で、MessageFilter派生クラスを指定してやります。

イベント処理は、MessageFilterクラスのPreFilterMessage()メソッドで行います。

ここで、WM_NCLBUTTONDBLCLK 、WM_NCLBUTTONDOWN はタイトルバーでのイベントで、WM_LBUTTONDOWNはクライアントエリアで発生するイベントを指します。

こんな感じです。


       private const int WM_LBUTTONDOWN = 0x201;
       private const int WM_NCLBUTTONDBLCLK = 0x00A3;
       private const int WM_NCLBUTTONDOWN = 0x00A1;

       public bool PreFilterMessage(ref Message msg)
        {
            switch (msg.Msg)
            {
                case WM_NCLBUTTONDBLCLK:
                case WM_NCLBUTTONDOWN:
                case WM_LBUTTONDOWN:
                    {
                        int lparam = (int)msg.LParam;
                        int x = lparam & 0xffff;
                        int y = lparam >> 16;

                        Simulator simulator = (Simulator)sender;
                        Point pos = simulator.RichTextBox1.PointToClient(new Point(x, y));
                        Rectangle rect = new Rectangle(0, 0, simulator.RichTextBox1.Bounds.Width
                            , simulator.RichTextBox1.Bounds.Height + SystemInformation.HorizontalScrollBarThumbWidth);
                        if (!rect.Contains(pos))
                        {
                            simulator.focusOff();
                        }
                    }
                    break;
            }
            return false;
        }

日曜日, 5月 22, 2011

C# クラスのAPIレファレンスの自動生成

C#には、自動的にクラスのAPIレファレンスを作成する機能があります。

Visual Studioでは、プロジェクトのプロパティでXMLファイルを出力できます。



あとはSandcastle Help File Builderなどを使ってレファレンスの形にします。

土曜日, 5月 07, 2011

C#の、プリンタの状態を示すクラス

C#では、プリンタの状態を示すクラスがあって便利です。

プリンタサーバーを指定するクラス PrintServer 、プリンタキューのリストを返すクラス PrintQueueCollection が準備されています。

プリンタキューからジョブリストを得るメソッド GetPrintJobInfoCollection もあります。

LocalPrintServer myPrintServer = new LocalPrintServer();
PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
string jobList = "";
foreach (PrintQueue pq in myPrintQueues)
{
   if (!pq.IsWaiting)
   {
      PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection();

      foreach (PrintSystemJobInfo job in jobs)
      {
          jobList = jobList + "Job: " + job.JobName + " ID: " + job.JobIdentifier+"\n";
      }
    }     
}

土曜日, 4月 09, 2011

C#の多次元配列

C#では、配列の宣言がJavaと異なります。

角カッコが、型のほうにつく。

(C#)
string[] nameList={"Ann","Chris","Freda","Darlene","Toni"};

こんな感じです。

これがJavaだと、変数名のほうにつきます。

(Java)
String list[]={"Brad","Alfie","Chris"};

こんなことでも、結構ストレスになるものです。

C#では、多次元配列がさらに特殊な形をとります。

(C#)
int[,] intList = { { 1, 2 }, { 3, 4 } };

あれ、というような意外感があるように思います。

さらに、Javaのように宣言する配列は、C#ではjagged配列という、また別なデータ構造を意味します。

これは、配列の配列という位置づけで、それぞれの配列の要素に、任意の配列を指定できます。

逆に言うと、それぞれの配列の要素に配列を指定しなければなりません。

(C#)
int[][] jaggedList =new int[2][];
jaggedList[0] = new int[2];
jaggedList[1] = new int[3];

注意が必要です。

土曜日, 4月 02, 2011

仕事でC#を使うことに。

C#は、Javaもどきとしか認識しておりませんでしたが、なんといってもマイクロソフトのVisual Studioつき。

IDEが完備しているのは強い。情報もある、といえるでしょう。

使いやすい。

イベントの処理の方法など、VC・C++などと同様に扱えます。

無意味な数値を極力使わないJava系のよさも引き継いています
リソースに「番号」を振り分ける悪趣味は、ここにはない。

コンポーネントに追加した順番ですべてが決まります。

--

Eclipse と比較すると、ヘルプやサンプルコードにすぐにアクセス出来ない、遠い感じがします。

情報はすべからくHTML形式にして、ネットに置いて欲しいものです。

水曜日, 12月 29, 2010

電子書籍:世界標準、日本語も対応 EPUB縦書き可能に

電子書籍のEPUBが日本語に正式対応するという。

来年5月に完成予定のEPUB3.0は縦書きや句読点の禁則処理、ルビ表記などに対応するという。

電子書籍市場は爆発的な伸びを見せており、2010年は前年度比3倍超という試算があるという。

電子書籍:世界標準、日本語も対応 EPUB縦書き可能に (2010-12-29)

水曜日, 12月 01, 2010

欧州委がグーグルの調査開始、独禁法抵触の恐れ

EUの欧州委員会は30日、米グーグル社をEU競争法(独占禁止法)に抵触するおそれがあるとして、正式に調査を開始したという。

欧州委がグーグルの調査開始、独禁法抵触の恐れ (2010-12-1)

水曜日, 10月 27, 2010

世界一安全な日本ドメイン

米マカフィーの「危険なウエブサイトの世界分布2010」によると、日本(.jp)ドメインは危険度0.1%と2年連続で最も安全な国別ドメインとなったという。

最も危険な国別ドメインはベトナム マカフィー調査 (2010-10-27)

金曜日, 10月 22, 2010

Amazon.comのQ3決算、39%増収で16%増益

米アマゾン社は21日、同年代3四半期の決算を前年同期比39%増と発表したという。

Amazon.comのQ3決算、39%増収で16%増益 (2010-10-22)

フランスのFNACでも電子ブックを売っているようです。

E-book : La Fnac attaque Amazon avec sa liseuse FnacBook

全世界的な現象ですね。

月曜日, 10月 04, 2010

Firefoxをもっと便利にする10のテクニック

Firefox のショートカットやツールバー、アイコンについての記事をマイコミジャーナルで発見しました。

ちょうどこんなのが欲しかった 的な工夫が満載です。

http://journal.mycom.co.jp/articles/2010/10/04/firefox-useful-10-tips/index.html

日曜日, 5月 09, 2010

ほぼ全社がグーグル電子書籍承認 印刷本から急速シフト

グーグルは9日、共同通信との取材で、同社が6月下旬に予定している電子書籍の販売に、米国のほぼ出版社ほぼ全社が参加していると述べたという。

ほぼ全社がグーグル電子書籍承認 印刷本から急速シフト (2010-5-10)
【出版】iPad登場で電子書籍、価格上昇の怪 (2010-5-6)
グーグル独占に懸念も 米国の電子書籍市場 (2010-5-10)

アマゾン・ドット・コムの Kindle や、アップル社の iPad ですね、まったくすばらしいです。

一瞬にして本がダウンロードできる。電源をオンにすると自動的に今日の新聞がダウンロードされる。レイアウトなんてのもばっちりです。タブレットってのもいいものです。

iPad なんかだと、極めて自然な動作で、ページが見事にめくれます。動作をためらうと、それなりにページがふわっと止まってくれるわけです。これがやみつきになる。

もちろん、何冊でもメモリの許す限り保有することができます。多くの本を手元に所有する安心感。さらに、ポテンシャルとして可能な限りの本を所有することの出来る期待感。

読みながら辞書が引けるということもあります。

早いところ、日本の書籍が読みたいと切に思います。

水曜日, 5月 05, 2010

米グーグル、電子書籍販売サイト立ち上げへ

米グーグルは7月末までに電子書籍販売を始めると発表。

米グーグル、電子書籍販売サイト立ち上げへ (2010-5-5)

iPad でも読めるEPUBフォーマットを採用するとのことです。

火曜日, 5月 04, 2010

米アップルの「iPad」販売が100万台突破、電子書籍150万冊

米アップル社は3日、iPad の販売台数が先月30日まで100万台に達したと発表したという。

米アップルの「iPad」販売が100万台突破、電子書籍150万冊 (2010-5-4)

電子書籍のダウンロード数も圧倒的です。

日本の電子書籍のコンソーシアムはいったいどうなっているんでしょうか。

水曜日, 4月 14, 2010

金曜日, 4月 02, 2010

グーグル社名変更など IT関連企業各社のエープリルフール

恒例のエイプリル・フールの面白ネタをいくつか。

* グーグルが社名をトピカに変更

これって、カンザス州の州都トピカが、3月限定で市名を「グーグル」に変更したことへの返礼とかいうことです。べつに企業城下町ということではなくて、グーグル社に光ファイバー網をひいてほしいという要請の一環とのことです。

* ヤフーのトップ画面が3D

これは本当に画面が用意してあって、アメコミ風のSilverlightでなんちゃってページが置いてありました。広告にカーソルを当てると飛び出てくる趣向で、悪くないアイデアといえるでしょう。

* ユーチューブが動画のテキスト版配信を開始

これは完全にありえないやつで、バンド幅が節約できるとの触れ込みつき。

グーグル社名変更など IT関連企業各社のエープリルフール (2010-4-2)
カンザス州都は「グーグル市」、過去には「トピカチュウ」も (2010-4-2)
グーグルの「エープリルフール」不発 (2010-4-2)

水曜日, 2月 24, 2010

ダライ・ラマもツイッター=中国を刺激?

チベットのダライラマ法王は23日、ツイッターに登録、利用を始めたことが分かったという。法王は、ロサンゼルスでツイッター社の最高経営責任者(CEO)に会い、登録を決めたという。IDは DalaiLama で、フォロワーが急増中という。

ダライ・ラマもツイッター=中国を刺激? (2010-2-24)

水曜日, 2月 10, 2010

IE9でSVGに対応の可能性 - MicrosoftがSVG WGに参加

IE9でSVGに対応の可能性 - MicrosoftがSVG WGに参加 (2010-1-7)

マイクロソフトは、W3Cのワーキンググループに参加するそうです。

IE9で、SVGに対応する可能性が出てきました。

SVGのように、構造化されたグラフィクスがウェブ上で使えるようになると、素晴らしい世界が広がります。

現在、ウェブでページを書くとき、ちょっと凝ったふうに表示しようと思えば、いっさいがっさい、全部、画像ファイルにして読み込まねばなりません。

タイトルを大きく書こうと思えば、そのような画像ファイルを用意し、背景を描くなりなんなりせねばなりません。

SVGなら、スタイルシートで、ベクトル画を指定できます。

大きく文字を書いて、背景にグラデーションをかけて、下線を引く、などの動作が、画像ファイルでなくて、コードで指定できる。

画像ファイルでないので、転送速度はもちろん速くなります。

そして、構造化されたグラフィクスとして、自動生成できるようになります。

利点は、自動生成できることばかりにあるわけではありません。

文字コードで記述されるということは、つまり、ALTタグなどで指定しなくても検索が可能になるということです。

さらに、Javascriptなどと組み合わせれば、データを動的に指定して画像にすることができます。



Javascriptとの組み合わせでは、かなり高度なアプリやゲームができます。

ただし、コンパイルせずにコードをそのまま流す形になります。

フラッシュやシルバーライトと競合する可能性があります。



SVG規格は、HTML5規格でHTMLページへの組み込みが可能になります。

他にベクトル描画規格としては、Canvasなどがあります。

SVGとCanvasと、健全な競争による切磋琢磨が期待されます。

火曜日, 1月 19, 2010

独仏の政府機関、「IE」の利用を控えるよう勧告

マイクロソフト社は14日、IE(Internet Explorer)のゼロデイ脆弱性により、複数の米国企業へのサイバー攻撃に利用されたことを認めたという。

ドイツ政府とフランス政府は、マイクロソフトのIEの使用を控えるよう国民に呼びかけているという。

グーグルのセキュリティ侵害はIEのゼロデイ脆弱性が原因--マイクロソフトが認める (2010-1-19)
独仏の政府機関、「IE」の利用を控えるよう勧告 (2010-1-19)
ドイツやフランスの政府機関、「IEの利用中止」を推奨 (2010-1-19)

土曜日, 1月 16, 2010

USB3.0

USB3.0製品、出てますねー

規格は2008年11月に正式発表されてます。

最大データ転送速度が5Gbps。

物理的に、ピンの数が9本となってますが、後方互換性ありとかで、USB1.1,USB2.0のコネクタが使えるらしい。

通信速度を上げているため、スペクトラム拡散やシールドなど電磁放射雑音対策が必須となり、最大伝送距離が短くなっているそうです(推定約3mという)。

符号化形式は、8B/10B。通信モードは全二重。給電能力が最大900mA。省電力を目指し、ポーリング排除、4つの待機モード。

usb3.0のニュース検索結果

木曜日, 1月 14, 2010

米グーグル、メールの安全強化 暗号化機能、標準仕様に

米グーグル社は、同社の無料メールサービス「Gメール」を暗号化し、サイバー攻撃に対処するという。

グーグルは、中国からサイバー攻撃を受けたと発表しており、安全性向上に努めるという。

米マイクロソフトとヤフーは13日、グーグル社と協力して事態に対処すると発表したという。

米グーグル、メールの安全強化 暗号化機能、標準仕様に
マイクロソフトやヤフー、相次ぎグーグル支持 サイバー攻撃巡り
米ヤフーにも中国でグーグル同様のサイバー攻撃-関係者

水曜日, 1月 13, 2010

中国事業から撤退辞さず=人権活動家狙ったサイバー攻撃で-米グーグル

米グーグル社は12日、中国語サイトの検索結果の検閲受け入れを停止を目指し、中国政府と交渉すると発表したという。

中国事業から撤退辞さず=人権活動家狙ったサイバー攻撃で-米グーグル (2010-1-13)

ヤフー、マイクロソフト、シスコが検閲反対に協力・賛同するかどうか注目されている。

2006年にはこの4社は、中国政府の要請で検閲ソフトを使用し、情報を提供したために、言論の自由を損ない、民主活動家の弾圧に加担したとして米下院の公聴会に呼び出され、非難されている。

中国政府の検閲に協力的なIT企業を批難、米国下院議会

グーグル検索を使えないとすれば、実はそれだけで「制裁」そのものだと思いますね。

グーグル問題/中国は情報統制をやめよ (2010-1-16)

日曜日, 1月 10, 2010

A4サイズの電子ブック 「QUE」

A4サイズの電子ブックが4月に発売になるそうです。

英Plastic Loic社のQUEproReaderという製品で、タッチスクリーンでボタンはひとつ。

無線LAN対応のモデルが$649、携帯電話網対応モデルが$799。

Barns and Noblesなどと提携しているとかで、雑誌・新聞が毎日、自動的にダウンロードされてどこでも読める。書籍の iPod 版とかいうコンセプトだとか。

電子書籍市場の拡大と充実が楽しみです。

メールも読める電子書籍リーダー「QUE」、Plastic Logicが発表――発売は4月半ば (2010-1-11)

書籍端末 はや乱戦 米見本市に20社超参加 (2010-1-15)

CPUは、米Marvell社の、ARMベースの「ARMADA」だそうです。

MarvellとE-Ink、電子書籍リーダー用プロセッサを提供 (2010-1-11)
ARMADA 100

火曜日, 12月 22, 2009

土曜日, 12月 19, 2009

CIAと外務省サイトを検索するChrome拡張機能

CIAと外務省サイトを検索するChrome拡張機能を作ってみました。

CIA Search

拡張機能は、まだ Chrome のベータ版でしか機能しませんが、すでに多くの拡張機能がアップされています。

ポップアップのウィンドウでは、ドロップダウンリストがそのままでは実装できないので注意が必要です。

木曜日, 12月 17, 2009

Chrome Extensions

Google Chrome browser seem to get the momentum now that many extensions are available.

Chrome Extensions

Sensible enough, it runs Javascript. The objects are custom made, though, and it will take time to get them all.

Google Chrome Extensions (Labs)

A code like this will set a listener. The specified callback function will be invoked when the icon is clicked.



chrome.browserAction.onClicked.addListener(function(tab) {

alert(tab.url);

});



When the extension is invoked, it creates popup window. It could create empty background window. The current selected window is called contents window and scripts and css's etc for the window can be specified in .json file.

Overview

Google Chrome 拡張機能では、それぞれ任意のページ(background), サイトを開いたときに起動する(contents), アイコンをクリックすると表示される(popup)などで指定するコードを起動できる。

水曜日, 12月 09, 2009

バーチャルキーボード

赤外線を投影し、反射で打鍵を認識する、バーチャルキーボードという商品があるとか

バーチャルキーボード【ばーちゃるきーぼーど】 (2009-12-10)

Chromeの拡張機能が利用可能に - Googleがベータ提供開始

Chrome に拡張機能がついたベータ版がでたそうです。

Chromeの拡張機能が利用可能に - Googleがベータ提供開始 (2009-12-9)

ベータ版のダウンロードが必要です。

拡張機能のページで検索できるようです。

土曜日, 12月 05, 2009

ウルドゥー語の表示

Firefox

Chrome

IE8.0



Firefox のフォームのテキストエリアのウルドゥー語の表示では、e をつないでも結合しないということを発見しました。どうも、独立形への変換はしても、接続形には自動的に変換しないようです。

chrome ではきちんと表示できます。

IEでは、e のみならず ph の結合が正しく表示されません。

土曜日, 11月 28, 2009

PHPで、棒グラフ

PHPで、棒グラフなど書くことができます。画像に書き出してそれをHTMLのページに埋め込むことができるということです。データベースからデータを読み出して、グラフにして表示することが、オンラインで可能です。

以下のコードを、.php ファイルに保存して、ApacheなどPHPの動く環境でブラウザでアクセスすると、t.png の画像ファイルができて棒グラフになっているはずです。




$data=array();

array_push($data,1);
array_push($data,2);
array_push($data,3);

$width=300;
$height=10+10*count($data);

$image=imagecreatetruecolor($width,$height);

$white=imagecolorallocate($image,255,255,255);
imagefilledrectangle($image,0,0,$width,$height,$white);
$black=imagecolorallocate($image,0,0,0);
$i=0;
foreach($data as $item)
{
$y0=5+10*$i;
$x1=$item*10;
imagefilledrectangle($image,0,$y0,$x1,$y0+10,$black);
$i++;
}

$filename="t.png";
imagepng($image,$filename);
imagedestroy($image);

?>



木曜日, 11月 12, 2009

インテル、AMDと和解 1100億円支払いで

AMD(アドバンスト・マイクロ・デバイシズ)社がインテル社を独禁法で訴えていた件で12日、インテルは12億5千億ドル(約1100億円)をAMDに支払うことで和解したという。

インテル、AMDと和解 1100億円支払いで (2009-11-13)
インテル、AMDとの訴訟で和解 独禁法違反巡り (2009-11-13)
米インテルがAMDと全訴訟で和解、12.5億ドル支払い (2009-11-13)

火曜日, 11月 10, 2009

OracleのSun買収に欧州委員会が異議申し立て

米オラクル社の米サン・マイクロシステムズ社の買収に関し、EUの欧州委員会は9日、異議申し立てを行ったという。

OracleのSun買収に欧州委員会が異議申し立て (2009-11-10)

日曜日, 10月 11, 2009

PHP: ディレクトリを丸ごとコピーします。

ディレクトリを丸ごとコピーします。

readdir の返り値はファイル名なので、フルパスではありません。

is_dir の引数には、もとのディレクトリとフルパスを指定します。

ファイルの存在は file_exists で検査します。

To copy a directory recursively in PHP:



function copyDirectory($imageDir, $destDir)
{
$handle=opendir($imageDir);
while($filename=readdir($handle))
{
if(strcmp($filename,".")!=0
&& strcmp($filename,"..")!=0)
{
if(is_dir("$imageDir/$filename"))
{
if(!empty($filename) && !file_exists("$destDir/$filename"))
mkdir("$destDir/$filename");
copyDirectory("$imageDir/$filename","$destDir/$filename");
}
else
{
if(file_exists("$destDir/$filename"))
unlink("$destDir/$filename");
copy("$imageDir/$filename","$destDir/$filename");
}
}
}
}

木曜日, 9月 10, 2009

パナソニックもLED電球に参入

省電力・小型・長寿命なLED電球に、続々と企業が参入で、期待大。

パナソニック、LED電球に参入 10月発売へ (2009-9-10)
パナソニックもLED電球に参入 (2009-9-10)
三菱、60W白熱電球相当の明るさのLED電球 (2009-9-10)

アキバで売ってる安いのだと、青っぽかったりしてトイレとかだと使えるってカンジですけどね。エコだと思うといいもんです。

金曜日, 9月 04, 2009

MySQLの行く末を保証せよ - EU、OracleのSun買収について詳細調査を開始

欧州委員会は3日、データベース大手のオラクルのサン買収について、追加の調査を実施すると発表したという。

オラクルがMySQLを保有するサンを買収することで、MySQLが有料化されたり、開発が止まったりする懸念について調査するという。

欧州委員会の最終決定は、2010年1月19日以降になるという。

MySQLの行く末を保証せよ - EU、OracleのSun買収について詳細調査を開始 (2009-9-4)

PHP: 定数を扱う

プロジェクトごとの定数を扱うクラス Config\Constants の紹介です。 <?php namespace Config; class Constants {     public const DB_USER = "linguist...