Skip to content

Instantly share code, notes, and snippets.

@zunda
Last active August 6, 2026 19:59
Show Gist options
  • Select an option

  • Save zunda/679de3c67968822ce9d2adcb5b2eef05 to your computer and use it in GitHub Desktop.

Select an option

Save zunda/679de3c67968822ce9d2adcb5b2eef05 to your computer and use it in GitHub Desktop.
Estimate change of numbers of lines containing keywords
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%S"
set format x "%b\n%Y"
set ylabel "Total lines"
set yrange [0:12]
plot "固定.tsv" using 1:3 with steps title "固定" lw 2,\
"ピン.tsv" using 1:3 with steps title "ピン" lw 2
# usage:
# git log -p app/javascript/mastodon/locales/ja.json config/locales/ja.yml |\
# ruby git-log-grep.rb 固定 ピン
#
require "time"
keywords = ARGV
changes = Hash.new{|h, word| h[word] = Hash.new{|h, time| h[time] = 0}}
ts = nil
$stdin.each_line do |line|
if x = line.scan(/^Date:\s*(.*)/).flatten.first
ts = Time.parse(x).utc
else
keywords.each do |k|
if x = line.scan(/^([+-]).*#{k}/).flatten.first
case x
when "+"
changes[k][ts] += 1
when "-"
changes[k][ts] -= 1
end
end
end
end
end
keywords.each do |k|
File.open("#{k}.tsv", "w") do |f|
ts = changes[k].keys.sort
c = 0
f.puts "#time\tchange\ttotal #{k}"
ts.each do |t|
d = changes[k][t]
c += d
f.puts [t.iso8601, d, c].join("\t")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment