Skip to content

Instantly share code, notes, and snippets.

@kouyaf77
kouyaf77 / test_rspec.rb
Created March 18, 2015 11:59
Rspec test
require "rails_helper"
describe TestsController, type: :controller do
render_views
let(:tests){FactoryGirl.create_list :test, 3}
let(:test){FactoryGirl.create :test}
describe "GET #index" do
before {get :index}
@kouyaf77
kouyaf77 / setup_docker1.13.1_docker_compose1.11.1_in_ubuntu14.0.4.sh
Last active February 14, 2017 13:03
Shellscript for installing Docker(1.13.1) and Docker compose(1.11.1) in Ubuntu(14.0.4)
#!/bin/sh
# Install Docker 1.13.1
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual
curl -fsSL https://apt.dockerproject.org/gpg | sudo apt-key add -
apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D
sudo apt-get install -y software-properties-common
@kouyaf77
kouyaf77 / benchmark_exception.rb
Last active January 9, 2019 06:58
Ruby例外処理の計測
# Ruby 2.5.1
# ----- Result ------
# Normal: 0.0035529999986465555s
# Exception: 0.08799100000032922s
# Exception/Normal: 24.765268796467108
# Catch&Throw: 0.027447000000393018s
# Catch&Throw/Normal: 7.725021111975346
require 'benchmark'
@kouyaf77
kouyaf77 / bad_example_client.rb
Last active March 4, 2020 19:53
BadExampleClient
require 'faraday'
class BadExampleClient
DEFAULT_URL = 'https://example.com'.freeze
def get(url=DEFAULT_URL)
Faraday.get url
end
end
@kouyaf77
kouyaf77 / good_example_client.rb
Last active March 4, 2020 19:53
GoodExampleClient
require 'faraday'
class GoodExampleClient
DEFAULT_URL = 'https://example.com'.freeze
def get(url=DEFAULT_URL)
r = Faraday.get url
Response.new(r.body, r.status)
end
@kouyaf77
kouyaf77 / good_example_x_client.rb
Last active March 4, 2020 19:53
GoodExampleXClient
require 'net/http'
require 'uri'
class GoodExampleXClient
DEFAULT_URL = 'https://example.com'.freeze
def get(url=DEFAULT_URL)
r = Net::HTTP.get_response(URI.parse(url))
Response.new(r.body, r.code)
end
SELECT *
FROM LOG
WHERE time >= '2020-03-06T03:14:00Z' AND time < '2020-03-06T03:35:00Z' ORDER BY time;
@kouyaf77
kouyaf77 / rspec.yml
Created April 26, 2020 00:38
GitHub Actions Rspec
name: Rspec
on: pull_request
jobs:
rspec:
runs-on: ubuntu-latest
services:
db:
image: mysql:5.7
@kouyaf77
kouyaf77 / capybara.rb
Created April 28, 2020 23:01
spec/support/capybara.rb
require 'capybara/rspec'
require 'selenium-webdriver'
Capybara.server_host = Socket.ip_address_list.detect{|addr| addr.ipv4_private?}.ip_address
Capybara.register_driver :selenium_chrome_headless do |app|
opts = { desired_capabilities: :chrome, browser: :remote, url: ENV['SELENIUM_URL'] }
Capybara::Selenium::Driver.new(app, opts)
end
@kouyaf77
kouyaf77 / polymorphic_anti_pattern.rb
Created May 19, 2020 13:19
polymorphic_anti_pattern.rb
case like.likable
when Post
PostExcutor.call(like)
when Comment
CommentExcutor.call(like)
end