Skip to content

Instantly share code, notes, and snippets.

Shohei Yamasaki shoyan

Block or report user

Report or block shoyan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@shoyan
shoyan / sample_static.php
Created Feb 7, 2014
static修飾子の簡単なサンプル
View sample_static.php
<?php
/*
* static修飾子を使うとあたかもインスタンスのメンバ変数のような振る舞いができる
*/
class Hoge
{
static $hoge = null;
function add()
{
@shoyan
shoyan / verify_authenticity_token.rb
Created Apr 10, 2014
[Rails]外部の認証機構よりcallbackしたときにCSRFのチェックにひっかかってしまう問題への対処法
View verify_authenticity_token.rb
# 外部の認証機構よりcallbackしたときにCSRFのチェックにひっかかってしまう問題への対処法
skip_before_filter :verify_authenticity_token, only: [ :callback ]
@shoyan
shoyan / word_list.rb
Created Apr 16, 2014
ymlから単語リストを取得して、ランダムでだす(サンプル)
View word_list.rb
class WordList
class << self
def find(option = {})
default_option = {limit: 10}.merge(option)
option = default_option.merge(option)
word_list_path = Rails.root.join('lib/word_list/config/')
@word_list = []
@file ||= YAML.load_file(word_list_path.to_s + file)
@shoyan
shoyan / object_create_mix_in.js
Created May 14, 2014
Object.createを使ったMixInのサンプル
View object_create_mix_in.js
/*
* Object.create(): the New Way to Create Objects in JavaScript
* http://www.htmlgoodies.com/beyond/javascript/object.create-the-new-way-to-create-objects-in-javascript.html
*/
var Car2 = Object.create(null); //this is an empty object, like {}
Car2.prototype = {
getInfo: function() {
return 'A ' + this.color + ' ' + this.desc + '.';
@shoyan
shoyan / email_validator_spec.rb
Created Jan 15, 2015
test of EmailValidator.
View email_validator_spec.rb
require 'spec_helper'
describe "EmailValidator" do
before do
@validator = EmailValidator.new({:attributes => {email: ''}})
@mock = double("Foo")
allow(@mock).to receive(:errors).and_return([])
allow(@mock.errors).to receive(:[]).and_return({})
allow(@mock.errors[]).to receive(:<<)
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 / 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";
You can’t perform that action at this time.