UbuntuのbashがCtrl+sで固まらないようにする

Ubuntuのbashで作業していて
Ctrl+s
を押してしまうと画面がかたまります

戻るには
Ctrl+q
を押せば戻れるのですが不便です

$ stty -a
をみると

stop = ^S;

とstopにCtrl + sが割り当たっているからなので

$ stty stop undef
としてしまえば無効になります

常に無効にしたかったら

~/.bashrc

stty stop undef
を書き込んでしまえばいいです

gem install mysql2でエラー

$ gem install mysql2
でエラー発生

[code lang=text]
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/home/vagrant/.rbenv/versions/2.2.0/bin/$(RUBY_BASE_NAME)
–with-mysql-dir
–without-mysql-dir
–with-mysql-include
–without-mysql-include=${mysql-dir}/include
–with-mysql-lib
–without-mysql-lib=${mysql-dir}/lib
–with-mysql-config
–without-mysql-config
–with-mysql-dir
–without-mysql-dir
–with-mysql-include
–without-mysql-include=${mysql-dir}/include
–with-mysql-lib
–without-mysql-lib=${mysql-dir}/lib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mlib
–without-mlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-zlib
–without-zlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-socketlib
–without-socketlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-nsllib
–without-nsllib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mygcclib
–without-mygcclib
–with-mysqlclientlib
–without-mysqlclientlib

extconf failed, exit code 1

Gem files will remain installed in /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/mysql2-0.3.17 for inspection.
Results logged to /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86-linux/2.2.0-static/mysql2-0.3.17/gem_make.out
Installing truncate_html 0.9.2
Installing spring 1.2.0
An error occurred while installing mysql2 (0.3.17), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.17'` succeeds before bundling.
[/code]

調べてたらmysql周りのものが足りないらしく
$ sudo apt-get install mysql-client libmysqlclient-dev
で解決しました

参考サイト) http://stackoverflow.com/questions/19765290/error-failed-to-build-gem-native-extension-error-installing-mysql2

jQueryUIのautocompleteにcomboboxをつけて空白も選べるようにする

jQueryUIのautocompleteにcomboboxをつけて使っていたのですが、空白表示も選ばせたくちょっと手を加えました

コードは、
http://jqueryui.com/autocomplete/#combobox
の view source をクリックすれば見れます
htmlで保存するだけで使えるのですが

107行目を

if ( this.value && ( !request.term || matcher.test(text) ) )

if ( !request.term || matcher.test(text) )

に変更
これで、valueがない空白ものもリストに含まれます
これだと Select one… という文字が表示されるので

171行目を

<option value="">Select one...</option>

<option value="">&#27;</option>

にかえます
画面に表示されないHTMLエンティティならなんでもいいと思います

これで空白が表示されるようになります

参考) http://stackoverflow.com/questions/25523636/jquery-ui-combo-box-empty-value-rendering

javascriptの正規表現まわりのメソッドを整理

javascriptの正規表現まわりのメソッドを整理してみました

Regexp

  • test -> マッチしたら true or false を返す
  • exec -> マッチした結果が返る

String

  • search -> マッチしたらマッチしたインデックスを返す
  • match -> マッチした結果が返る

実行した結果がこちら

var re = /am/;
var str = 'sample string';

console.log( re.test(str) );
// true
console.log( re.exec(str) );
// ["am", index: 1, input: "sample string"]

console.log( str.search(re) );
// 1
console.log( str.match(re) );
// ["am", index: 1, input: "sample string"]

パターンマッチ演算子のgをつけてみます(globalのg)
g をつけると繰り返しマッチさせます

var re = /am/g;
var str = 'sample string sample';

console.log( re.test(str) );
// true
console.log( re.exec(str) );
// ["am", index: 15, input: "sample string sample"]

console.log( str.search(re) );
// 1
console.log( str.match(re) );
// ["am", "am"]

re.exec の index が最後のマッチの index が返ってきて、
str.matchがマッチした分が配列で返ってきています