Skip to content

Instantly share code, notes, and snippets.

View kachick's full-sized avatar
😋
😪

Kenichi Kamiya kachick

😋
😪
View GitHub Profile
@kachick
kachick / mergesort.rb
Created June 24, 2015 17:21
Rubyでアルゴリズムやらデータ構造やらのお勉強(Merge Sort / マージソート)- 2
# coding: us-ascii
# 2015 Kenichi Kamiya
class Array
# [6, 5, 1, 4, 3] => [1, 3, 4, 5, 6]
def mergesort
case size
when 0, 1
self
when 2
import functools
def checkio(els):
return functools.reduce(lambda x,y: x+y, els[:3])
if checkio([1, 2, 3, 4, 5, 6]) == 6:
print('Done!')
@kachick
kachick / how_to_delete_exif.md
Created February 9, 2014 16:04
コマンドラインから、exifに詰まった情報を削除する

Perl製なツールのexiftoolがOSSで公開されてて対応フォーマットも多く、一番良いんじゃ無いかなーと感じた。

exiftool -all= image.jpg

とかで消えた。と思う。

@kachick
kachick / 2014-01.md
Last active February 13, 2022 20:02
電子書籍300冊程度自炊した時点での解像度・ファイルフォーマット方針

個人の感想

書籍(文字中心)

  • 300dpでもあんま気にならない。が、技術書(2500~8000円程度?)中心だと総じてコミック(400~1500円程度?)に比べて高価なのでこっちをケチるのもなんだかなーという気はしてしまう。
  • JPEGだと文字のにじみが目立つ
  • 可逆圧縮が効きやすい(サイズがJPEG比で、256色だと1.6~1.7倍程度。16色だと0.8倍程度)
  • 2色しか目立たない様な書籍でも、モノクロスキャンだと違和感を感じる(なんで?濃度?)
  • 白黒だと省かれるみたいだけど、グレースケールだと紙質(ざらざらとか)がそのまま暗さとして反映されたりするっぽい
@kachick
kachick / multilogger.rb
Created January 17, 2014 12:10
一度に複数箇所へ同じログ発生させるって需要あると思うんだけど、標準機能では用意されてないのかな。
# coding: us-ascii
require 'logger'
class MultiLogger
def initialize(*destinations)
@destinations = destinations.map { |dst| Logger.new dst }
end
Logger.instance_methods.each do |meth|
@kachick
kachick / convert_png_and_decrease_color.rb
Last active May 15, 2017 09:26
TIFFなりなんなりの無圧縮or可逆圧縮データからImageMagick経由で可逆圧縮PNGを生成した後に、pngquantで減色する (文字中心データ対象なら--speed は10で十分。標準の3だとめっちゃ遅い)
# coding: us-ascii
require 'logger'
sources = ARGV.dup
abort "Pass target sources." if sources.empty?
class MultiLogger
def initialize(*destinations)
@destinations = destinations.map { |dst| Logger.new dst }
@kachick
kachick / undef_method_on_ancestor.rb
Last active December 30, 2015 21:39
undef_methodの動作がいっつもピンと来ないので確認
# 「上位含めてundef扱いにする」の上位っていうのは、undefした瞬間じゃなくて動的に判断される?
module Super1
def a; end
end
module Super2
def a; end
undef_method :a
end
@kachick
kachick / call_superclass_method.rb
Last active December 23, 2015 14:59
superclass(ancestor)のメソッドを再定義している時に、どの定義を使うか指定する
$VERBOSE = true
class Super
def a
"super_a"
end
def b
"super_b" + c
end
behavior :array_uniq_on_dupulicated_elements, :shared => true do
it "returns a squashed array" do
verify([1, 1].send(@method)).is.eq([1])
end
end
describe "Array#uniq" do
context "when elements are duplicated" do
verify.behavior(:array_uniq_on_dupulicated_elements, :uniq)