Skip to content

Instantly share code, notes, and snippets.

View shoyan's full-sized avatar

Shohei Yamasaki shoyan

View GitHub Profile
@shoyan
shoyan / sample_static.php
Created February 7, 2014 08:33
static修飾子の簡単なサンプル
<?php
/*
* static修飾子を使うとあたかもインスタンスのメンバ変数のような振る舞いができる
*/
class Hoge
{
static $hoge = null;
function add()
{
@shoyan
shoyan / verify_authenticity_token.rb
Created April 10, 2014 03:28
[Rails]外部の認証機構よりcallbackしたときにCSRFのチェックにひっかかってしまう問題への対処法
# 外部の認証機構よりcallbackしたときにCSRFのチェックにひっかかってしまう問題への対処法
skip_before_filter :verify_authenticity_token, only: [ :callback ]
@shoyan
shoyan / word_list.rb
Created April 16, 2014 03:44
ymlから単語リストを取得して、ランダムでだす(サンプル)
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 16:07
Object.createを使ったMixInのサンプル
/*
* 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 January 15, 2015 09:13
test of EmailValidator.
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(:<<)
@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 / 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";