Skip to content

Instantly share code, notes, and snippets.

@compwron
Created January 9, 2015 19:08
Show Gist options
  • Select an option

  • Save compwron/a64972f2e3c527405923 to your computer and use it in GitHub Desktop.

Select an option

Save compwron/a64972f2e3c527405923 to your computer and use it in GitHub Desktop.
alpha params finder
filename = ARGV[0] || 'app/models/transaction.rb'
f = File.open(filename, 'rb')
c = f.read
all = c.split(/\n|,/).map { |i| i.strip.gsub(/[^A-Za-z0-9\s\[\]\._\(\)]/, '') }.reject(&:empty?)
# too many false positives
DEFAULT = 'aaa --- DEFAULT --- '
alph_list = [DEFAULT]
all.each do |line|
if [alph_list.last, line].sort.last == line # this line is after everything in alph list alphabetically
alph_list << line
else
if alph_list.size > (ARGV[1].to_i || 6)
puts (alph_list - [DEFAULT]).join("\n") + "\n\n"
end
alph_list = [DEFAULT]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment