This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update | |
sudo apt-get upgrade | |
sudo apt-get install build-essential cmake pkg-config | |
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev | |
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev | |
sudo apt-get install libxvidcore-dev libx264-dev | |
sudo apt-get install libgtk2.0-dev | |
sudo apt-get install libatlas-base-dev gfortran | |
sudo apt-get install python2.7-dev python3-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
class Converter | |
def initialize(file_name) | |
@file_name = file_name | |
@tables = {} | |
@current_table = {} | |
end | |
def to_ruby(rails_v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
end | |
class Admin < User | |
has_many :images, as: :imageable | |
end | |
class NormalUser < User | |
has_many :images, as: :imageable | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twelves = User.where(age: 12) | |
# ActiveRecord::QueryMethods#limitを使用する | |
twelves.limit(3) | |
# User Load (4.9ms) SELECT `users`.* FROM `users` WHERE `users`.`age` = '12' LIMIT 3 | |
#=> <#ActiveRecord::Relation [<#User id: 1, name: "ゴン=フリークス", age: 12>, <#User id: 2, name: "キルア=ゾルディック", age: 12>, <#User id: 3, name: "ピーター・パン", age: 12>]> | |
# ActiveRecord::FinderMethods#takeを使用する | |
twelves.take(3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BeatingFreeza | |
class << self | |
def possible?(collection) | |
new(collection).possible? | |
end | |
end | |
def initialize(collection) | |
@collection = collection | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mechanize' | |
AGENT = Mechanize.new | |
BASE_URL = 'https://yomikatawa.com/kanji/' | |
def to_hiragana(kanji) | |
AGENT.get(BASE_URL + kanji).search('#content p').first.inner_text | |
end | |
def to_romaji(kanji) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def keys_to_sym | |
self.inject({}) do |hash, (key, value)| | |
value = value.keys_to_sym if value.class == Hash | |
hash[key.to_sym] = value | |
hash | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
問題3. Rails記述問題 | |
1. RailsでActiveRecord::Baseを継承すればfind,newなどのDatabaseに関わる様々なメソッドが使えるようになる。 | |
2. mergeメソッドは二つの配列を合成するためのメソッドである。 | |
3. n+1問題とはSQL文を発行しすぎることの問題である。これはcontrollerで取り出した情報のリレーションされているものをviewファイルで取り出すときにもう一度SQL文が走ってしまうことに原因があるので、controllerで取り出すときにincludeメソッドで同時にリレーションするものもひとつのSQL文でまとめて取り出すことで解決する。 | |
4. deviseは会員登録の機能を実装するためのgemである。 | |
5. kaminariを導入すればページネーションを簡単に実装することができる。 |