金曜日, 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)

金曜日, 8月 14, 2009

米マイクロソフトのZuneHD、iPod下回る価格設定

マイクロソフト社は13日、ポータブル・メディアプレーヤーZune(ズーン)HDの価格設定を発表したという。

ZuneHD は、Windows CE を搭載、CPUは ARM ベースの NVIDIA Tegra 。

iPod に対抗するとし、価格は219.99ドル(16GBモデル)、289.99ドル(32GBモデル)、発売予定日は9月15日という。

FMラジオ機能があるほか、HDMI端子がついており、テレビに動画が送れるという。

米マイクロソフトのZuneHD、iPod下回る価格設定 (2009-8-14)
ZuneHD
zunerama

オプションでFM電波を飛ばせるため、カーステレオで音楽が聴けるということでした。

日本発売は予定がないそうです。

金曜日, 7月 31, 2009

MicrosoftとYahoo!が検索分野で10年間に渡る提携を発表した狙い

マイクロソフト社とヤフーは検索エンジンを共同開発するという話題があがってますよね。

MicrosoftとYahoo!が検索分野で10年間に渡る提携を発表した狙い (2009-7-30)

もっぱら、グーグルばかり使ってた人間ですが、自分のサイトが登録されていなかったので...(笑・なぜだろう)

言語学のページ

楽天のサイトなのに理由が分かりません。

競争があるのはありがたい、と実感したという顛末でした。

日曜日, 7月 26, 2009

Microsoftが欧州でWindows 7に「ブラウザ選択画面」,ECが歓迎の声明


米マイクロソフト社は24日、新たに販売されるWindows7に「バロット・スクリーン」(投票画面)を設置し、ブラウザを選択できるようにすると発表したという。

PCに標準搭載されるOSに、特定のソフトウエアがバンドルされることは市場独占につながるとする意見に対し、マイクロソフト社は自社のブラウザ、IEをバンドルしない方針を表明していた。

欧州委員会はこのマイクロソフト社の方針に否定的コメントを発表していたという。

これに対し、マイクロソフト社は5種類のブラウザから選択できる「バロット・スクリーン」の設置を提案しているのだという。

マイクロソフト社は、IE, Firefox,Safari,Google Chrome,Opera を提案しているという。

PCメーカーは、ブラウザをプリインストールすることができるという。

Microsoftが欧州でWindows 7に「ブラウザ選択画面」,ECが歓迎の声明 (2009-7-26)

個人的には、アドオンの豊富なFirefox、起動の早いChrome,IEしか対応していないサイトがあるのでIE ...といったところが好みですね。

特に、アドオンでムカつく画像を消せたり、CSSを変えられたりできるので、Firefoxに一票。adblockとstylish、flashblockなどお勧めです。

もちろん、IEならIE7Proを使うと、広告がブロックできます。アドオンを有効にして、ツールメニューからIE7Pro preferencesをクリック。広告ブロックにチェックを入れると、広告がカットできます。

選べると、シェアが変動するので、サイトのほうも対応して変わってくる。

楽しみですね。標準化なるか、あるいはブラウザを指定するようになるか。

標準化したところで、ChromeOSの登場とか。

月曜日, 7月 20, 2009

Microsoft、「オンライン版Office」でGoogleに対抗

サンが買収されるまで、仮想マシンを散々に言ってきたマイクロソフトがこうである。「どこまで仮想化できるか」

そのマイクロソフトはオンラインのオフィスを提供する予定と発表している。

金のためにマイクロソフトは技術の発展を止めた、というのは不都合な真実というよりは現在の、特に米国の、そして日本の企業文化に対する理解への必要性を理解するべきであろう。

「仮想化したら重い」という批判とともに、仮想化・標準化は絶対にいい、かならず必要になる、メモリ制限などなくなるに決まっているという意見がある。

先走るのは、技術的にデメリットがあるというより、社会的なアクセプタンスの問題が生じる。

Microsoft、「オンライン版Office」でGoogleに対抗 (2009-7-14)

金曜日, 7月 10, 2009

Firefox で埋め込み画像の機能

つい先だって ver. 3.5 の発表されたFirefox ですが、Firefox には IE にはない機能があります。

埋め込み画像の機能です。画像を(バイナリでなく)文字コード化して表示できます。

ページを保存するだけで、中の画像が別ファイルなしで表示できます。

タグのフォーマットは、IMGタグにBASE64でエンコードされた画像を記述します。

PHPコードで、試験的に画像ファイルを読み込んで、埋め込んで表示するコードを書いてみました。



$fileName="hatch.gif";

$fd=fopen($fileName,"r");
$contents=fread($fd,filesize($fileName));
fclose($fd);

echo "<img src='data:image/gif;base64,". base64_encode($contents)."'>";




base64_encode()関数を用いて画像ファイルをエンコードし、埋め込んでいます。

水曜日, 7月 08, 2009

米グーグルがパソコン用OS「Google Chrome OS」を開発

Google社は8日、ネットブックOS「Google Chrome OS」を開発中と発表。

米グーグルがパソコン用OS「Google Chrome OS」を開発 (2009-7-8)

ブラウザ上でのアプリは、見た目が統一されており、広く普及しているため、Windowsに取って代わるだけの標準となりうる脅威として語られて久しい。

ブラウザだけ動けば、OSは何でもいいとなれば独占市場が切り崩せると、いう夢物語が現実に...?

火曜日, 6月 30, 2009

中国政府、「検閲ソフト」義務化を延期 新華社報道

中国は30日、検閲ソフト Green Dam の義務化を延期すると発表したという。

検閲ソフトはPCにインストールしてネットへのアクセスを制限するもので、建前上は有害サイトへのアクセスを自動的に阻むとしていた。

検閲ソフトは、技術上の問題があったとして批判があったほか、サイト許可リストへの著作権の問題やアクセス許可を国家が行うことへの非難が国内外から殺到しており、米国政府も懸念を表明していた。

中国政府、「検閲ソフト」義務化を延期 新華社報道 (2009-6-30)

月曜日, 6月 15, 2009

コード盗用に脆弱性――中国フィルタリングソフトの問題、米研究者が指摘

米ミシガン大学の研究者らは11日、中国政府がPCメーカーなどに義務付けようとしているフィルタリングのソフト「Green Dam」に、脆弱性を発見したと発表したという。

「Green Dam」は、URLでアクセスを規制するほか、画像を選択的に規制、さらになんとテキスト入力フィールドで入力をチェックするという。

米ミシガン大学のスコット・ウォルチョク氏、ランディ・ヤオ氏、アレックス・ホルダーマン氏らは、「Green Dam」に、URLリクエスト処理のプロセスでバッファオーバーランの脆弱性と、更新プログラムでの脆弱性があるとしている。
さらに、Solid Oak Software社は12日、URLのブラックリストの著作権について CyberSitter からの盗用であると発表しているという。

Solid Oak Software社と米ミシガン大学のグループは、PCメーカーらに「Green Dam」の搭載をとめるよう働きかけていくとしている。

中国政府指定の検閲ソフトにセキュリティ脆弱性--米大学研究チームが警告 (2009-6-15)
中国がPCメーカーに導入義務づけのフィルタリングソフトに盗用疑惑 (2009-6-15)
コード盗用に脆弱性――中国フィルタリングソフトの問題、米研究者が指摘 (2009-6-15)

金曜日, 6月 12, 2009

ウィンドウズ7欧州版、IE搭載せず…独占禁止法に配慮か

マイクロソフト社は11日、Windows 7の欧州版に、同社のブラウザであるIEをバンドルしないと発表したという。

OSにソフトを標準搭載することで、健全な競争が阻害されるという批判に対する、EU競争法(独占禁止法)に基づく処置という。IEについては、「タブ機能」の実装で出遅れるなど、ブラウザ間の競争が健全でないという批判があった。プラグインやアドオンの開発のオープンさ、アプリの起動・動作のスピードなど、ブラウザ間の競争に対する要望は強い。

OSがアプリを標準搭載しないということは、ユーザーにとって、そのままでは動かない、ソフトをインストールする必要がある、ユーザーがばらばらなソフトを使うので標準化されないといったデメリットがある。なんといっても、標準装備というのは便利である。コンテンツを提供する側、ソフト開発側にとっても、標準化されていれば作りやすい。マイクロソフト社の製品が重宝され、必要とされてきた理由のもっとも大きなものである。

ブラウザはOSに代わってデスクトップと同等の機能、標準化されたインターフェースを持ちうるものとして、さらに既存メディアに代わるものとして、重要な意味を持つ。マイクロソフト社が、ブラウザ上でのアプリやアプレットの動作を規制、あるいは阻害する危険性については論議がある。ブラウザ間の競争を促進することは、有効な選択肢をユーザーに与え、多様化をもたらすものであると同時に、開発者側には競争による高機能化と利便性の向上を約束するものである。

今回の措置で、PCベンダーや販売業者は任意のブラウザを搭載して販売できるようになるという。ブラウザ・ベンダー間の競争は、ブラウザ間の競争そのものではなく、ユーザーに有効な選択肢を与えるものであるかどうかは、ベンダーの処置による、という。欧州委員会では、マイクロソフト社に選択肢を提供することを義務付ける案などさまざまな可能性を示唆しているという。

ウィンドウズ7欧州版、IE搭載せず…独占禁止法に配慮か (2009-6-12)
EU、欧州版「Windows 7」からIEを削除する措置に賛否の混じった評価 (2009-6-12)
マイクロソフト、欧州向けにIE非搭載のWindows 7を提供へ (2009-6-12)

月曜日, 6月 08, 2009

中国政府、PCに監視ソフト搭載を義務づけへ 米WSJ

中国政府は、販売するPCにサイトをフィルターする監視ソフト搭載を義務付けるという。

記事からすると、有害サイトをフィルターするウイルス対策アプリのように、常駐して外部へのアクセスを監視するものらしい。

もしそうだとすると、ユーザーに使う意図がなければプロセスを殺すことが可能であり、義務付ける意味はない。さらに、リナックスなどのように、OSを変えてしまえばまったく意味はない。そのような情報が、ユーザーの間で広まらないようにすることで、ある程度のフィルタリングを強制することができるが、そうなると自由な世界の住民をすべて敵に回しているわけであり、考えにくい。

中国政府は、プロバイダや検索エンジンに規制をかけていることで悪評が高い。WikiやYoutubeを閲覧できなくするという究極の愚民政策は、中国政府に「守られている」という意識よりは、「阻害されている」という反発をより多く招くものである。法の網をくぐること、が正義になるようでは、建設的発想はもたらされない。

建前にも、誰も、自国民でさえ納得のできない愚民政策を続けるより、判断をユーザーに委譲することで責任を負う義務を課し、建設的な発想に多数が納得する、選挙、投票による意思決定システムを打ち立てるよう要請したいものである。

中国政府、PCに監視ソフト搭載を義務づけへ 米WSJ (2009-6-8)

水曜日, 4月 29, 2009

オバマ大統領のアドバイザーに、GoogleのEric Schmidt氏ら任命

オバマ大統領の科学技術関連の助言を行うアドバイザーに、GoogleからEric Schmidt氏、MicrosoftのCraig Mundle氏ら20人を任命

オバマ大統領のアドバイザーに、GoogleのEric Schmidt氏ら任命 (2009-4-28)

Schmidt氏は、lexを作ってるんですね。

火曜日, 4月 21, 2009

ソマリ語

ソマリ語は、アジアアフリカ語族の低地東クシ語に属する言語で、他にオロモ語などがクシ語に分類される。内戦状態であったため、教育制度が確立しておらず標準化されておらず、表記のゆれが大きい。Digil/Roxanweyn方言などがあるという。

イスラム法を導入するほどイスラム教の勢力が強く、アラビア語の借用語が多い。アラビア語で朝はサバフであるが、ソマリ語でsubaxとなる。おはようはsubax wanaagsan(スバフ ワナーグサン)。-sanや-anは形容詞につく語尾という。ほか、Qahtaniからの借用語が多いという。

「止まれ」がjoogso(ジョーグソ)。 「はい」がhaa(ハェー)で、「いいえ」がmaya(マヤ)。 「ありがとう」がmahad sanid(マハッド・サニッド)。「こんにちは」がiska warran(イスカ・ワラン)。

長母音・短母音、前舌音・後舌音が区別され、合計5x4=20個の母音がある。長母音・短母音の区別は母音の重複で表し、前舌音・後舌音は表記上で区別されない。

声調があり、声調によって意味が異なる場合がある。

日本語と同じく、膠着語でSOVである。不定冠詞は表記しない。

1972年からローマ字が使われているが、かつてはアラビア文字(Wadeed's writing)が, 20世紀前半にはOsmanya scriptや Borama scriptが使用されたという。

ソマリ語の数字

1 hal ハル
2 laba ラボ
3 seddex セッデフ
4 afar アファル
5 shan シャン
6 lix リフ
7 todoba トドボ
8 sideed シデード
9 sagaal サガール
10 toban トバン
11 kow iyo toban ク・イユ・トバン
12 laba iyo toban ラボ・イユ・トバン
13 sedex iyo toban セデフ・イユ・トバン
14 afar iyo toban アファル・イユ・トバン
15 shan iyo toban シャン・イユ・トバン
16 lix iyo toban リフ・イユ・トバン
17 todoba iyo toban トドボ・イユ・トバン
18 sideed iyo toban シデード・イユ・トバン
19 sagaal iyo toban サガール・イユ・トバン
20 labaatan ラバータン
30 soddon ソッドン
40 afartan アファルタン
50 konton コントン
60 lixdan リフダン
70 todobaatan トドバータン
80 sideetan シデータン
90 sagaashan サガーシャン
100 boqol ボコル

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

オラクルがサンを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のクラス構造」といいたい。

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

PHP: 定数を扱う

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