Skip to content

Instantly share code, notes, and snippets.

View songfei1983's full-sized avatar

songfei songfei1983

View GitHub Profile
@songfei1983
songfei1983 / file0.js
Last active August 29, 2015 14:10
よくWebOSやJSで禁止されるキー設定 ref: http://qiita.com/songfei1983/items/f8d5fde5709c74c6b5f5
var event = e || window.event;
var k = event.keyCode;
if((event.ctrlKey == true && k == 82) || (event.ctrlKey == true && k == 78) || (k == 116) || (event.ctrlKey == true && k == 116))
{
event.keyCode = 0;
event.returnValue = false;
event.cancelBubble = true;
return false;
}
@songfei1983
songfei1983 / EuclidDistance.php
Last active August 29, 2015 14:12
欧几里得度量(euclidean metric)二维
<?php
// 欧几里得度量_百度百科 http://baike.baidu.com/link?url=zAEZl46AoeKqIg0v1n_nPWP5JycEYvoOepRf_lTin_i-nb9YTNQGOFILLYYqTxF3Nho0Wn5vWgNWTYHklq0mE_
function distance()
{
$argv = func_get_args();
$argc = func_num_args();
if ($argc !== sizeof($argv)) return;
$res = $j = intval(NULL);
for (; $j < sizeof($argv[0]); $j++)
@songfei1983
songfei1983 / file0.scala
Last active August 29, 2015 14:14
1から100までの奇数の平方合 ref: http://qiita.com/songfei1983/items/66965bc935039d4a9791
scala> (0/:(0 to 100))((s,i)=>s+i%2*i*i)
@songfei1983
songfei1983 / EvolutionSpec.scala
Created March 4, 2015 15:46
Evolution Unit Test
import play.api.db.evolutions.Evolutions
import play.api.db.DBPlugin
import play.api.db.evolutions.InconsistentDatabase
import play.api.test.FakeApplication
import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner._
/**
@songfei1983
songfei1983 / file0.txt
Last active August 29, 2015 14:17
新しいホストをknown_hostsに追加 ref: http://qiita.com/songfei1983/items/d2f543697e6eb777323c
ssh-keygen -R [hostname]
ssh-keygen -R [ip_address]
ssh-keygen -R [hostname],[ip_address]
ssh-keyscan -H [hostname],[ip_address] >> ~/.ssh/known_hosts
ssh-keyscan -H [ip_address] >> ~/.ssh/known_hosts
ssh-keyscan -H [hostname] >> ~/.ssh/known_hosts
/**
* This action is used to serve Home page of the application
*
* @return
*/
def index = Action { implicit request =>
Ok(views.html.index("Your new application is ready."))
}
/**
@songfei1983
songfei1983 / file0.scala
Created May 10, 2015 01:14
可変引数Rangeの重複しない整数の個数を求める。 ref: http://qiita.com/songfei1983/items/2ea390612bed3b1b40b5
def cover(rs: Range*):Int = ???
assert(cover(0 to 4, 1 to 5) == 6)
assert(cover(0 to 4, 1 to 3) == 5)
assert(cover(0 to 4, 6 to 7) == 7)
assert(cover(0 to 4, 6 to 7, 2 to 6) == 8)
@songfei1983
songfei1983 / size.sql
Created July 7, 2015 01:06
テーブルのコラムサイズを調べる ref: http://qiita.com/songfei1983/items/8a9b1fba0ae0513dcd45
select
sum(pg_column_size(the_text_column)) as total_size,
avg(pg_column_size(the_text_column)) as average_size,
sum(pg_column_size(the_text_column)) * 100.0 / pg_relation_size('t') as percentage
from t;
@songfei1983
songfei1983 / ls.txt
Last active August 29, 2015 14:28
lsでディレクトリのみ,ファイルのみ,表示する
// ディレクトリのみ
ls -F | grep /
// ファイルのみ
ls -F | grep -v /
@songfei1983
songfei1983 / file0.txt
Created August 30, 2015 00:28
メモ!Finderで隠しファイル・フォルダを表示 - Mac ref: http://qiita.com/songfei1983/items/84777346c65a1882cb7e
$ defaults write com.apple.finder AppleShowAllFiles TRUE