Skip to content

Instantly share code, notes, and snippets.

View shoyan's full-sized avatar

Shohei Yamasaki shoyan

View GitHub Profile
@shoyan
shoyan / .vimrc
Created August 7, 2012 07:43
.vimrc
set nocompatible
filetype off
set rtp+=~/.vim/vundle.git/
call vundle#rc()
Bundle 'quickrun.vim'
Bundle 'neocomplcache'
@shoyan
shoyan / simpletest_calc
Created September 14, 2012 10:18
sample is simple test with php4
<?php
require_once('simpletest/autorun.php');
require_once('Calc.php');
class TestOfCalc extends UnitTestCase {
function testCalcAdd() {
$calc = new Calc();
// 1 + 1 = 2
$this->assertEqual($calc->add(1,1), 2);
@shoyan
shoyan / rake sample
Created October 4, 2012 00:19
rakeファイルのサンプル
require 'rake'
require 'rspec/core/rake_task'
# RSpec::Core::RakeTask.new(:spec)
# task :default => :spec
task :default do
filelist = FileList['spec/*_spec.rb'].join(' ')
sh "bundle exec rspec #{filelist}"
end
@shoyan
shoyan / nihongo_validate.js
Created December 5, 2012 00:54
jsの日本語バリデーションサンプル
var wPat = "[a-zA-Z0-9-]"; // 英数字・ハイフン
wPat += "|[\u3041-\u3093]"; // ひらがな
wPat += "|[\u30A1-\u30F6]"; // カタカナ
wPat += "|[・ヽヾゝゞ々ー]"; // 記号
wPat += "|[\u4E00-\u9FFF]"; //漢字
wPat = "^(" + wPat +")+$";
if (!str.match(wPat)) {
return false;
}
@shoyan
shoyan / const_tips1.php
Created December 6, 2012 01:52
定数をリテラルの中で使う方法
<?php
define('FOO', 1);
define('BAR', 2);
// 変数展開が「{$」で始まっている場合、関数の実行等が可能です。
$c = 'constant';
echo "FOO: {constant('FOO')}, BAR: {constant('BAR')}" . PHP_EOL; // => FOO: 1, BAR: 2
@shoyan
shoyan / custome_object_sample01.js
Created January 9, 2013 03:26
カスタムオブジェクトのサンプル
<script>
var Obj = function(){
var background = "#fff";
var state = "on";
this.change_state = function(){
if(state === "on"){
state = "off";
background = "#000";
} else {
state = "on";
@shoyan
shoyan / debug.js
Created January 11, 2013 00:27
javascriptでエラーが起きたら補足してalertで表示してくれる
window.onerror = function(message, url, linenumber) {
alert("JavaScript error: " + message + " on line " + linenumber + " for " + url);
}
@shoyan
shoyan / exception_notifier.js
Created January 11, 2013 08:52
javascriptのエラーをapacheでloggingできるようにします。
window.onerror = function(message, file, lineNumber) {
new Image().src = "/this_url_doesnt_exist?message="
encodeURIComponent(message)
"&file=" + encodeURIComponent(file)
"&lineNumber=" + encodeURIComponent(lineNumber);
};
@shoyan
shoyan / exception_notifier_analytics.js
Created January 11, 2013 09:21
javascriptのエラーをanalyticsに送る
window.onerror = function(message, file, lineNumber) {
_gaq.push([
'_trackEvent',
'error',
file + ':' + lineNumber,
message + ''
]);
};
@shoyan
shoyan / user_agent.php
Last active December 11, 2015 06:39
USER_AGENTを見て判断するサンプル
<?php
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$isMobile = false;
if (preg_match("/Android/", $userAgent, $match)) {
$isMobile = true;
}
if (preg_match("/iPhone/", $userAgent, $match)) {