Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View shoyan's full-sized avatar

Shohei Yamasaki shoyan

View GitHub Profile
@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 / 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 / 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 / sample_static.php
Created February 7, 2014 08:33
static修飾子の簡単なサンプル
<?php
/*
* static修飾子を使うとあたかもインスタンスのメンバ変数のような振る舞いができる
*/
class Hoge
{
static $hoge = null;
function add()
{
@shoyan
shoyan / sql_practice_20130928.sql
Created September 28, 2013 12:09
SQLの練習帳
UPDATE class_A SET sex_code =1;
SELECT * FROM class_A;
UPDATE class_A SET sex_code = 2 WHERE id IN (3,4);
-- sex_codeをわかりやすく出力する
SELECT name,
CASE sex_code
WHEN 1 THEN 'Male'
@shoyan
shoyan / 3moji_ascii.rb
Created September 27, 2013 14:24
3文字の英数字の組み合わせ
ascii = []
0x61.upto(0x7a){|a| ascii.push(a.chr) }
0.upto(9) {|num| ascii.push(num.to_s) }
list = []
ascii.each do |chr1|
ascii.each do |chr2|
ascii.each do |chr3|
list.push(chr1 + chr2 + chr3)
end
@shoyan
shoyan / pascals_traiangle.rb
Last active December 23, 2015 17:29
パスカルの三角形をRubyで実装してみました。PascalsTriangle.new.run(10)で数字を出力、PascalsTriangle.new.run(40, 'fractal')でフラクタル図形を描画します。(fractalの場合はCOUNTを40くらいにするとよいです)
# encoding: utf-8
class PascalsTriangle
@@count= 10
@@list = []
def create(list)
sum = []
i = 1
while i < list.size
@shoyan
shoyan / yes_or_no_prompt.sh
Created September 5, 2013 04:02
yesかnoを訪ねて、yesの場合は処理をする
#!/bin/sh
while true; do
read -p "Do you wish to install this program? [y/n]" yn
case $yn in
[Yy] ) echo "Install!"; break;;
[Nn] ) exit;;
* ) echo "Please answer y or n.";;
esac
done
@shoyan
shoyan / simple_insert_sort.js
Created September 4, 2013 09:09
単純挿入法で配列の値を昇順にソートする(JavaScript版)
/*
* 単純挿入法で配列の値を昇順にソートする
*/
var list = [8, 1, 3, 4, 9, 5],
i = 1,
j,
tmp;
for (i; i < list.length; i++) {
@shoyan
shoyan / simple_insert_sort.rb
Created September 4, 2013 09:01
単純挿入法で配列の値を昇順にソートする(Ruby版)
#encoding: utf-8
#
# 単純挿入法で配列の値を昇順にソートする
#
list = [8, 1, 3, 4, 9, 5]
i = 1
while i < list.size do
j = i