Skip to content

Instantly share code, notes, and snippets.

View Y-Fujikawa's full-sized avatar
🥃
Working from home

Y-Fujikawa Y-Fujikawa

🥃
Working from home
View GitHub Profile
@Y-Fujikawa
Y-Fujikawa / supsert_test_data.sql
Last active January 14, 2017 05:52
supersetのテストデータ投入SQL
CREATE DATABASE sample CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON *.* TO sample@localhost IDENTIFIED BY 'sample' WITH GRANT OPTION;
use sample;
CREATE TABLE `trn_customer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(255) DEFAULT NULL,
`last_name` varchar(255) DEFAULT NULL,
`first_name_kana` varchar(255) DEFAULT NULL,
`last_name_kana` varchar(255) DEFAULT NULL,
@Y-Fujikawa
Y-Fujikawa / 2017-06-08_Sample.rb
Last active June 8, 2017 00:56
moduleの呼び出し確認
module Hoge1
class Base
# 初期処理は1つにまとめる
def initialize *args
@x = "Hoge1 - Base - initialize - #{args[0]}"
end
# Common配下のすべてのクラスに共通するメソッド
def display
puts @x
@Y-Fujikawa
Y-Fujikawa / 0_reuse_code.js
Created June 8, 2017 01:00
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Y-Fujikawa
Y-Fujikawa / 2017-06-17_sample_001.rb
Created June 17, 2017 06:48
可変長引数のサンプルソース
# 引数を元にメッセージを表示する
def display_messages(name, *messages)
messages.each do |message|
p "#{name} : #{message}"
end
end
# 実行
display_messages 'John', 'Hello', 'Goodbye', 'Thank you'
@Y-Fujikawa
Y-Fujikawa / 2017-06-17_sample_002.rb
Created June 17, 2017 06:56
配列の展開のサンプルソース
# 引数を元にメッセージを表示する
def display_messages(name, message_first, message_second)
p "#{name} : #{message_first}"
p "#{name} : #{message_second}"
end
# 実行(正常動作)
messages = %w(Hello Goodbye)
display_messages 'John', *messages
@Y-Fujikawa
Y-Fujikawa / 2017-06-18_sample_002.rb
Created June 18, 2017 05:21
キーワード引数(デフォルト値なし)のサンプルソース
# 引数を元にメッセージを表示する
def display_message(name:, message:)
p "#{name} : #{message}"
end
display_message(name: 'John', message: 'Hello')
display_message(message: 'Hello', name: 'John')
display_message
display_message('John', 'Hello')
@Y-Fujikawa
Y-Fujikawa / 2017-06-18_sample_001.rb
Last active June 18, 2017 05:22
キーワード引数(デフォルト値あり)のサンプルソース
# 引数を元にメッセージを表示する
def display_message(name: 'Smith', message: 'Sample')
p "#{name} : #{message}"
end
display_message
display_message(name: 'John', message: 'Hello')
display_message(message: 'Hello', name: 'John')
display_message('John', 'Hello')
@Y-Fujikawa
Y-Fujikawa / 2017-07-09_sample_001.rb
Created July 9, 2017 05:07
文字列リテラルのダブルクォートとシングルクォート
# ダブルクォート
# ・バックスラッシュ記法と式展開が有効になる
str1 = "式展開も試してみます"
puts "ダブルクォートのサンプル文字列です\n\nそして、#{str1}"
# 文字列内でダブルクォートを使いたい場合、エスケープ文字を入れる
# ※「サンプル文字」をダブルクォートで括ってみる
puts "ダブルクォートの\"サンプル文字列\"です\n\nそして、#{str1}"
# シングルクォート
@Y-Fujikawa
Y-Fujikawa / 2017-08-12_sample_001.rb
Created August 12, 2017 08:44
moduleに関すること
module ViewString
def view(message)
puts message
end
end
class Sample1
# includeした場合、インスタンスメソッドとして使える
include ViewString
end
@Y-Fujikawa
Y-Fujikawa / 2017-09-12_sample_001.rb
Last active September 12, 2017 03:26
define_methodに関すること
class Animal
{ cat: 'にゃー', dog: 'わん' }.each do |name, message|
# 動的にクラスやモジュールを定義でき、defによるメソッド定義をしなくてもよい
# メソッド本体はブロックで記述する
define_method(name) do
message
end
end
end