This file contains hidden or 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
| import unittest | |
| import requests | |
| import responses | |
| class ResponsesUsageTestCase(unittest.TestCase): | |
| @responses.activate | |
| def test_simple(self): | |
| responses.add(responses.GET, 'http://www.example.com', | |
| json={'error': 'not found'}, status=404) |
This file contains hidden or 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
| import time | |
| import os | |
| import subprocess | |
| import asyncio | |
| import aiohttp | |
| async def test(url): | |
| with aiohttp.Timeout(10): | |
| async with aiohttp.ClientSession() as session: |
This file contains hidden or 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 'dry-validation' | |
| RSpec.describe 'Sample of Dry::Validation.Schema' do | |
| describe '必須 AND 整数 AND 1以上' do | |
| let(:schema) do | |
| Dry::Validation.Schema do | |
| required(:x) { int? & gteq?(1) } | |
| end | |
| end |
This file contains hidden or 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 'benchmark' | |
| string = (0..127).map(&:chr).join.freeze | |
| long_string = (string * 1_000_000).freeze | |
| delete_pattern = "\x00\x01\x02\x03\x04\x05\x06\a\b\v\f\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\e\x1C\x1D\x1E\x1F\x7F" | |
| delete_tr_pattern_1 = "\x00-\x08\x0b\x0c\x0e-\x1f\x7f" | |
| delete_tr_pattern_2 = ["\x00-\x1F\x7F", "^\t\n\r"] | |
| tr_pattern = "\x00-\x08\x0b\x0c\x0e-\x1f\x7f" | |
| gsub_pattern_1 = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/ |
This file contains hidden or 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 yum install -y vsftpd |
This file contains hidden or 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 'benchmark' | |
| require 'mini_magick' | |
| require 'open3' | |
| n = 100 | |
| Benchmark.bm(22) do |x| | |
| x.report("mini_magic") do | |
| n.times do | |
| blob = File.open('sample.jpg') |
This file contains hidden or 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 'objspace' | |
| require 'csv' | |
| require 'nkf' | |
| require 'tempfile' | |
| def test_a | |
| src_encoding = NKF.guess(File.read(ARGV[0], 1_048_576)) | |
| case src_encoding | |
| when Encoding::US_ASCII, Encoding::UTF_8 | |
| 'UTF-8' |
This file contains hidden or 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
| # $ rails new <application name> -T -d postgresql --skip-spring -m heroku_rails_template.rb | |
| if yes? 'Deploy to herok?' | |
| gem 'rails_12factor', group: :production | |
| end | |
| gem 'dotenv' | |
| if yes? 'Use slim?' | |
| gem 'slim-rails' |
This file contains hidden or 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 'set' | |
| require 'rss' | |
| # キーワード集合を作成 | |
| # キーワードの長さ配列を作成 | |
| dictionary = Set.new | |
| size_list = [] | |
| # はてなキーワードの2カラム目を切り出して uniq したもの | |
| # curl -s http://d.hatena.ne.jp/images/keyword/keywordlist_furigana.csv | lv -Ou -Ie | cut -f2 | sort -u > keywordlist.tsv | |
| open('keywordlist.tsv') do |input| |