pxkw.hatenadiary.com

めもめも

trをslideToggleする

<div id="trSlideToggleSample">

  <table>
    <tr class="trTrigger">
      <th colspan="2">Click me to show.</th>
    </tr>
    <tr style="display:none">
      <th>Can you</th>
      <td>see me?</td>
    </tr>
  </table>

  <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
  <script>
    $(function(){
      $(".trTrigger").click( function() {
        $(this).next().slideToggle(125);
      });
    });
  </script>

</div>

Click me to show.
Can you see me?


うにょってなんね。

うにょってさせる

<div id="trSlideToggleSample2">

  <table>
    <tr class="trTrigger2">
      <th colspan="2">Click me to show.</th>
    </tr>
    <tr>
      <th><span style="display:none">Can you</span></th>
      <td><span style="display:none">see me?</span></td>
    </tr>
  </table>

  <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
  <script>
    $(function(){
      $(".trTrigger2").click( function() {
        $(this).next().children("th").children("span").slideToggle(225);
        $(this).next().children("td").children("span").slideToggle(225);
      });
    });
  </script>

</div>

Click me to show.
Can you see me?


なんか変だ。

tdをslideToggleする

<div id="tdSlideToggleSample">

  <table>
    <tr>
      <th class="thTrigger">Click me to show.</th>
      <td style="display:none">Can you see me?</td>
    </tr>
  </table>

  <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
  <script>
    $(function(){
      $(".thTrigger").click( function() {
        $(this).next().slideToggle(125);
      });
    });
  </script>

</div>

Click me to show. Can you see me?


うにょってなんね。

うにょってさせる

<div id="tdSlideToggleSample2">

  <table>
    <tr>
      <th class="thTrigger2">Click me to show.</th>
      <td><span style="display:none">Can you see me?</span></td>
    </tr>
  </table>

  <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
  <script>
    $(function(){
      $(".thTrigger2").click( function() {
        $(this).next().children("span").slideToggle(225);
      });
    });
  </script>

</div>

Click me to show. Can you see me?


なんかへん。

dlをslideToggleする

参考: 超簡単jQuery!"toggle系メソッド"を使ってアコーディオンメニューやタブをさくっと実装する方法 | 株式会社LIG

ミニマルなコードはこんな感じかな

<div id="dlSlideToggleSample">

  <dl>
    <dt class="trigger">Click me to show/hide item.</dt>
    <dd style="display:none"> Can you see me?</dd>
  </dl>

  <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
  <script>
    $(function(){
      $(".trigger").click( function() {
        $(this).next().slideToggle(125);
      });
    });
  </script>

</div>

Click me to show/hide item.
Can you see me?


JavaでC-cした時の処理

シャットダウン時に走るスレッドを用意してRuntimeに渡す.

参考:日記(仮) >> Javaプログラム終了時に確実に終了処理をする

ミニマルなコードはこんな感じか

public class ShutdownHookSample {

    public static void main(String[] args) {

        // Set thread to be run when Runtime is shut down.
        Runtime.getRuntime().addShutdownHook( new Thread(){
                @Override
                public void run(){
                    System.out.println("\nBye.");
                }
            });

        System.out.println("Started. (C-c to shut me down.)");
        while(true);

        // Control will never reach here.
    }
}

実行結果例

Started. (C-c to shut me down.)
^C
Bye.

symlinkをchownする

オプションhを付与する。

chown -h owner:group symlink

chownのマニュアル:

  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         ownership of a symlink)

なので、 -h を付与しないと参照先の所有権を変えてしまう。


symlinkでのみアクセスできるみたいなことできるのかな

--> できない。

$ ls -l
    (略)
-r--------  1 root root   16 Jan 28 16:33 testfile
lrwxrwxrwx  1 pxkw pxkw    8 Jan 28 16:31 testlink -> testfile
    (略)
$ sudo cat testfile 
can you see me?
$ cat testfile 
cat: testfile: Permission denied
$ cat testlink 
cat: testlink: Permission denied

symlinkは読み書き権限の変更不可

chmodのマニュアル:

       chmod never changes the permissions of symbolic links; the chmod system call cannot change their permissions.  This is not a  problem  since
       the permissions of symbolic links are never used.  However, for each symbolic link listed on the command line, chmod changes the permissions
       of the pointed-to file.  In contrast, chmod ignores symbolic links encountered during recursive directory traversals.

hardlinkの権限/所有者変更はすべてのhardlinkに影響する

$ ls -l
    (略)
-rw-rw-r--  3 pxkw pxkw    0 Jan 28 16:40 file
-rw-rw-r--  3 pxkw pxkw    0 Jan 28 16:40 ln1
-rw-rw-r--  3 pxkw pxkw    0 Jan 28 16:40 ln2
    (略)
$ chmod 777 ln1
$ ls -l
    (略)
-rwxrwxrwx  3 pxkw pxkw    0 Jan 28 16:40 file*
-rwxrwxrwx  3 pxkw pxkw    0 Jan 28 16:40 ln1*
-rwxrwxrwx  3 pxkw pxkw    0 Jan 28 16:40 ln2*
    (略)
$ sudo chown root:root ln2
$ ls -l
    (略)
-rwxrwxrwx  3 root root    0 Jan 28 16:40 file*
-rwxrwxrwx  3 root root    0 Jan 28 16:40 ln1*
-rwxrwxrwx  3 root root    0 Jan 28 16:40 ln2*
    (略)

SymLinkとHardLinkの使い分けどころ

Linuxのシンボリックリンクとハードリンクはどう使い分けますか.. - 人力検索はてな

私が知っている中で、ハードリンクを最も効果的に使っているのは Cyrus IMAP Server と呼ばれる IMAP サーバのソフトで、このソフトの場合、基本的にはメール1通が1ファイルで保存されるのですが、複数の人に同じメールを送った場合、保存されるのは1通分で、各ユーザのメールボックスのファイルとしてハードリンクを作ります。
こうすると、人数分のファイルを作らないので、それだけディスクの節約になるのと同時に、誰かがメールを削除しても、全く問題ありません。もし、これをシンボリックリンクにしようとすると、ユーザのメールボックスとは無関係にファイルを作って、ユーザのメールボックスにはシンボリックリンクを置く、といったことになると思いますが、じゃぁ、全員が削除したときに、この本物のファイルを削除するのはどうするか? という問題が残ります。
ハードリンクであれば、全員が削除して本当に必要が無くなったときには、本体も削除されていることになるので、その点でもシンボリックリンクよりスマートです。

基本的にsymlinkでOKだけど、上記のようにどこからも必要なくなった時点で自動に消したい場合はhardlinkの方が便利そう。