2016年4月27日水曜日

MySQLでError Code : 1548 Cannot load from mysql.proc. The table is probably corruptedとか出て困ったときの対処法

何かのきっかけ(システムの更新?)でMySQLがmysql.procからロードできない、なんか壊れてるよ、ってエラーが出た場合にした対処方法をメモ。

mysql_upgrade -u root -p

これをするとMySQLを治してくれた。

参考:

https://dev.mysql.com/doc/refman/5.1/en/upgrading-from-previous-series.html

http://blog.zwiegnet.com/linux-server/error-code-1548-cannot-load-from-mysql-proc-the-table-is-probably-corrupted/

http://serverfault.com/questions/361838/mysql-cannot-load-from-mysql-proc-the-table-is-probably-corrupted

MySQLのダンプとリストアのなかなかよくまとまってるページがあったのでメモ

MySQLのダンプとリストアのなかなかよくまとまってるページがあったのでメモ

http://xpaper.info/information-technology/mysql-backup-and-restore-commands-with-gzip-bzip2/#.Vx-mT6MrLdR

MySQLのビューでプライマリキーとなるカラムが無い場合、Hibernateのエンティティをどう書くのか?

MySQLのビューでプライマリキーとなる@IDが無い場合、つまり、複数のカラムでユニークキーとなる場合はそれぞれのカラムに@IDを指定する。

但し、これはJPAによると推奨されていないらしい。


http://stackoverflow.com/questions/4381290/hibernate-exception-org-hibernate-annotationexception-no-identifier-specified

2016年4月16日土曜日

SVGでチェックボックスを使いたい時はforeignObjectのタグを使う

<script type="text/javascript">
    var svg = d3.select("body").append("svg")
        .attr("width", 100)
        .attr("height", 100);

    svg.append("foreignObject")
        .attr("width", 100)
        .attr("height", 100)
        .append("xhtml:body")
        .html("<form><input type=checkbox id=check /></form>")
        .on("click", function(d, i){
            console.log(svg.select("#check").node().checked);
        });
</script>


http://bl.ocks.org/biovisualize/3085882
https://developer.mozilla.org/ja/docs/Web/SVG/Element/foreignObject

d3.jsonを一時的にハードコードしたデータでテストしたい時


こういうAjaxでのリクエストを、

d3.json("/test/this/url", function(json) {
// ToDo: ------> Write something here..
}

こういう感じで変えると、バックエンドがない場合でもテストできる。

var testData = '{test:[1,2,3]}';
var json = JSON.parse( testData );

http://stackoverflow.com/questions/10934853/d3-js-loading-json-without-a-http-get

d3はmin, maxで最大値や最小値で配列からデータを取得できる


var data = [1, 2, 3];
d3.min(data) ---> 1
d3.max(data) ---> 3

http://stackoverflow.com/questions/11488194/how-to-use-d3-min-and-d3-max-within-a-d3-json-command

d3で子のHTMLの子エレメントとSVGの子エレメントを削除する方法はちょっと違う

HTMLの要素の場合:
d3.select("div.parent").html("");

SVGの要素の場合:
d3.select("g.parent").selectAll("*").remove();


http://stackoverflow.com/questions/14422198/how-do-i-remove-all-children-elements-from-a-node-and-them-apply-them-again-with

RESTfulなWEBサービスへのアクセスをLinuxのコンソールからテストする方法は?


curlコマンドを使う。-HオプションでJSON取得を指定して、-Xでメソッド(GET/POST/PUT/UPDATE/DELETE)を指定できる。

curl -i -H "Accept: application/json" -X GET http://abc.def.com/test/this/url


http://stackoverflow.com/questions/21326397/curl-get-request-with-json-parameter

2016年1月5日火曜日

Tomcatのログローテーションのやり方

Tomcatのログローテーションのやり方を確認。

/etc/logrotate.d/tomcat

/var/log/tomcat/catalina.out {   copytruncate   daily   rotate 7   compress   missingok   size 5M  }

https://dzone.com/articles/how-rotate-tomcat-catalinaout

2015年12月2日水曜日

MySQLでの実行コマンドの履歴を表示するには

MySQLのコマンドのログをチェックしたかったので調べたら、どうやらファイルが作成されているようだ。

cat ~/.mysql_history

http://stackoverflow.com/questions/7818031/sql-command-to-display-history-of-queries

SpringでUTF8エンコードで表示されない問題の解決方法

Spring MVCで文字エンコーディングがUTF8で表示されないので苦戦したが、どうやらエンコードで使っていたフィルターの順序が問題だったようなので、1番目に設定したらエンコード問題がなくなった。

 <filter>
     <filter-name>EncodingFilter</filter-name>
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
     <init-param>
         <param-name>encoding</param-name>
         <param-value>UTF-8</param-value>
     </init-param>
     <init-param>
         <param-name>forceEncoding</param-name>
         <param-value>true</param-value>
     </init-param>
 </filter>

http://stackoverflow.com/questions/16029269/utf-8-encoding-with-form-post-and-spring-controller

2015年9月13日日曜日

iPhotoの写真でビックリマークが出現した時の対処方法

MacのOSのバージョンアップを重ねたり、外付けハードが予期せぬ出来事でUSBから外れたりと、どういう状況で発生しているのか分かりませんが、iPhotoのアルバム内の写真がビックリマークの出現で表示できないという事態が起こる時があります。

こういう場合はiPhoto起動時にCommand+Optionを押すと、フォトライブラリFirst Aidを使う。データベースを修復というオプションで修復できない場合は、データベースの再構築で修復する。

参考:
https://discussions.apple.com/thread/3873468?start=0&tstart=0

2015年8月8日土曜日

Blocked loading mixed active contentが出た時に気をつけること

FirefoxのFirebugで"Blocked loading mixed active content..."というエラーが出てるので調べてみると、どうやらCDNを使ってHTMLページでインポートしてるJS/CSSファイルが読み込まれていない。

さらに掘り下げてみると、httpsで読み込んでるページからhttpでこれらのCDNからJS/CSSを読み込もうとするとエラーが出てるようだ。

What is Mixed Content?When a user visits a page served over HTTP, their connection is open for eavesdropping and man-in-the-middle (MITM) attacks. When a user visits a page served over HTTPS, their connection with the web server is authenticated and encrypted with SSL and hence safeguarded from eavesdroppers and MITM attacks.However, if an HTTPS page includes HTTP content, the HTTP portion can be read or modified by attackers, even though the main page is served over HTTPS. When an HTTPS page has HTTP content, we call that content “mixed”. The webpage that the user is visiting is only partially encrypted, since some of the content is retrieved unencrypted over HTTP. The Mixed Content Blocker blocks certain HTTP requests on HTTPS pages.
引用:
http://stackoverflow.com/questions/18251128/why-am-i-suddenly-getting-a-blocked-loading-mixed-active-content-issue-in-fire

要するに、HTTPSのページにHTTPリクエストで呼ばれているコンテンツがあると、それを”mixied(混在した)”コンテンツとみなし、MITM攻撃の被害になりえるのでやめて下さいとFirefoxが新しいバージョンではエラーとして表示してくれているようだ。

一般的な解決策は意外と簡単で、インポートしてるファイル(js/css)の構文をhttpからhttpsに変えてやればいい。もしくは//みたいな書き方でURLをブラウザが自動判別してくれるということ。

http://stackoverflow.com/questions/4831741/can-i-change-all-my-http-links-to-just

追加:

ただ、CDNによってはhttpからhttpsになぜかリクエストが変わってくれなかったので、そういうケースは泣く泣くCDNを使わずローカルにファイルを保存したりして回避した。

2015年8月5日水曜日

Tomcat6でjsessionidをURLから表示させないようにするには?

Tomcat6でjsessionidをURLから表示させないようにするには、context.xmlでContextの属性値をdisableURLRewriting="true"にしてやる。

<Context disableURLRewriting="true">
....
</Context>

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

2015年8月1日土曜日

Antでビルドする時にサーバー環境によってweb.xmlの内容を書き換えたいのでcopyタスクのFilterChainsを使う

Antでビルドする時にサーバー環境によってweb.xmlの内容や他の設定ファイル類の内容を書き換えたいので調べてみたら、copyタスクにFilterChainsというタスクで指定した文字列を書き換える事ができると分かったのでやってみた。

やり方の流れ:


  1. 書き換えたいファイルのテンプレートとなるファイルを作る(web_template.xml)
  2. テンプレートで書き換わる文字列をプロパティとして設定したファイルを作る(server1.xml)
  3. ビルドファイルにテンプレートと変数を元に生成するファイル(web.xml)を作るルールを書く(build.xml)
1.web_template.xml

....
<context-param>
    <param-name>someparameter</param-name>
    <param-value>@somevariable@</param-value>
</context-param>
....

※@~@の@は分かり易くつけてるだけです。

2.server1.xml

<project>
    <property name="server.host" value="abc.com" />
</project>

3.build.xml

<target name="rewriteXmlFile" >

    <copy file="/template/web_template.xml"  tofile="/WEB-INF/web.xml" overwrite="true">
        <filterchain>
            <tokenfilter>
                <replacestring from="@somevariable@" to="${server.host}"/>        
            </tokenfilter>
        </filterchain>
    </copy>

</target>



http://stackoverflow.com/questions/5217501/ant-copy-filterset
http://ant.apache.org/manual/Tasks/copy.html
http://ant.apache.org/manual/Types/filterchain.html#replacestring


2015年7月30日木曜日

MySQLのSelect文で特定の文字列の場所を見つけると同時に分割する関数

MySQLのSelect文で特定の文字列の場所を見つけると同時に分割する関数でsubstring_indexというのが便利だったのでメモ。indexofとsubstringの両方が合わさったもの。

substring_index("www.google.com",".","2)

1つ目と2つ目の引数は明らかなので割愛。3つ目の引数がポイント。

正の数:分割された文字列の何番目かを左からから指す
負の数:分割された文字列の何番目かを右からから指す


http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php

2015年6月17日水曜日

MySQLについてくるautomysqlbackupの使い方

MySQLにはバックアップ専用にautomysqlbackupがついてくるので、ちょっと使い方についてメモ書き。


  1. sudo apt-get install automysqlbackup でインストール
  2. /var/lib/automysqlbackup にバックアップが毎日作られるが、スクリプト中で保存先は指定できる。
※ BACKUPDIRとDBNAMESぐらいかな、変更したのは。。




https://serverpilot.io/community/articles/how-to-back-up-mysql-databases-with-automysqlbackup.html