2016年8月16日火曜日

正規表現メモ

        //数字で始まり、1つ以上で終わり
        var re0 = /^[0-9]+$/ ;
         var val0 = $('#txt0').val();
         if(val0.match(re0)){
                 alert("数字です");

         }

         //数字で始まり、数字4桁-数字2桁-数字2桁で終わる
         //var re1 = /^[0-9]{4}[¥-][0-9]{2}[¥-][0-9]{2}$/;
         var re1 = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
        
         var val1 = $('#txt1').val();
         if(val1.match(re1)){
             alert("カレンダー型!");

         }

2016年8月14日日曜日

HomeBrewでrootでログインできなくなったので対応メモ。

HomeBrewで再度インストールしたが、rootでログインができなくなったので、対応のメモ
$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.12.el_capitan.bot
Already downloaded: /Library/Caches/Homebrew/mysql-5.7.12.el_capitan.bottle.tar.gz


==> Pouring mysql-5.7.12.el_capitan.bottle.tar.gz

==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql/5.7.12: 13,281 files, 444.8M


rootでログインができないのでハマル・・・
Access denied for user 'root'@'localhost' (using password: NO)が出たら
セーフモードでmysqlを起動すれば、rootでパスワードなしでログインできるようだ。
以下のように対応


mysqlを停止
mysql.server stop

プロパティリスト(.plist)ファイルのKeepAliveをfalseに変更。
プロパティリスト?
プロパティリストは Mac OS X や iOS で利用することができるデータ永続化のためのファイル形式です。Mac OS X ではもっぱらユーザの情報を設定するのに使われる事が多く Windows のレジストリのような使われ方をしています。iOS では Info.plist のようにアプリの情報を設定するのに使われることが多いですとのこと。
http://glassonion.hatenablog.com/entry/20110910/1315609950



cd ~/Library/LaunchAgents
vi  homebrew.mxcl.mysql.plist

  <key>KeepAlive</key>
  <false/>

セーフモードでmysqlを起動する。
mysqld_safe —skip-grant-tables

新しい、ターミナルを立ち上げる
mysql -uroot


update user set authentication_string=password("新しいパスワード") where user='root';

権限を再度読み込み
flush privileges;
quit;

MySQLを再起動
mysql.server restart

mysql -uroot -p
>新しいパスワード


で変更できた!

2016年8月1日月曜日

複数の結合表から削除方法

結合のように書く


delete table1, table2 from table1 left join table2 on table1.id = table2.id where table1.column = ?


http://blog.higty.xyz/archives/320/

2016年7月31日日曜日

Google検索でグラフが表示できる

Google検索で関数を入力すると、グラフを表示してくれる。 log(x),y=x,y=x^2と入力した場合の結果です。

2016年7月28日木曜日

c#文字列比較

c#では、Equalsではなく、==を使って文字列比較したほうが良さそうだね。
タイプセーフ、nullで比較した時に落ちない。Stringクラスの中で、==で比較できるように、Equalsを再定義してるようだ。
http://sinproject.blog47.fc2.com/blog-entry-38.html


C# == str1 == str2
VB.NE = str1 = str2
Java .equals str1.equals(str2)
VB6/VBA = str1 = str2
↑Option Compare {Binary|Text|Database}のモードによる
Binary  

バイナリ文字コード順によって並べ替え順序が決まります。
Option Compare ステートメントの記述がない場合はこの Binary モードが使用されます
Text  

50音順による並べ替え順になります。
ただし、大文字と小文字、文字幅、カタカナとひらがなは区別しません。

2016年7月21日木曜日

jQueryでKey Valueのテーブルから、KeyでValueを検索

1.Tableの要素を取得
2.find("td.class")でKeyが入ってるtdを取得
3.eachでごりごり回しながら、Keyとマッチ
4.マッチしたら、next()で隣の要素を取得
5. return false;でeachから抜ける

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>HTML5サンプル</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="   crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
//alert("hello");

 //検索ボタンクリック
 $(document).on("click", "[id='seach']", function() {
  $('#testTable').each(function () {
   $(this).find('td.code').each(function () {
    $(this).next().attr('style', '');
   });
   $(this).find('td.code').each(function () {
    if($(this).text() == $('#search_word').val()) {
    //alert($(this).next().text());
      $(this).next().attr('style', 'background-color:yellow');
      return false;
    } else {
     $(this).next().attr('style', '');
    }
   });
  });
 });


/*
 // grep
 $(document).on("click", "[id='seach']", function() {
  $('#testTable').each(function () {
   $(this).find('td').each(function () {
    if($(this).text().match(new RegExp($('#search_word').val(),"g"))) {
     $(this).attr('style', 'background-color:yellow');
    } else {
     $(this).attr('style', '');
    }
   });
  });
 });
*/
});
</script>
</head>
<body>
<br />
テキストボックスに検索したい文字を入力&#12289;検索ボタンをクリックすると&#12289;
<br />
入力した文字列が含まれるセルの背景色が黄色に変わります&#12290;<br />
<br />
<input type="text" id="search_word"">
<button type="button" id="seach"> Search </button>
<table id="testTable" border ="1">
<tr>
<th>Key</th><th>Value</th>
</tr>
<script type="text/javascript">
for (i=0; i<=10;i++){
    document.write("<tr>");
    document.write("<td class=\"code\">" + i + "</td>");
    document.write("<td>" + Math.floor(Math.random() *1000) + "</td>");
    document.write("</tr>");
}
</script>
</table>
</body>
</html>

LINQ Where句動的 AsQueryable()を使う。と可読性が増す

int? categoryID = null;
string categoryName = string.Empty;
string description = string.Empty;

// nullチェックとORでくっつけてやる
from c in ctx.Categories
where (categoryID == null || c.CategoryID == categoryID)
&& (string.IsNullOrEmpty(categoryName) || c.CategoryName == categoryName)
&& (string.IsNullOrEmpty(description) || c.Description == description)
select c;
↓でWhere句を動的に書ける。
var q = ctx.Categories.AsQueryable();
if (categoryID != null)
{
    q = q.Where(c => c.CategoryID == categoryID);
}
if (!string.IsNullOrEmpty(categoryName))
{
    q = q.Where(c => c.CategoryName == categoryName);
}