Skip to content

Instantly share code, notes, and snippets.

View koshigoe's full-sized avatar

Masataka SUZUKI koshigoe

View GitHub Profile

textlint の --cache オプションが活きるのは、検査対象のファイルのタイムスタンプを維持できる環境だけということかな。

# https://github.com/textlint/textlint/blob/835269c28b9369ed9472516682f21fa712d46d66/packages/textlint/src/engine/execute-file-backers/cache-backer.ts#L23C26-L23C40
this.fileCache = fileEntryCache.create(config.cacheLocation);

usecheckSum: Whether to use md5 checksum to verify if file changed. If false the default will be to use the mtime and size of the file. https://github.com/jaredwray/file-entry-cache?tab=readme-ov-file#createcachename-directory-usechecksum

@koshigoe
koshigoe / test.rb
Created December 10, 2019 10:20
Ruby の Net::FTP#put で例外が発生するとコネクションを閉じない?
require 'net/ftp'
def upload
ftp = Net::FTP.new
ftp.read_timeout = 0.1
ftp.passive = true
ftp.connect('localhost')
ftp.login('user', 'pass')
i = 0
require 'csv'
puts CSV::VERSION
File.open('test.csv', 'wb') do |f|
100.times { f.puts('あ' * 1_024) }
5.times { f.puts 'a' }
f.write("Invalid Byte Sequence in UTF-8 \x90")
end
@koshigoe
koshigoe / rotate-iam-token.sh
Last active March 13, 2019 03:45
AWS IAM アクセストークンを更新するスクリプトのサンプル
#!/bin/bash -eu
# Find inactivated access key.
#
# # original output
# {
# "AccessKeyMetadata": [
# {
# "UserName": "koshigoe",
# "AccessKeyId": "********",
@koshigoe
koshigoe / bench-grapheme-length.rb
Last active February 7, 2019 03:29
サロゲートペアなどを途中で切り詰めない様にしたい
require 'benchmark'
N = 10
str = "がぎぐげご" * 100
gra = "か\u3099き\u3099く\u3099け\u3099こ\u3099" * 100
Benchmark.bm(64) do |x|
x.report('String#size (1)') do |x|
N.times { str.size }
@koshigoe
koshigoe / bench-parse.rb
Created January 3, 2019 00:08
Ruby csv 3.0.2
require 'benchmark'
require 'csv'
TEST_FILE = 'test.csv'
unless File.exist?(TEST_FILE)
ROW_SIZE = 1_000_000
ROW = ('a'..'z').map { |c| %Q{"",""#{c}""\n""#{c}""\r""#{c}""\r\n""} }
CSV.open(TEST_FILE, 'wb') do |csv|
@koshigoe
koshigoe / build_1694_step_102_container_0.txt
Created December 25, 2018 13:31
Ruby 2.6 コンパイルで -std=c99 を要求されたときのログ
This file has been truncated, but you can view the full file.
+ RUBY_X_Y_VERSION=2.6
+ SPEC_FILE=ruby-2.6.spec
++ grep '^Version: ' /home/builder/ruby-rpm/ruby-2.6.spec
++ awk '{ print $NF }'
+ RUBY_X_Y_Z_VERSION=2.6.0
+ cp /home/builder/ruby-rpm/ruby-2.6.spec /home/builder/rpmbuild/SPECS/
+ cd /home/builder/rpmbuild/SOURCES
+ curl -LO https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.0.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
@koshigoe
koshigoe / test-pget.rb
Created December 10, 2018 09:56
分割並行 HTTP ダウンロードのプロトタイプ
require 'open-uri'
require 'uri'
require 'net/http'
require 'thread'
require 'tmpdir'
require 'benchmark'
class PGet
attr_reader :thread_count, :min_chunk_size
@koshigoe
koshigoe / sample.rb
Last active November 15, 2018 06:20
String#[0] may return a byte, not a character.
require 'pg'
# $ docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres:9.6
conn = PG.connect(host: 'localhost', port: 5432, user: 'postgres', password: 'password', dbname: 'postgres')
conn.exec <<SQL
drop table if exists test_copy_to;
create table test_copy_to (str varchar);
insert into test_copy_to (str) values ('Ä');
@koshigoe
koshigoe / test.rb
Last active November 15, 2018 03:40
pg gem: invalid byte sequence in UTF-8
require 'pg'
# $ docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres:9.6
conn = PG.connect(host: 'localhost', port: 5432, user: 'postgres', password: 'password', dbname: 'postgres')
conn.exec <<SQL
drop table if exists test_copy_to;
create table test_copy_to (str varchar);
insert into test_copy_to (str) values ('Ä');