gitでaddしてないファイルをすべてなかったことにする

gitで管理してるディレクトリに大量にファイルをしてしまった..

$ git status

On branch v.2.13.3
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   data/Smarty/templates/default/abouts/index.tpl
        modified:   data/Smarty/templates/default/cart/index.tpl
        modified:   data/Smarty/templates/default/contact/complete.tpl
        modified:   data/Smarty/templates/default/contact/confirm.tpl
        modified:   data/Smarty/templates/default/contact/index.tpl
        modified:   data/Smarty/templates/default/entry/complete.tpl
        modified:   data/Smarty/templates/default/entry/confirm.tpl
        modified:   data/Smarty/templates/default/entry/index.tpl
        modified:   data/Smarty/templates/default/entry/kiyaku.tpl
        modified:   data/Smarty/templates/default/error.tpl
        modified:   data/Smarty/templates/default/footer.tpl
        # 延々に続く..

となったときに全て無かったことにするには

$ git clean -f

これで元通り
あ、すべて消えるのでご使用はお気をつけてください

CakephpのbeforeFilterでComponentを使うときのエラー

CakephpのbeforeFilterでComponentを使っているとなんやらメソッドがないとかエラーが

Fatal error: Call to a member function save() on a non-object ...

えー、普通に使ってるのに..と思ったら、beforeFilterでは、Componentのstartupがまだ呼ばれてないっぽい(使える準備ができてない)
仕方ないので、メインのメソッドに書きました

WordPressでSyntaxHighlighter Evolvedを外して文書を一気に直す

このブログもWordpressを使っていますが
シンタックスハイライト(プログラムコードとかを綺麗に見せる)に

  • SyntaxHighlighter Evolved

というプラグインを使っていましたが、Markdown形式でかける

  • Jetpack by WordPress.com

のソース表示でいいか、と思ったのと、コードのタグとかがサニタイズ( < が &#060 にみたいに変換されたりするので外すことに

プラグインを外すと

[text]
 シンタックスハイライトしていた文章..
[/text]

[php]
 シンタックスハイライトしていたphpのコード..
[/php]

と文章に SyntaxHighlighter Evolved で使っていた、記号が出てしまいます

Jetpack by WordPress.comのMakdownは ``` で囲えばいいのですがこれは
preタグ+codeタグに変換されます
文章をMysqlでいっきに置換してみます

まず [text] とか出てる記事を見て ID を調べます

http://(wordpress address)/?p=611

とかの611がIDだったりします

ひとつ試しにIDを指定して置換

サーバー、mysqlにログイン

$ mysql -u (mysqluser) -p (wordpress database name)

表示した記事の文章を置換して [text] -> <pre><code> に変換

mysql> update wp_posts set post_content = replace(post_content, ‘[text]’, ‘<pre><code>’) where id = 611;
mysql> update wp_posts set post_content = replace(post_content, ‘[/text]’, ‘</code></pre>’) where id = 611;

記事確認
http://(wordpress address)/?p=611

無事きれいになってたら成功
where以降をとってしまえば、全記事に適用されます([text]がない記事には影響しない)

mysql> update wp_posts set post_content = replace(post_content, ‘[text]’, ‘<pre><code>’);
mysql> update wp_posts set post_content = replace(post_content, ‘[/text]’, ‘</code></pre>’);

どうように [php] も取ります

mysql> update wp_posts set post_content = replace(post_content, ‘[php]’, ‘<pre><code>’);
mysql> update wp_posts set post_content = replace(post_content, ‘[/php]’, ‘</code></pre>’);

ひとつプラグインが減ってすっきりしました

jQueryで非表示にする

jQueryを使って非表示にするには

<div id="box1" class="box">this is box1.</div>
<div id="box2" class="box">this is box2.</div>
<div id="box3" class="box">this is box3.</div>

id指定だと

$('#box1').hide();

boxクラスで全部非表示にだと

$('.box').each( function() { $(this).hide(); } );

シンプルにこれでもいい

$('#box1').css('display', 'none');
$('.box').each( function() { $(this).('display', 'none'); } );