Skip to content

Instantly share code, notes, and snippets.

View koshigoe's full-sized avatar

Masataka SUZUKI koshigoe

View GitHub Profile
@koshigoe
koshigoe / test_responses.py
Created November 15, 2017 10:48
responses と requests.get(url, stream=True)
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)
@koshigoe
koshigoe / aiohttp-multisession.py
Last active November 14, 2017 04:34
aiohttp のメモリ増加を検証
import time
import os
import subprocess
import asyncio
import aiohttp
async def test(url):
with aiohttp.Timeout(10):
async with aiohttp.ClientSession() as session:
@koshigoe
koshigoe / dry_validation_spec.rb
Last active October 19, 2017 04:21
dry-validation を試す
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
@koshigoe
koshigoe / benchmark-delete-control-character.rb
Last active June 15, 2016 13:06
制御文字を削除する
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]/
@koshigoe
koshigoe / file0.txt
Last active October 22, 2015 01:39
ELBはなんでもロードバランスできると聞いたのでFTPしてみる ref: http://qiita.com/koshigoe/items/7e4e9466e821df547192
$ sudo yum install -y vsftpd
@koshigoe
koshigoe / bench.rb
Created July 8, 2015 06:40
画像100%リサイズを mini_magick と convert で比較
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')
@koshigoe
koshigoe / gist:fdb25fdce655e3686d96
Created July 2, 2015 07:36
ファイルの文字コード変換のメモリ使用量を調べる、的な
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'
@koshigoe
koshigoe / heroku_rails_template.rb
Created April 12, 2015 01:27
Rails Application Template for Heroku app
# $ 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'
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|