Skip to content

Instantly share code, notes, and snippets.

Shohei Yamasaki shoyan

View GitHub Profile
View .vimrc
set nocompatible
filetype off
set rtp+=~/.vim/vundle.git/
call vundle#rc()
Bundle 'quickrun.vim'
Bundle 'neocomplcache'
@shoyan
shoyan / simpletest_calc
Created Sep 14, 2012
sample is simple test with php4
View simpletest_calc
<?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 Oct 4, 2012
rakeファイルのサンプル
View rake sample
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 Dec 5, 2012
jsの日本語バリデーションサンプル
View nihongo_validate.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 Dec 6, 2012
定数をリテラルの中で使う方法
View const_tips1.php
<?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 Jan 9, 2013
カスタムオブジェクトのサンプル
View custome_object_sample01.js
<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 Jan 11, 2013
javascriptでエラーが起きたら補足してalertで表示してくれる
View debug.js
window.onerror = function(message, url, linenumber) {
alert("JavaScript error: " + message + " on line " + linenumber + " for " + url);
}
@shoyan
shoyan / exception_notifier.js
Created Jan 11, 2013
javascriptのエラーをapacheでloggingできるようにします。
View exception_notifier.js
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 Jan 11, 2013
javascriptのエラーをanalyticsに送る
View exception_notifier_analytics.js
window.onerror = function(message, file, lineNumber) {
_gaq.push([
'_trackEvent',
'error',
file + ':' + lineNumber,
message + ''
]);
};
@shoyan
shoyan / user_agent.php
Last active Dec 11, 2015
USER_AGENTを見て判断するサンプル
View user_agent.php
<?php
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$isMobile = false;
if (preg_match("/Android/", $userAgent, $match)) {
$isMobile = true;
}
if (preg_match("/iPhone/", $userAgent, $match)) {
You can’t perform that action at this time.