Skip to content

Instantly share code, notes, and snippets.

@saboyutaka
saboyutaka / frogs_scraping.rb
Created Aug 2, 2018
スクレイピングの実演
View frogs_scraping.rb
require 'nokogiri'
require 'httparty'
url = 'https://www.ryukyu-frogs.com/information/'
res = HTTParty.get(url)
doc = Nokogiri::HTML.parse(res.body)
doc.css('.news-list li').each do |node|
puts node.css('.content .title').text
end
@saboyutaka
saboyutaka / user_sample.rb
Created Aug 2, 2018
クラスの宣言、インスタンス生成のサンプル
View user_sample.rb
class User
attr_accessor :first_name, :last_name, :age
// コンストラクタ Constructor
def initialize(last_name, first_name, age)
self.last_name = last_name
self.first_name = first_name
self.age = age
end
@saboyutaka
saboyutaka / Dockerfile
Created Jul 28, 2018
Docker Compose for Rails
View Dockerfile
FROM ruby:2.5.1
ENV LANG C.UTF-8
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
libfontconfig1 \
less \
@saboyutaka
saboyutaka / app.rb
Last active Jun 11, 2018
Sinatra Login
View app.rb
require 'sinatra'
require 'mysql2'
require 'mysql2-cs-bind'
def db
# Mysqlドライバの設定
@db ||= Mysql2::Client.new(
host: 'localhost',
port: 3306,
username: 'root',
@saboyutaka
saboyutaka / app.rb
Last active May 21, 2018
MySQLにアクセスしてデータを取得し表示する
View app.rb
require 'sinatra'
require 'sinatra/reloader'
require 'mysql2'
require 'mysql2-cs-bind'
# Mysqlドライバの設定
db = Mysql2::Client.new(
host: 'localhost',
port: 3306,
username: 'root',
@saboyutaka
saboyutaka / db.rb
Created May 21, 2018
MySQLにアクセス
View db.rb
require 'mysql2'
require 'mysql2-cs-bind'
# Mysqlドライバの設定
db = Mysql2::Client.new(
host: 'localhost',
port: 3306,
username: 'root',
password: '',
database: 'sample',
@saboyutaka
saboyutaka / app.rb
Last active May 21, 2018
ArrayとHashを表示させる
View app.rb
require 'sinatra'
require 'sinatra/reloader'
set :public_folder, File.dirname(__FILE__) + '/public'
get '/' do
@title = 'hoge'
erb :index
end
@saboyutaka
saboyutaka / app.rb
Created May 21, 2018
sinatra static files
View app.rb
require 'sinatra'
require 'sinatra/reloader'
set :public_folder, File.dirname(__FILE__) + '/public'
get '/' do
erb :index
end
@saboyutaka
saboyutaka / app.conf
Last active May 15, 2018
nginx setting
View app.conf
server {
server_name sample.test;
listen 80;
client_max_body_size 10m;
root /var/www;
location ~ .*\.(html?|jpe?g|gif|png|css|js|ico|swf|inc) {
expires 1d;
add_header Cache-Control 'public';
You can’t perform that action at this time.